Skip to content
Sensorsproximity

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

  1. Confirm the exact part number and breakout-board revision.
  2. Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
  3. Check controller pin assignments and bus address or interface mode against the example code.
  4. Power up with external loads disconnected, then test signals before full integration.
  5. 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.

Board Integration

Library

None — built-in digitalRead by —

No library needed; uses core Arduino functions only.

Wiring

Component pinArduino Uno pinNote
VCC5V
GNDGND
OUTD2Active LOW on most breakout boards — reads LOW when an obstacle is detected.

Swipe sideways to see every column →

C++
  • Adjust the onboard potentiometer to tune detection range (typically 2-30cm).
  • Output logic (active LOW vs active HIGH) varies by manufacturer — if detection reads backwards, just flip the ! in the code.
  • Works by reflected IR, so very dark or IR-absorbing surfaces may not trigger it reliably.
View full Arduino Uno guide