Arduino, Engineering Projects

How to Interface IR Sensor with Arduino

In this post, we will learn How to Interface IR Sensor with Arduino. It’s is one of the most commonly used sensor and it is used for multiple purposes such as Line following Robot, Obstacle avoiding Robot, Controlling LEDs with IR Sensor, color detection, fire detection, etc.

So Today we are going to cover step by step guide on How to Interface Infrared Sensor with Arduino.

Interfacing of IR Sensor with Arduino

What is IR Sensor?

An Infrared sensor or commonly known as IR Sensor is an electronic device, used to sense the heat of an object and motion of an object. Basically, an IR Sensor can detect Infrared radiation that is not visible with naked eyes. A body when heated radiates infrared light which can be detected by IR Sensor.

IR Sensor is consist of two circuits, IR transmitter, and IR receiver. In the transmitter section, IR LED is used and in the Reciever section, a photodiode is used. IR LED transmit Infrared light to an object and then that IR light is bounced back and IR receiver, receives that light and convert it to the electric voltage accordingly.

Picture down below shows the IR Sensor and Operation of IR Sensor.

IR Sensor Module

WORKING OF IR SENSOR

IR Sensor Module:

IR Sensor module is used with Arduino to detect infrared radiations that are not visible to the human eye. It is mostly used for robot obstacle avoidance, obstacle avoidance car, line count and black and white line tracking.

Specification of IR Sensor Module:

  1. It has a receiving range of 2 ~ 30 cm.
  2. working voltage of 3 .3 V to 5 V.
  3. working current of 1.5 mA.
  4. operating temperature range from -25 C to 85C.

IR Sensor Module Pins:

  1. +5v Source: IR sensor Module require +5v to work perfectly.
  2. Ground: In order to get operation from IR Sensor module we need to provide ground to the sensor module.
  3. OUT Pin: OUT pin is important pin it is used to connect sensor with microcontroller’s input or output port.

Components required:

  1. Arduino Uno
  2. IR Sensor Module
  3. Jumper Wires
  4. Breadboard (Optional)

components required for ir sensor project

Let’s Interface IR Sensor with Arduino:

The connection for Interfacing of  IR Sensor with Arduino is very easy, connect VCC of a module with Arduino 5v pin, connect the ground of module with Arduino’s Ground and connect OUT pin of a module with a 4th digital pin of Arduino.

Interface IR Sensor with arduino

Note: do not get confused if you feel any query do comment down below we will respond you as soon as possible.

Source code for Interfacing IR Sensor with Arduino

/*
Interfacing of IR Sensor with arduino code
Purpose: Turns on an LED when object is detected, else off.
copyrights: www.studentsheart.com
*/


const int IRSensor=4;

void setup() { 
// initialize the digital pin as an output.
// Pin 13 has an builtin LED connected on most Arduino boards:
pinMode(13, OUTPUT); 
//Pin 4 is connected to the output of IR sensor
pinMode(IRSensor,INPUT);
}

void loop() {
if(digitalRead(IRSensor)==HIGH) //Check the sensor output
{
digitalWrite(13, HIGH); // set the LED on
}
else
{
digitalWrite(13, LOW); // set the LED off
}
}

Note: by varying sensor’s potentiometer you can ensure that the sensor is correctly working or not!

Just place an object in front of a sensor and observe the change in LED connected to pin 13 (Built-in Arduino’s LED). If the LED is high it means the sensor is working if the LED is low vary the potentiometer till the LED goes high.

Now remove the object and see if LED goes low it means the sensor is working correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *