MyRoboPathOpen Robotics Lab
Arduino Uno #17 of 35
Est. 0.5 Hours
Budget: $2 - $4
Beginner

IR Infrared Obstacle Avoidance Sensor Module

Detect nearby objects instantaneously using a 940nm IR emitter/photodiode pair and LM393 threshold comparator.

Equip your Arduino Uno with fast short-range obstacle sensing using the classic FC-51 / KY-032 IR obstacle module. Tune the onboard LM393 comparator trimpot to set detection distance (2–25cm), interpret active-LOW digital outputs, and count passing objects reliably.

Arduino Uno R3IR Obstacle SensorLM393 Comparator940nm ReflectanceObject Counter
IR Infrared Obstacle Avoidance Sensor Module Blueprint
IR Infrared Obstacle Avoidance Sensor ModuleCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Understand how reflected 940nm infrared energy shifts photodiode current into the LM393 comparator.
2Calibrate detection range (2–25cm) accurately using the onboard sensitivity potentiometer.
3Recognize why dark matte black surfaces absorb IR and shorten detection distance compared to white surfaces.
4Implement rising/falling edge tracking to build a conveyor-belt object counter.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The IR obstacle module runs directly from Arduino Uno 5V, consuming ~20mA to drive its continuous 940nm IR emitter LED and LM393 comparator stage. Keep the black receiver photodiode shielded from direct sunlight; tune trimpot gently without forcing past stops.

IR Infrared Obstacle Avoidance Sensor Module Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for IR Infrared Obstacle Avoidance Sensor Module
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P @ 16MHz1$8.00
IR Obstacle Avoidance Sensor Module940nm emitter + photodiode + LM393 comparator1$1.50
5mm Red LED + 220Ω ResistorObstacle indicator output1$0.15
Breadboard & Jumper Wires5× breadboard leads1$2.00

Electrical & System Architecture

Connect IR Sensor VCC to 5V, GND to GND, and OUT to D2. Wire an obstacle alert LED (+220Ω resistor) to D8.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for IR Infrared Obstacle Avoidance Sensor Module.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for IR Infrared Obstacle Avoidance Sensor Module.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling FC-51 Infrared Obstacle Avoidance Module acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for IR Infrared Obstacle Avoidance Sensor Module.
Figure: Firmware execution flow and state transitions for IR Infrared Obstacle Avoidance Sensor Module.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Inspect Emitter & Receiver Alignment

Duration: 5 Mins

Verify the clear IR emitter LED and black photodiode point straight forward and parallel.

IR Infrared Obstacle Avoidance Sensor Module hardware layout diagram
Stage 1: FC-51 Infrared Obstacle Avoidance Module hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • Check that neither diode is bent sideways or touching the other.
  • Identify the 3 pins: VCC, GND, and OUT.
  • Notice the two onboard SMD LEDs: Power LED and Obstacle-Detect indicator LED.
Engineering & Tuning Tip: Wrapping tiny black heat-shrink sleeves around the sides of the emitter stops light leaking sideways directly into the photodiode!
2

Wire IR Module to D2 & Alert LED to D8

Duration: 5 Mins

Connect power, ground, sensor output, and external indicator LED.

IR Infrared Obstacle Avoidance Sensor Module breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • Connect IR Sensor VCC → 5V, GND → GND, and OUT → D2.
  • Wire D8 → 220Ω resistor → Red LED anode → cathode to GND.
  • Connect USB cable to power the Uno.
Engineering & Tuning Tip: Remember: standard LM393 IR modules output LOW (0V) when an object IS detected.
3

Calibrate Range with Blue Trimpot

Duration: 10 Mins

Adjust the onboard potentiometer so the module detects your hand cleanly at ~10cm.

IR Infrared Obstacle Avoidance Sensor Module power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (≈20mA IR LED)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • Hold a white card 10cm in front of the sensor.
  • Rotate the trimpot clockwise until the module's green Detect LED turns ON.
  • Remove the card—confirm the Detect LED turns cleanly OFF; if it stays ON, back off slightly CCW.
Engineering & Tuning Tip: If you turn the trimpot too far clockwise, background room reflections will permanently latch the sensor ON.
4

Upload Obstacle & Conveyor Counter Sketch

Duration: 5 Mins

Flash the edge-counting firmware and monitor real-time detections on Serial Monitor.

IR Infrared Obstacle Avoidance Sensor Module serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • Upload the production sketch below.
  • Open Serial Monitor at 115200 baud.
  • Pass objects across the beam and verify clean single-increment counting.
