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.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerThe 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.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| IR Obstacle Avoidance Sensor Module | 940nm emitter + photodiode + LM393 comparator | 1 | $1.50 |
| 5mm Red LED + 220Ω Resistor | Obstacle indicator output | 1 | $0.15 |
| Breadboard & Jumper Wires | 5× breadboard leads | 1 | $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.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling FC-51 Infrared Obstacle Avoidance Module acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Inspect Emitter & Receiver Alignment
Verify the clear IR emitter LED and black photodiode point straight forward and parallel.
- 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.
Wire IR Module to D2 & Alert LED to D8
Connect power, ground, sensor output, and external indicator LED.
- 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.
Calibrate Range with Blue Trimpot
Adjust the onboard potentiometer so the module detects your hand cleanly at ~10cm.
- 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.
Upload Obstacle & Conveyor Counter Sketch
Flash the edge-counting firmware and monitor real-time detections on Serial Monitor.
- Upload the production sketch below.
- Open Serial Monitor at 115200 baud.
- Pass objects across the beam and verify clean single-increment counting.
Compare Surface Reflectivity
Measure detection distance against white paper, aluminum foil, and matte black cloth.
- 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.
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 DiagnosticMinimal standalone sketch to verify pin wiring and signal response for FC-51 Infrared Obstacle Avoidance Module before running the full project firmware.
// 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);
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* 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
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Object in Range | D2 = LOW (0V) | IR Reflected | D8 LED ON + Count++ |
| Open Path | D2 = HIGH (5V) | No Reflection | D8 LED OFF (Clear) |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Obstacle LED stays permanently ON even in open air | Trimpot turned too sensitive or direct sunlight hitting photodiode | Turn potentiometer counter-clockwise while facing open room | Back 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 target | Test with white card while slowly turning trimpot CW | Increase sensitivity clockwise using a white test card. |
| Power LED is off | VCC/GND loose or swapped | Verify 5V across module VCC and GND | Re-seat power jumpers securely. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Toggle a desk LED ON/OFF each time you wave your hand past the IR sensor.
Place two IR sensors 5cm apart to determine whether an object moved Left→Right or Right→Left.
Trigger an SG90 servo (Project 8) to lift a lid for 4 seconds when a hand approaches.