IR Obstacle Sensor
Setup Guide
Detect objects in front of your robot or project without any contact — using invisible infrared light. Adjustable range from 2 to 10 cm. Only 3 wires needed, no library required.
Video walkthrough
Prefer to watch? These cover the same steps.
Community videos. Tishvi is not affiliated with creators.
How It Works
Understand the sensor before you wire it.
The IR sensor has two key components on its front face: an IR LED transmitter (emits infrared light continuously) and a photodiode receiver (listens for reflected light). When an object is in range, the IR light bounces back and the receiver detects it — the onboard LM393 comparator then pulls the OUT pin LOW to signal detection.
Arduino 5V pin works perfectly
Adjustable with potentiometer
Narrow cone in front of sensor
LOW = obstacle · HIGH = clear
What You Need
Everything required for this guide.
Tishvi Arduino UNO R3
Must already be set up with Arduino IDE. See the UNO R3 Setup Guide first if needed.
IR Obstacle Sensor Module (ADIY with Pot)
The blue PCB with 3 pins (VCC, GND, OUT) and a blue potentiometer knob on top.
3× Jumper Wires (Female-to-Male)
Female end connects to the sensor's header pins. Male end goes into Arduino.
USB-A to USB-B Cable
To connect Arduino to your computer for uploading the sketch.
Wiring to Arduino UNO R3
3 wires total — takes under 2 minutes.
| IR Sensor Pin | Arduino UNO R3 Pin | Wire Colour | Notes |
|---|---|---|---|
| VCC | 5V | Red | Powers the sensor — must be 5V |
| GND | GND | Black / Brown | Common ground |
| OUT | Pin 7 (Digital) | Yellow / White | Digital signal — any digital pin works |
Reading the Sensor
Upload this sketch and open Serial Monitor to see obstacle detection live.
The OUT pin is LOW (0) when an obstacle is detected and HIGH (1) when the path is clear. The sketch below reads this pin and prints the status — and also blinks the built-in LED on pin 13 as a visual indicator.
// IR Obstacle Sensor — Basic Detection Sketch // OUT pin → Arduino Pin 7 const int IR_OUT_PIN = 7; const int LED_PIN = 13; // Built-in LED bool lastState = HIGH; void setup() { pinMode(IR_OUT_PIN, INPUT); pinMode(LED_PIN, OUTPUT); Serial.begin(9600); Serial.println("IR Obstacle Sensor Ready"); } void loop() { bool val = digitalRead(IR_OUT_PIN); if (val == LOW) { // LOW = obstacle detected digitalWrite(LED_PIN, HIGH); if (lastState != LOW) Serial.println("OBSTACLE DETECTED"); } else { // HIGH = clear digitalWrite(LED_PIN, LOW); if (lastState != HIGH) Serial.println("Path clear"); } lastState = val; delay(50); }
OBSTACLE DETECTED appear, and the built-in LED will light up.Adjusting Detection Range
Use the blue potentiometer to fine-tune sensitivity.
The blue potentiometer (the small knob with a cross-slot) controls how sensitive the sensor is — which effectively sets how far away it can detect objects.
Power up the sensor
Connect to Arduino and upload the sketch above. Open Serial Monitor. Keep your hand about 5 cm in front of the sensor.
Turn the potentiometer slowly
Use a small Phillips-head screwdriver. Turn clockwise to increase range (detect further away), counter-clockwise to decrease range (detect only very close objects).
Watch the Signal LED
The green/red Signal LED (near the bottom of the board, next to the Power LED) turns on when the sensor detects something. Adjust the pot until it turns on reliably at your desired distance.
Troubleshooting
Not working? Check these first.
Power LED not lighting up
Check the VCC wire is in the Arduino's 5V pin (not 3.3V). Also check the GND connection. If the power LED is off, the sensor has no power.
Signal LED never turns on
The detection range may be set too short — try turning the potentiometer clockwise slowly. Also make sure you're using a flat, light-coloured surface. Dark or transparent objects reflect less IR.
Signal LED always stays on (never off)
Range is set too wide — the sensor is detecting the surface below it or a nearby wall. Turn the pot counter-clockwise to decrease range, or move the sensor further from any background surfaces.
Serial Monitor shows nothing
Confirm the baud rate in Serial Monitor matches Serial.begin(9600). Also check that Pin 7 is connected to OUT (not VCC or GND).
Readings are unreliable under bright light
Strong ambient IR (direct sunlight, incandescent bulbs) can interfere. Use the sensor indoors away from direct sunlight, or shield it from the side. This is a normal limitation of simple IR sensors.
Download Sample Sketch
Get a ready-to-upload .ino file for the IR obstacle sensor.
Download the complete sample sketch — it includes wiring comments, state-change detection (prints only on change, not every loop), built-in LED feedback, and Serial Monitor output. No libraries needed.
.ino file. No external libraries needed — works with vanilla Arduino IDE out of the box.Next Steps
What to build with your IR sensor next.
SG90 Servo + IR Sensor
Make a servo react when an IR sensor detects an obstacle — the classic obstacle-avoidance robot building block.
HC-SR04 Distance Sensor
For longer-range detection (up to 400 cm), pair with or replace the IR sensor with the HC-SR04 ultrasonic sensor.
Arduino Project Hub
Line followers, obstacle-avoiding robots, automatic doors — hundreds of IR sensor projects.