Component guide · Beginner · 3 min read
IR Obstacle Sensor Module

How It Works, Wiring and Limits
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
An IR obstacle sensor module shines infrared light from an LED and watches for its reflection with a photodiode; when something is within about 2 to 30 cm, its OUT pin goes LOW. It runs on 3.3 to 5 V and needs no library. It cannot measure distance, struggles with black or shiny objects and false-triggers in sunlight, so use an HC-SR04 or VL53L0X when you need a real distance.
Key specs at a glance
- Supply
- 3.3 to 5 V, about 20 mA
- Output
- Digital, active LOW on detection (most modules)
- Range
- About 2 to 30 cm, set by the trimmer (FC-51)
- Detection angle
- About 35 degrees
- Comparator
- LM393 with an adjustable threshold
- TCRT5000 version
- 1 to 25 mm, for line following and reflective sensing
How an IR obstacle sensor works
The module has an infrared LED emitting at about 940 nm and a photodiode next to it, separated by a small barrier. With nothing in front, no light returns. A nearby object reflects some IR back onto the photodiode, the LM393 comparator compares that signal with the level set by the trimmer, and OUT switches LOW. A second LED on the board lights to show detection.
Wiring and code
Three pins: VCC, GND, OUT. The output is open-collector with a pull-up on the board, so it connects directly to an Arduino, ESP32 or Pico pin.
const int IR = 7;
void setup() {
pinMode(IR, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(IR) == LOW) Serial.println("Obstacle");
else Serial.println("Clear");
delay(200);
}Setting the range
Turn the trimmer with a small screwdriver while holding a white card at the distance you want, until the detection LED just switches on. Turning it too far makes the sensor trigger permanently; back it off until the LED goes out with nothing in front. Do the adjustment in the lighting the robot will actually use.
Why it misses black objects and false-triggers in sunlight
- Dark and matte surfaces absorb IR, so black tape or a black robot may be invisible.
- Shiny surfaces reflect IR away at an angle.
- Sunlight and halogen lamps carry a lot of IR and swamp the photodiode. Shield the sensor or use a modulated sensor (such as a 38 kHz IR receiver with a pulsed LED).
- It gives no distance value. For distance use the HC-SR04 or a VL53L0X laser sensor.
IR sensor types compared
| Module | Range | Output | Best for |
|---|---|---|---|
| FC-51 obstacle sensor | 2 to 30 cm | Digital | Obstacle avoidance, object counting |
| TCRT5000 reflective module | 1 to 25 mm | Digital + analog | Line following, edge detection, encoder wheels |
| Sharp GP2Y0A21 | 10 to 80 cm | Analog distance | Real distance with a narrow beam |
| 38 kHz IR receiver (TSOP / VS1838) | Up to 10 m with a remote | Demodulated digital | Remote control, beam-break with a modulated LED |
| VL53L0X | 3 to 200 cm | I2C distance | Accurate short-range distance |
- FC-51 obstacle sensor
- Range:
- 2 to 30 cm
- Output:
- Digital
- Best for:
- Obstacle avoidance, object counting
- TCRT5000 reflective module
- Range:
- 1 to 25 mm
- Output:
- Digital + analog
- Best for:
- Line following, edge detection, encoder wheels
- Sharp GP2Y0A21
- Range:
- 10 to 80 cm
- Output:
- Analog distance
- Best for:
- Real distance with a narrow beam
- 38 kHz IR receiver (TSOP / VS1838)
- Range:
- Up to 10 m with a remote
- Output:
- Demodulated digital
- Best for:
- Remote control, beam-break with a modulated LED
- VL53L0X
- Range:
- 3 to 200 cm
- Output:
- I2C distance
- Best for:
- Accurate short-range distance
Common mistakes to avoid
- Expecting a distance value from a digital obstacle sensor.
- Mounting the emitter and receiver where the robot's own body reflects IR back.
- Testing indoors, then running outdoors where sunlight triggers it constantly.
- Forgetting the output is active LOW.
- Turning the trimmer to maximum, which makes the sensor always on.
Frequently asked questions
What is the range of an IR obstacle sensor?
About 2 to 30 cm for the common FC-51 module, adjustable with the trimmer. Real range depends on the object's colour and surface.
Why does my IR sensor not detect black objects?
Black and matte surfaces absorb infrared instead of reflecting it, so little light returns. Use an ultrasonic sensor for those objects.
Can an IR sensor measure distance?
Digital modules cannot. Analog sensors such as the Sharp GP2Y0A21, or time-of-flight sensors like the VL53L0X, give a distance value.
Does an IR obstacle sensor work with ESP32?
Yes. Power it from 3.3 V so the output never exceeds 3.3 V, and read it on any GPIO.
What is the difference between an IR obstacle sensor and a TCRT5000?
Both use reflected IR. The TCRT5000 works at a few millimetres and often has an analog output, which suits line-following robots. The obstacle sensor is tuned for several centimetres.
Parts for this guide
Terms in this guide
Projects that use it
Put this into practice: 11 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
- TCRT5000 datasheet (Vishay)
- LM393 comparator datasheet (Texas Instruments)
- FC-51 module schematic (community documentation)
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.



