Best way to program these line sensors?

My team has bought these line sensors that we intend to use to detect reflective tape on the floor. We are having trouble finding any documentation on how to program theme. We thought we might use an arduino to program them as we’ll also be using one to control a couple of LED strips as well. The code we have tried however doesn’t seem to work as it constantly posts “obstacle detected.”

#define SENSOR 7 
void setup() {

Serial.begin(9600);// setup Serial Monitor to display information
    PinMode(SENSOR, INPUT_PULLUP);// define pin as Input  sensor


void loop() {
int L =digitalRead(SENSOR);// read the sensor 

  if(L == 0){
Serial.println(" Obstacle detected");


 Serial.println("All clear");


I have the yellow IO wire plugged into pin 7 on an Arduino Mega 2560. Is there something we’re missing? Would it be easier to program it through the RIO? I have tried adjusting the range screw but it doesn’t seem to have an effect.

It’s probably analog output - can you plug it into one of the mega’s analog ports and use the corresponding analog read command?

Those yellow IR reflective sensors are digital, there is likely a small screw on the rear that you can adjust the sensitivity.

If you want to use them on your FRC robot it will be easier to just plug them into the roboRIO’s digital IO. They need power, ground and signal. Add a PWM(.1in molex connector) or splice into a pwm cable. Red to red, black to black, and yellow to white.

Then just poll the Digital Input to see it’s state in code.

There is also normally a red light on the sensors that will turn on if it detects an object in it’s sensitivity range.

1 Like

The details are on the product page.

I don’t think that sensor is going to be useful in detecting the tape lines on the carpet. Those sensors are distance sensors and will detect any object that is closer than their detection threshold. Those sensors are great for things like detecting when you have collected a game object, or positioning yourself a set distance away from a scoring location. But they will not be able to detect the difference between the white tape and the carpet.

To detect the tape, you really need a color sensor. You probably want something like this or this instead. I have not used these, so this is not a product endorsement. Someone else might have a better sensor that they have actually used. What you would do is set the RGB detection levels so that it could distinguish between white tape and the darker color carpet. If you used a single sensor, you would have to integrate it with a hunting program that would detect when it had crossed from white to not white and then turn the robot until it found the white again. Alternatively, you could use 2 of these sensors and position them wide enough so that the tape would go down the middle between them without being detected. If one sensor detects the tape, you turn toward the side with that sensor which should result in that sensor o longer detecting the tape. Assuming you are now travelling at a slight angle to the tape, the other side would eventually detect the tape and then you turn toward that side and so on. This will keep the tape in between the two sensors and therefore guide you along the tape.

You did not say specifically whether you were detecting the white tape on the FRC field or some generic tape on some generic floor. The concept is the same for any other color tape. Basically you just need to determine the RGB values for that tape (easy enough to do by pointing the sensor at a sample of the tape) and then adjust your settings to distinguish between tape and not tape.

1 Like

Plain IR sensors can be used to detect some things on the floor that are more reflective than the carpet. I have mentored a couple teams that have successfully used them to detect tape and one that used them to detect the edge of the key in 2012. Of course, there will be no differentiation between colors. What sensor to use would depend in part on if this is important to you. Usually, multiple sensors are used for the reasons stated in other posts above.

When selecting an IR sensor, we have typically looked for three things, a digital input, an effective range that comfortably includes the distance from our sensors to the floor, and adjustable sensitivity.

As for this particular sensor, the poor documentation does not really answer any of these questions. Also unfortunately, I do not currently have access to the sensors we did use. I do recall the some came in the kit of parts in 2011 and those worked fine for us.


@Ryan-1701, what you’re looking for here is a reflectance sensor, not a proximity sensor. They also have an LED and photoresistor or photo transistor, but they respond true/false based on the intensity of the light coming back, rather than the time it takes to come back. Reflectance sensors are available in IR and visible frequencies. Note that reflectance at visible frequencies may not correspond to reflectance at IR for some materials.

1 Like

Yes. I got a bit sloppy there. What I have used before had an LED to transmit IR and a photo sensor to see how much came back.

Thank you for the correction.

I’m pretty sure that nearly any industrial IR sensor will be using either pure amplitude or triangulation. The only sensors I’ve ever seen that use time-of-flight are the ones specifically sold as ToF or LIDAR sensors.

Update: We got them working, and surprisingly enough, they work for detecting the reflective tape. When held at a distance above the floor where it normally wouldn’t be detecting anything, when we pass it over the reflective tape it registers. The adjustment screw has allowed us to tune it so that we can mount it at the height we want.

Are you using reflective tape or white gaffers tape? FRC to my knowledge has never used the retroreflective tape on the floor, only gaffers tape lines.

I can’t find any documentation to back this up, but I’m pretty sure that “triangulation” uses a time-of-flight (ToF) with corrections for the location of the bright spot and the spacing between the LED and the PSD (Position Sensitive Device), and ToF is the more important input. As the details were not critical to the question at hand, I gave the first-order answer.

In a bit more depth: With the LED and PSD a known distance apart, the ToF specifies an ellipsoid where the reflecting surface might be, with foci at the LED and PSD (assuming only that the speed of light is essentially constant). In addition to time, the PSD provides a bearing from the PSD to the reflecting surface. Unless I’m missing a something profound, there’s no way to figure distance from only the angular location of the “bright spot”. Indeed, as long as the range is larger than the spacing between the PSD and LED, it comes down to ToF being the first-order answer with the PSD info being a correction.

If anyone has info that says I’m wrong, please post - I’ve only learned two things so far today.