How to Use the IR Obstacle Avoidance Sensor on Arduino
by MrSottong in Circuits > Arduino
3179 Views, 4 Favorites, 0 Comments
How to Use the IR Obstacle Avoidance Sensor on Arduino
Hello, all,
In this article I will write how to use Avoidance Obstance IR Sensor on Arduino.
Components Required:
Software required:
Avoiddance Obstance IR Sensor
His sensor can be used to detect objects or obstacles in front of it using reflected infrared light.
This sensor has 2 main parts, namely IR Emitter and IR receiver. IR emitter has the duty to emit infrared light. when it hits an object, infrared light will be reflected. And the IR Receiver's function is to receive the infrared reflection.
When the IRreceiver receives reflected infrared light, the output will be "LOW". When the IRreceiver does not receive reflected infrared light, the Output will be "HIGH".
There are 2 LED indicators in this sensor. Power indicator led and output indicator led. The power indicator LED will turn on if the module is powered by an electric current. The output indicator LED will light up if there is an object in front of the sensor or IR receiver receiving infrared light reflection.
Connect the IR Sensore to Arduino
Use a jumper cable to connect the IR sensor to Arduino.
See the picture above or instructions on this:
IR to Arduino
VCC ==> + 5V
GND ==> GND
OUT ==> D2
Programming
Below is a sketch I have made to try this IR sensire:
int pinIR = 2;
void setup(){ Serial.begin(9600); pinMode(pinIR, INPUT); Serial.println("Detect IR Sensor"); delay(1000); } void loop(){ int IRstate = digitalRead(pinIR); if(IRstate == LOW){ Serial.println("Detected"); } else if(IRstate == HIGH){ Serial.println("Not Detected"); } delay(1000); }
I also provide the file, can be downloaded below:
Downloads
Result
If you place an object in front of the sensor, the serial monitor will say "Detected".
if there is no object in front of the sensor, the monitor serial will say "Not Detected".
This result can be utilized to control LEDs, relays and others.
The function of IR sensors is not only to detect objects. we can use this IR sensor to read data from the remote controller. and I will make it in the next article.