Menu Close

Arduino – Digital and Analog Infrared Sensor

This tutorial of Robo India explain the working concept of Infrared(IR) sensor as Digital and Analog sensor. 

1. Introduction:

This is a multipurpose infrared sensor which can be used for color detection.The sensor provides a digital as well as analog output. An on board LED is used to indicate the presence of an object. This digital output can be directly connected to an Arduino, Raspberry Pi or any other microcontroller to read the sensor output.

IR sensors are highly susceptible to ambient light and the IR sensor on this sensor is suitably covered to reduce effect of ambient light on the sensor. The on board potentiometer should be used to calibrate the sensor.

An infrared light emitting diode (IR LED) emits light of Infrared range 700 nanometers (nm) to 1 mm. This light is not visible by naked eyes but can be seen by a camera (that is why these are also used in night vision cameras).

A photo diode gives response in term of change in resistance when light falls on it. That change is measured in terms of voltage.

An IR LED and a Photo diode are used in a combination for proximity and color detection. An IR LED (transmitter) emits IR light, that light gets reflected by the object, the reflected light is received by an IR receiver (Photo Diode). Amount of reflection and reception varies with the distance. . This difference causes to change in input voltage through IR input. This variation in input voltage is used for proximity detection.

For color detection application: The amount of reflected light depends upon the color of surface from which it is reflected. The reflection is different for different colored surfaces. This makes it a color detector.

2 Hardware Interfacing

IR Sensor have four pins:

1. VCC +5V

2. GND

3. D connects with any digital pin of Arduino when IR pair use as Digital Sensor.

4. A connects with analog input pin of Arduino when IR pair use as Analog Sensor

3. Building Circuit

S. No. Item Required for making this project Buy on Amazon Buy on Robo India
1.Arduino UNOclick hereclick here
2.IR Sensorclick hereclick here
3.Jumper Wireclick hereclick here

Digital Interfacing:

Analog Interfacing:

3. Programming:

You may download this arduino sketch (code) for digital output from here.

const int ProxSensor=2;
int inputVal = 0;

void setup() 
{                
  pinMode(13, OUTPUT);          // Pin 13 has an LED connected on most Arduino boards:  
  pinMode(ProxSensor,INPUT);    //Pin 2 is connected to the output of proximity sensor
  Serial.begin(9600);
}

void loop() 
{
  if(digitalRead(ProxSensor)==HIGH)      //Check the sensor output
  {
    digitalWrite(13, HIGH);   // set the LED on
  }
  else
  {
    digitalWrite(13, LOW);    // set the LED off
  }
inputVal = digitalRead(ProxSensor);
Serial.println(inputVal);
delay(1000);              // wait for a second
}




You may download this arduino sketch (code) for analog output from here.

const int ProxSensor=A0;
int inputVal = 0;

void setup() 
{                
  pinMode(13, OUTPUT);          // Pin 13 has an LED connected on most Arduino boards:  
  pinMode(ProxSensor,INPUT);    //Pin 2 is connected to the output of proximity sensor
  Serial.begin(9600);
}

void loop() 
{
  if(digitalRead(ProxSensor)==HIGH)      //Check the sensor output
  {
    digitalWrite(13, HIGH);   // set the LED on
  }
  else
  {
    digitalWrite(13, LOW);    // set the LED off
  }
inputVal = analogRead(ProxSensor);
Serial.println(inputVal);
delay(1000);              // wait for a second
}




4. Output

Place the object in front of IR proximity sensor and observe the change in LED connected to board. When you remove object you will see it gets turned off.

The sensor outputs a logic 1 (+5V) at the digital output when an object is placed in front of the sensor and a logic 0 (0V), when there is no object in front of the sensor.

Do the same for Analog output. Arduino scales an analog signal in a range of 0-1023.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com


1 Comment

Leave a Reply