IR Obstacle Avoidance Sensor Module
Short-range IR proximity sensor with an adjustable threshold — perfect for line-following robots.
Wiring & code for
IR Obstacle Sensor practical reference
A low-cost infrared proximity sensor with an onboard potentiometer for tuning detection distance, the standard choice for line-following and obstacle-avoidance robots. It works by emitting an IR beam and measuring the reflected signal strength bouncing back off nearby surfaces, outputting a simple digital signal when an object comes within the adjustable detection range — an inexpensive way to give a small robot basic 'something is close' awareness without the complexity of an ultrasonic or ToF distance sensor.
Key specifications
- Sensor type: IR reflectance-based obstacle/proximity sensor with onboard comparator
- Operating voltage: 3.3V–5V DC
- Operating current: ~20-25 mA typical
- Detection range: ~2cm-30cm, adjustable via the onboard potentiometer (exact max range varies by board revision)
- Output: Digital output only on most versions — goes LOW when an object is detected within range (active LOW is common but check your specific board)
- Sensitivity adjustment: Onboard trimmer potentiometer sets the effective detection distance
- Surface dependency: Detection distance varies with target surface color and reflectivity — dark or non-reflective surfaces are detected at shorter range than light/reflective ones
- Interface: Single digital output pin, read directly as a HIGH/LOW input
Pinout and connection notes
Adjust the onboard potentiometer while testing against your actual target surface (e.g. the specific line-following track or wall material), since detection range shifts noticeably with surface color and reflectivity — a setting tuned against a white wall may under- or over-trigger against a black line-following track. Multiple sensors mounted close together on the same robot chassis can occasionally cross-interfere with each other's IR beams; angling them apart slightly usually resolves this.
- VCC: Power, 3.3–5V DC
- GND: Ground
- OUT: Digital output — active LOW when an obstacle is detected within the adjusted range
Integration checklist
- Confirm the exact part number and breakout-board revision.
- Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
- Check controller pin assignments and bus address or interface mode against the example code.
- Power up with external loads disconnected, then test signals before full integration.
- If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.
Troubleshooting and reproducibility
Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.