How to connect IR Obstacle Avoidance Sensor to Arduino to Arduino
In this tutorial, you will learn how to integrate the IR Obstacle Avoidance Sensor with Arduino and build projects such as obstacle detection, line following, etc
Submitted by: Gideon
Date: 28th January, 2018
IR obstacle avoidance sensor is for detecting obstacles in close range. This sensor is used in various robotic projects related to home automation and robotics. In this tutorial, we are going to use the IR obstacle avoidance sensor with the arduino to cause some actions on an LED. Using IR obstacle avoidance sensor with arduino is the best component for line-
The IR obstacle avoidance sensor has an IR transmitter and an IR receiver. This work works like the HC-SR04 Ultrasonic sensor module. The IR transmitter emits IR that is reflected back to the IR receiver when an obstacle with a bright surface comes into contact. The IR light does not reflect on dark surfaces but are rather adsorbed. This characteristics makes it really good for line following robots application.
When the IR obstacle avoidance sensor is not obstracted, the sensor uses is LOW but as at when it encounters an obstacle and the light is reflected, the sensor goes HIGH. The IR light is invincible to the human eye but visible to a camera. Show your phones camera to the ir sensor and you will see a pinkish ray emiting from the IR transmitter.
In this circuit we will be using the following components
This is how the IR obstacle avoidance sensor is.
In the fritzing image below, the circuitary is lay down comprehensively.
The code that is going to be used in tutorial requires that we demonstrate using the serial monitor. The ir detects an obstacle and turns on an LED on the arduino which is connected to pin 13. The GND and VCC of the sensor goes to the GND and 5v of the arduino board respectively. The OUT pin is connected to digital pin 5. The output of the IR obstacle avoidance sensor is displayed on a screen.
This is the code that run the setup to turn on LED on pin 13 when there is an obstacle but off when the obstacle is off.
int irsensor= 5; //out on the module is connected to arduino's pin 5
int sensorvalue; // variable to store ir sensor reading
void setup() // run once, when the sketch starts
Serial.begin(9600); //opens the serial port to communicate at 9600 bits per second
pinMode(irsensor,INPUT); //irsensor is declared as INPUT
sensorvalue=digitalRead(irsensor);// gets sensor reading an stores in sensorvalue variable.
Serial.print("Sensor =="); // prints Distance == on a row in the serial monitor
Serial.println(sensorvalue); //prints the values stored in distance
Serial.println(" No obstacle");
Serial.println(" Obstacle ");
This is the setup for the circuit in real life
It has been a great time to show you how to work with the IR obstacle avoidance sensor with arduino and mention to you some of the applications. If you have any issues, please leave a comment below and we will answer them. You can check out all the tutorials in our sensors section.
This is the tutorials website for Invent Electronics. We are a top online retailer of electronics components, microcontrollers and sensors in Ghana. Besides providing customers with good quality electronic components we want to help them build great projects with the components they buy for us so we’ve put together a ton electronics resources, projects and tutorials on this site just for you!
Looking for electronic components to buy in Ghana?
Get all your sensors, electronic components, Arduinos, Raspberry Pi and other parts for your project at great prices from our online store.
Join Our Community
We’re more than just an electronics store. We are also a community of makers, engineers, enthusiasts and more. Join our community today, meet and learn from other people like you.