Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
π Ready to explore and create with us? Click [here] and join today!
IR Obstacle Avoidance Sensor Moduleο
Introductionο
An IR Obstacle Sensor works in accordance with the infrared reflection principle to detect obstacles. When there is no object, the infrared receiver receives no signals; when there is an object ahead which blocks and reflects the infrared light, the infrared receiver will receive signals.
Principleο
An obstacle avoidance sensor mainly consists of an infrared transmitter, an infrared receiver and a potentiometer. According to the reflecting character of an object, if there is no obstacle, the emitted infrared ray will weaken with the distance it spreads and finally disappear. If there is an obstacle, when the infrared ray encounters it, the ray will be reflected back to the infrared receiver. Then the infrared receiver detects this signal and confirms an obstacle in front. The detection range can be adjusted by the built-in potentiometer.
Module Schematic Diagramο
Usageο
Hardware components
Arduino Uno R4 or R3 board * 1
IR Obstacle Avoidance Sensor Module * 1
Jumper Wires
Circuit Assembly
Codeο
Code explanationο
Define pin number for sensor connection:
const int sensorPin = 2;
Connect the sensorβs output pin to Arduino pin 2.
Setup serial communication and define sensor pin as input:
void setup() { pinMode(sensorPin, INPUT); Serial.begin(9600); }
Initialize serial communication at 9600 baud rate to print to serial monitor. Set sensor pin as input to read input signal.
Read sensor value and print to serial monitor:
void loop() { Serial.println(digitalRead(sensorPin)); delay(50); }
Continuously read digital value from sensor pin using
digitalRead()
and print value to serial monitor usingSerial.println()
. Add 50ms delay between prints for better viewing.
Note
If the sensor is not working properly, adjust the IR transmitter and receiver to make them parallel. Additionally, you can adjust the detection range using the built-in potentiometer.
Additional Ideasο
Add buzzer that beeps when obstacle is detected