/ IR Obstacle Sensor Guide
← All Guides Shop ↗
🌐 Translate:
⏱ 10 min 🔌 3 wires ✅ Beginner

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.

🛒
This guide covers the ADIY IR Sensor Module with Potentiometer. View product page ↗
📺

Video walkthrough

Prefer to watch? These cover the same steps.

Arduino IR Obstacle Sensor Tutorial
YouTube
▶ YouTube
IR Sensor with Arduino — Obstacle Detection
YouTube
▶ YouTube

Community videos. Tishvi is not affiliated with creators.

1

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.

Operating Voltage
3 – 5V DC
Arduino 5V pin works perfectly
📏
Detection Range
2 – 10 cm
Adjustable with potentiometer
📐
Detection Angle
35°
Narrow cone in front of sensor
📤
Output Signal
Digital (LOW / HIGH)
LOW = obstacle · HIGH = clear
ℹ️
The sensor has two onboard LEDs: a Power LED (stays on while powered) and a Signal LED (lights up when an obstacle is detected). You can see detection happening without even connecting to Arduino — just power it and wave your hand in front.
2

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.

💡
No breadboard needed! The sensor plugs directly into Arduino via jumper wires. This is one of the simplest setups possible — 3 wires and you're reading obstacle data.
3

Wiring to Arduino UNO R3

3 wires total — takes under 2 minutes.

ARDUINO UNO R3 5V GND D7 VCC (Red) GND (Black) OUT (Yellow) IR SENSOR MODULE
IR Sensor PinArduino UNO R3 PinWire ColourNotes
VCC5VRedPowers the sensor — must be 5V
GNDGNDBlack / BrownCommon ground
OUTPin 7 (Digital)Yellow / WhiteDigital signal — any digital pin works
⚠️
The sensor pins are labelled on the PCB as VCC · GND · OUT (right to left, with the sensor LEDs facing you). Double-check orientation before powering up.
4

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_sensor_obstacle.ino
// 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);
}
Open Serial Monitor (Tools → Serial Monitor, 9600 baud). Wave your hand 2–8 cm in front of the sensor. You should see OBSTACLE DETECTED appear, and the built-in LED will light up.
5

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.

1

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.

2

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).

3

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.

💡
Best surface: Light-coloured, flat, hard surfaces (paper, white plastic) reflect IR best. Dark objects, fabric, and transparent materials absorb IR and may not be reliably detected — you may need to increase sensitivity (turn pot clockwise) for these.
6

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.

📄
ir_sensor_sample.ino
State-change detection · LED feedback · Serial Monitor · No libraries
⬇ Download .ino
💡
How to open: In Arduino IDE go to File → Open and select the downloaded .ino file. No external libraries needed — works with vanilla Arduino IDE out of the box.