proximity
Interfacing IR Obstacle Sensor with Arduino Uno
What is the IR Obstacle Sensor?
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.
Setting Up IR Obstacle Sensor with Arduino Uno
Library
None — built-in digitalRead by —
No library needed; uses core Arduino functions only.
Wiring
| Component pin | Arduino Uno pin | Note |
|---|---|---|
| VCC | 5V | |
| GND | GND | |
| OUT | D2 | Active LOW on most breakout boards — reads LOW when an obstacle is detected. |
Swipe sideways to see every column →
- 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.
Related Components
A3144
Digital Hall-effect switch for contactless magnetic detection
ACS712
Measure AC or DC current with an analog Hall-effect sensor
ADXL345
Low-power 3-axis accelerometer with tap/double-tap and freefall detection for wearables.
GP2Y0A21
Analog IR distance sensor for obstacle detection at 10-80cm range — reliable and well-documented.
Related Guides & Projects
Arduino Uno R4 Minima Pinout: Every GPIO, ADC, DAC, and Op-Amp Pin Explained
A complete Arduino Uno R4 Minima pinout reference — digital I/O, ADC, DAC, op-amp, CAN, dual UART, and exactly what it leaves out compared to the WiFi variant.
Mastering PWM on Arduino: Dimming LEDs and Controlling Motors
Understand what PWM actually is on Arduino, dim an LED smoothly, and safely control a DC motor's speed with a driver chip -- plus the mistakes (like wiring a motor straight to a pin) that damage boards.
4-Digit 7-Segment Counter with TM1637 & Arduino
Drive a TM1637-based 4-digit 7-segment display with Arduino Uno to show a real-time up/down counter, elapsed timer, and scrolling text. Covers library setup, brightness control, and custom segment mapping.
Arduino Uno R4 Minima vs WiFi: Which One Should You Choose?
Same processor, same memory, different price. Here's what the WiFi variant's extra hardware actually gets you, and when the Minima is the smarter buy.