How to use the IR (Infrared) Obstacle Detection Sensor with Arduino
How to use the IR (Infrared) Obstacle Detection Sensor with Arduino
INTRODUCTION
An infrared sensor is an electronic device that emits an infrared wave to sense objects in its surroundings. You have already seen another type of IR sensor in the form of a PIR motion sensor which detects the motion of objects in the surroundings.
APPLICATIONS
It is used in the obstacle avoidance systems in Robotics. Autonomous cars have a number of these sensors installed at various locations on the vehicle.
WIRING DIAGRAM
VCC – 5V
OUT – Digital Pin 7
GND – GND
CODE
Courtesy of Henry's Bench.
// IR Obstacle Collision Detection Module // Henry's Bench int LED = 13; // Use the onboard Uno LED int isObstaclePin = 7; // This is our input pin int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE void setup() { pinMode(LED, OUTPUT); pinMode(isObstaclePin, INPUT); Serial.begin(9600); } void loop() { isObstacle = digitalRead(isObstaclePin); if (isObstacle == LOW) { Serial.println("OBSTACLE!!, OBSTACLE!!"); digitalWrite(LED, HIGH); } else { Serial.println("clear"); digitalWrite(LED, LOW); } delay(200); }
END RESULT
Open serial monitor and place an object in front of the sensor. You will observe the detection of an object in the serial terminal.
ADDITIONAL RESOURCES
https://create.arduino.cc/projecthub/Raushancpr/arduino-with-ir-sensor-1579b6
https://www.instructables.com/id/Using-Infrared-Sensor-With-Arduino/