# IR obstacle sensor always on or never detects

> Fix a 3-pin IR obstacle avoidance sensor that always reads an obstacle or never does: sensitivity trimmer, surface colour, sunlight and logic level.

Canonical: https://roboticsengineering.in/fix/ir-obstacle-sensor-always-detects-or-never/ | Published: 2026-11-03 | Updated: 2026-11-04

**Turn the small trimmer on the module until the indicator LED changes at the distance you want.** Most reports of “always detecting” are a trimmer set too high.

## What the message means

The module sends infrared light and compares the reflection with a threshold set by the trimmer. Dark or shiny surfaces and strong sunlight change the reflection.

## Fix it in this order

1. Point the sensor at open space and turn the trimmer until the LED turns off.
2. Bring an object closer and check that the LED turns on at the distance you want.
3. Test with a light colour surface. Black surfaces reflect little infrared and may not be seen.
4. Avoid direct sunlight and light bulbs, which contain infrared.
5. Check the output level. Many modules give LOW when an obstacle is present.
6. Power the module from the supply it is rated for and join the grounds.

## Why it happens

The module emits infrared light and a receiver measures what returns. A comparator, set by the trimmer, decides whether the reflection is strong enough to count as an obstacle, and then switches its output. Light, matte surfaces reflect a lot of infrared, while black or glossy ones reflect little. The same setting therefore detects some objects and misses others.

Ambient infrared from sunlight, incandescent bulbs, and the sensor’s own housing can saturate the receiver, which makes it appear to see something all the time. The trimmer sets the threshold, so adjusting it changes the distance at which the output switches. Many modules output LOW when they detect an object, so the code’s logic must match the module’s output polarity.

## If you see this, do this

| You see | Do this |
| --- | --- |
| LED always on | Trimmer too sensitive, or the sensor sees its own housing. |
| Never detects black objects | Use another sensor type. |

## Confirm the fix

1. Power the module with its output wired to an LED, and note the LED state with nothing in front of the sensor.
2. Turn the trimmer slowly until the LED switches off in open space, then move a white card in front and confirm it switches on.
3. Read the output pin in code and print it; confirm the printed value matches the LED state so the logic polarity is correct.

**Common mistake:** Assuming HIGH on the output means an obstacle is present. Many modules pull the output LOW when they see something, so the code can invert the meaning and steer the robot the wrong way.

## Related

[line follower sensors](https://roboticsengineering.in/fix/line-follower-sensors-not-detecting-the-line/), [HC-SR04 distance](https://roboticsengineering.in/fix/hc-sr04-returns-zero-or-wrong-distance/).

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.
