IR line sensors need the right height, a calibrated threshold and shade from ambient light. Read the raw values first and set the threshold from them.
What the message means
Each sensor sends infrared light and measures how much returns. A dark line returns less than a light floor. The values depend on distance, surface and room light, so a fixed number from a tutorial rarely fits your floor.
Fix it in this order
- Print the raw sensor values over the serial monitor over the line and over the floor.
- Set the threshold midway between the two readings, and repeat on the real track.
- Set the sensor height to about 3 to 10 mm above the surface, as the sensor datasheet advises.
- Shield the sensors from strong sunlight and bright lamps.
- Check the supply voltage. Weak batteries change the readings.
- Check whether your module outputs high or low on black. Some invert the output.
Why it happens
Typical IR line sensors have an infrared LED and a photodiode or phototransistor side by side. The receiver measures how much infrared light returns from the surface. A dark line absorbs more than a light floor, so the reading drops over the line. The output switches when the reading crosses a threshold, so the threshold decides what the robot sees.
Ambient light, sensor height and surface finish all change the reading, so a threshold that worked on a desk may fail on a track. Sunlight and bright lamps add infrared that washes out the contrast. Sensor height changes how much light reaches the receiver. Low battery voltage can also shift the readings. Calibrating on your own track, under your own lighting, avoids these traps.
If you see this, do this
| You see | Do this |
|---|---|
| Values never change | Wiring, power or height. |
| Works indoors but not outdoors | Ambient light. Shield the sensors. |
Confirm the fix
- Print each raw sensor value over the line and over the floor. A clear gap between the two readings means usable contrast.
- Hold the sensor at its mounted height over white paper and then black tape. Repeat under your real lighting to confirm the threshold.
- Note the output level, high or low, for black and white. Some modules invert the signal, and the code must match that polarity.
Common mistake: Most readers assume that one fixed threshold from a tutorial will work on any track, when lighting, sensor height and surface all change how dark the line reads.
Related
PID for a line follower, IR sensor with Arduino.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.