Engineering & Tuning Tip: Adding a 40ms settle filter prevents rapid chatter at the exact boundary of detection range.
5

Compare Surface Reflectivity

Duration: 5 Mins

Measure detection distance against white paper, aluminum foil, and matte black cloth.

IR Infrared Obstacle Avoidance Sensor Module live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • Measure max trigger range for white paper vs matte black surface.
  • Note why robotics builders prefer ultrasonic sensors for matte black walls and IR sensors for line tracking.
  • Document your tuned trigger distance.
Engineering & Tuning Tip: Avoid aiming the sensor toward sunny windows—sunlight contains intense 940nm infrared energy.

Subsystem Benchtop Verification Scripts

Test each hardware subsystem independently before deploying the full autonomous firmware.

1Bench Diagnostic: FC-51 Infrared Obstacle Avoidance Module Hardware Check

Subsystem Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for FC-51 Infrared Obstacle Avoidance Module before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// Diagnostic: Raw IR Obstacle OUT Monitor
void setup() { pinMode(2, INPUT); Serial.begin(115200); }
void loop() {
  Serial.println(digitalRead(2) == LOW ? "OBSTACLE (LOW)" : "CLEAR (HIGH)");
  delay(150);
}
Expected Output: Prints CLEAR (HIGH) normally and OBSTACLE (LOW) when hand enters range.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_ir_obstacle_avoidance_sensor.ino
arduino_uno_ir_obstacle_avoidance_sensor.inoArduino C++
/**
 * Project 17: IR Obstacle Avoidance Sensor & Object Counter
 * Board: Arduino Uno R3 | Pins: D2 (IR OUT), D8 (Alert LED)
 */
const uint8_t IR_OUT_PIN = 2;
const uint8_t ALERT_LED = 8;
const unsigned long FILTER_MS = 40;

bool lastBlocked = false;
unsigned long lastEdgeMs = 0;
unsigned long objectCount = 0;

void setup() {
  pinMode(IR_OUT_PIN, INPUT);
  pinMode(ALERT_LED, OUTPUT);
  Serial.begin(115200);
  Serial.println(F("IR Obstacle Detector & Counter Ready"));
}

void loop() {
  bool blocked = (digitalRead(IR_OUT_PIN) == LOW); // Active-LOW sensor
  digitalWrite(ALERT_LED, blocked ? HIGH : LOW);

  if (blocked != lastBlocked && (millis() - lastEdgeMs >= FILTER_MS)) {
    lastEdgeMs = millis();
    lastBlocked = blocked;
    if (blocked) {
      objectCount++;
      Serial.print(F("[DETECT] Obstacle #"));
      Serial.println(objectCount);
    } else {
      Serial.println(F("[CLEAR] Path open"));
    }
  }
}

Firmware Architecture Explanation:

  • Interprets the LM393 comparator's active-LOW output cleanly into a blocked boolean.
  • Applies a 40ms edge filter so slow-moving objects at the detection boundary do not double-count.
  • Maintains a running counter useful for conveyor belts, doorway entry counters, and wheel tachometers.

Operational Verification & Pin State Matrix

1Double-check all 4 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Prints CLEAR (HIGH) normally and OBSTACLE (LOW) when hand enters range.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for IR Infrared Obstacle Avoidance Sensor Module
Input / StatePin / SignalDetected ConditionExpected Output
Object in RangeD2 = LOW (0V)IR ReflectedD8 LED ON + Count++
Open PathD2 = HIGH (5V)No ReflectionD8 LED OFF (Clear)

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for IR Infrared Obstacle Avoidance Sensor Module
ProblemLikely CauseDiagnostic CheckEngineering Solution
Obstacle LED stays permanently ON even in open airTrimpot turned too sensitive or direct sunlight hitting photodiodeTurn potentiometer counter-clockwise while facing open roomBack off trimpot CCW until Detect LED extinguishes in open space.
Only detects objects touching the LEDs (<1cm)Trimpot turned too far CCW or matte black targetTest with white card while slowly turning trimpot CWIncrease sensitivity clockwise using a white test card.
Power LED is offVCC/GND loose or swappedVerify 5V across module VCC and GNDRe-seat power jumpers securely.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 1Touchless Hand-Wave Lamp

Toggle a desk LED ON/OFF each time you wave your hand past the IR sensor.

Level 2Dual-Gate Direction Counter

Place two IR sensors 5cm apart to determine whether an object moved Left→Right or Right→Left.

Level 3Smart Trash Bin Opener

Trigger an SG90 servo (Project 8) to lift a lid for 4 seconds when a hand approaches.