IR Obstacle Sensor With Arduino

Introduction

Hey folks! Another interesting topic to discuss and share! Integrating sensors to an Arduino board seems interesting and feels good, when you receive the desired digital output and manipulate it. Nowadays, hundreds of different kinds of sensors are available in the market. We need to try out and explore how we can improve the user experiences using these electronics. For example, temperature monitoring sensors, obstacles detection sensor, soil moisture detection sensors, heart pulse rate sensors, and many more. I will try and use as many sensors as I can and try to integrate them with more sophisticated devices. In this article, I will be sharing about the IR Obstacle sensor, which as the name suggests detects an object or any obstacle coming the sensor's way! Let's see how.

The sensor

sensor

Here is how the sensor looks. We will see another pictorial representation of the above sensor and discuss about the details of the part.

The pictorial representation is given below:

details

Let's learn and see what the sensor has. As you can see, the numbers are mentioned. We will discuss the workaround and try to understand each and every word. First one goes like:

Sensor Parts Functions
OUTPUT This port in the sensor sends the digital output to the output unit. Here, we have the sensor output port on board as 7.
GND This port is used to connect to the board's Grounded port.
VCC The voltage supply port, here we have used the 5 V supply port from the board.
Distance Manipulator The CW (Clock wise) movement increases the distance proximity and the opposite decreases.
Power and Obstacle LED Former illuminates when the Power is supplied and the latter when any obstacle comes over.

The circuit board looks as shown below:

board   board

The circuit diagram would look as shown below:
diagram

This is similar to the previous LED connection of my Arduino series. Series I

If the above is not clear, please share your query in the comments.

diagram

Snippet

  1. int LED = 13; // Use the onboard Uno LED   
  2. int obstaclePin = 7; // This is our input pin   
  3. int hasObstacle = HIGH; // HIGH MEANS NO OBSTACLE   
  4. void setup()  
  5. {  
  6.     pinMode(LED, OUTPUT);  
  7.     pinMode(obstaclePin, INPUT);  
  8.     Serial.begin(9600);  
  9. }  
  10. void loop()  
  11. {  
  12.     hasObstacle = digitalRead(obstaclePin); //Reads the output of the obstacle sensor from the 7th PIN of the Digital section of the arduino   
  13.     if (hasObstacle == LOW) //LOW means something is ahead, so illuminates the 13th Port connected LED   
  14.     {  
  15.         Serial.println("Stop something is ahead!!");  
  16.         digitalWrite(LED, HIGH); //Illuminates the 13th Port LED   
  17.     } else  
  18.     {  
  19.         Serial.println("Path is clear");  
  20.         digitalWrite(LED, LOW);  
  21.     }  
  22.     delay(200);  
  23. }
The Flow

When the full circuit is done the code set is also done. Now, it's the time to connect the board to the computer, using the USB jack. Suppose there is a COM3 port, open the Arduino Set up IDE, where the code set up is done, compile the code once and then upload the code to the board. Once the upload is done, the TX RX LED blinks quickly.

Now, we are all set to test the sensor. For better and precise testing, we can solder the wires (jumper wires) to the sensors as their connected pins are not portable. The whole set up can be soldered.

When we connect, open up the Serial port screen, which transmits at 9600 bits per second, and check the message, as written in the program.

As per the program, the LED also blinks and illuminates, based on the Obstacle sensor output.

The serial screen would look as shown below:

screen

That's it folks!!

Conclusion

Now, this is all about the sensor IR Obstacle sensor, which you can purchase at a very cheap rate from Ebay or Amazon and play with. We can use this set up in our cars and check it out!! In the upcoming series, I will be sharing more sensors and Bluetooth module integrations with Arduino. I hope they will be more fun! Please share your experiences and suggestions as I am still crawling.

Up Next
    Ebook Download
    View all
    Learn
    View all