IR Proximity Sensor with Arduino
IR Proximity sensor is a simple Infrared Sensor which is used to detect obstacles. This is a multipurpose sensor and used in many robotic applications like Obstacle avoidance robot, Line Follower Robot, and any other obstacle detection projects. This is an Active Infrared sensor, it emits and detects its own IR rays. A passive infrared sensor only detects the emitted IR Rays from objects. PIR Sensor is a good example for Passive IR Sensors.
IR Proximity Sensor Working Principle
Infrared lights are Electromagnetic radiations with longer wavelengths and are not visible to Human eyes. In IR Sensors we have IR emitting and receiving LEDs. In the long distance, the angle of light and sensor are meet together makes the output as HIGH (+5v). If there is an obstacle the angle is less and the receiving LED can’t detect the IR wave. Hence it will output a LOW Signal (0v).
A simple way to see Infrared with a mobile phone:
The operation of the camera is capturing light signals from an object. It can capture all the light signals even the IR. So let’s try to capture the IR light. Connect power supply of IR Sensor and look at the colorless LED. You can’t see any light emitted with a naked human eye. But a camera can detect the Infrared light. Show the sensor in front of your mobile camera and you can see the Red IR rays emitted from the colorless IR LED (Transparent LED). If still not visible, congrats! You have a good quality camera with IR Blocking filters.
IR Proximity Sensor Pinout
IR Sensor has three terminals, two terminals for power supply and one terminal for Output. Additionally, there is a potentiometer to calibrate the sensor.
VCC – Power Supply (+5V)
GND – Ground
OUT – Output
How to use IR Sensor with Arduino
IR Proximity sensor is simple to use with Arduino. You have to connect the power supply pins to +5V and Ground. The sensor output to any digital pin of Arduino.
Circuit Diagram for IR Sensor
IR Proximity Sensor Code for Arduino
We use the onboard LED and Serial monitor to see the operation of IR Proximity sensor. An IR LED is connected at pin 7 of Arduino and onboard sensor is at pin 13. We defined a variable ‘sensorOut’ to store the sensor value temporarily.
/* IR Obstacle Detection Module */ /*www.factoryforward.com */ int LED = 13; // Onboard LED pin int irPin = 7; // This is our input pin (IR LED at pin 7) int sensorOut = HIGH; // HIGH at No Obstacle void setup() { pinMode(LED, OUTPUT); pinMode(irPin, INPUT); Serial.begin(9600); } void loop() { sensorOut = digitalRead(irPin); if (sensorOut == LOW) { Serial.println("What is this Obstacle?"); digitalWrite(LED, HIGH); } else { Serial.println("No Obstacle"); digitalWrite(LED, LOW); } delay(200); }
Once the code is uploaded open serial monitor and make sure the baud rate is set to 9600. When there is no Obstacle in front of IR Sensor it prints ‘No Obstacle’. If you place an object in front of it, then it prints ‘What is this Obstacle?’ in the serial monitor.
There is also proximity sensors used for industrial purposes. They are called as Inductive Proximity Sensor and Capacitive Proximity Sensor. To learn more about interfacing inductive proximity sensor with Arduino, Check out this blog.
Comments (2)
Hii i interfaced atmega 8051 microcontroller to IR control the automatic lights on & off through Relay boards, distance was getting in LCD display correctly but relay was operating in reverse condition how it was happen ???
Change the connection at the output of the relay. From NO to NC (or) NC to NO.