Arduino Code and Video: Infrared Obstacle Avoidance Module
This project demonstrates how to build a simple obstacle avoidance system using an infrared sensor module and an Arduino microcontroller. This is a great project for beginners learning about sensor interfacing and basic programming. The applications for this technology are numerous and can be adapted to various projects.

For example:
- Robotic navigation: Program a robot to avoid obstacles autonomously.
- Smart home automation: Create a system to detect objects in a specific area and trigger actions accordingly.
- Security system: Design a basic intrusion detection system that alerts you when something enters a monitored area.
Hardware/Components
The project uses a readily available infrared obstacle avoidance module, an Arduino microcontroller, and some connecting wires. The infrared module itself contains an infrared emitter, a receiver, and an operational amplifier (op-amp) to process the signal (in video at 00:22). It also features two LEDs: one indicating power and another indicating obstacle detection (in video at 00:37).
The module has three pins: VCC (power), GND (ground), and an output pin. A potentiometer allows you to adjust the detection distance, ranging from a few centimeters up to approximately 10 centimeters (in video at 00:51).
Wiring Guide
The wiring is straightforward. Connect the VCC pin of the infrared module to the 5V pin of the Arduino, the GND pin to the GND pin of the Arduino, and the output pin to a digital input pin on the Arduino (pin 8 is used in the example code).

Code Explanation
The Arduino code is quite simple. The crucial part is setting the correct pin mode and reading the sensor's output. The code uses pin 8 as an input (pinMode(8, INPUT);) (in video at 06:10). The digitalRead(8) function reads the state of this pin, which is HIGH when no obstacle is detected and LOW when an obstacle is present (in video at 06:15). The code then prints "Obstacle on the way" or "All clear" to the serial monitor accordingly (in video at 06:29).
void setup() {
Serial.begin(9600);
pinMode(8, INPUT); // Set pin 8 as input
}
void loop() {
int detect = digitalRead(8); // Read pin 8
if (detect == LOW) {
Serial.println("Obstacle on the way");
} else {
Serial.println("All clear");
}
delay(300);
}
Live Project/Demonstration
The video demonstrates the functionality of the obstacle avoidance system. The presenter shows how the potentiometer adjusts the detection range (in video at 00:57). The serial monitor output clearly shows the "Obstacle on the way" and "All clear" messages, corresponding to the presence or absence of an obstacle (in video at 07:07). The maximum detection range is approximately 10 centimeters (in video at 03:30).
Chapters
- [00:06] Introduction to Infrared Obstacle Avoidance
- [00:22] Module Overview and Components
- [00:51] Potentiometer Adjustment and Detection Distance
- [01:19] How the Infrared Sensor Works
- [02:29] Demonstration of Obstacle Detection
- [05:57] Code Explanation: Setup and Loop
- [06:55] Code Upload and Serial Monitor Demo
- [07:35] Further Applications and Future Projects
Cosas que podrías necesitar
-
Amazonas
-
eBay
-
AliExpressPurchase IR obstacle avoidance module from AliExpresss.click.aliexpress.com
Recursos y referencias
Aún no hay recursos.
Archivos📁
Archivo de Fritzing
-
1x4 Membrane Matrix Keypad
application/zip0.01 MB