This tutorial of Robo India explain the working concept of Infrared(IR) sensor as Digital and Analog sensor with ESP8266.
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, NodeMCU, 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. Required Hardware
Following Hardware will be required to perform this LDR circuit.
S.No. | Item | Quantity |
1. | Arduino UNO | 1 |
2. | IR Sensor | 1 |
3. | Male to Female Jumper | 4 |
3. Hardware Interfacing
IR Sensor have four pins:
S.No. | IR Sensor | Node MCU |
1. | VCC | Vin |
2. | GND | GND |
3. | D | D1 (When IR Pair use as Digital Sensor) |
4. | A | A0 (When IR Pair use as Analog Sensor) |
4. Building Circuit
Digital Interfacing:
Analog Interfacing:
5. Programming:
You may download this arduino sketch (code) for digital output from here.
//Robo India tutorial on IR Sensor with ESP8266 //https://www.roboindia.com/tutorials/ const int ProxSensor=5; int LED = 16; void setup() { pinMode(LED, 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() { long state = digitalRead(ProxSensor); if(state == HIGH) //Check the sensor output { digitalWrite(LED, HIGH); // set the LED on Serial.println(state); delay(1000); } else { digitalWrite(LED, LOW); // set the LED off Serial.println(state); delay(1000); } }
You may download this arduino sketch (code) for analog output from here.
//Robo India tutorial on IR Sensor with ESP8266 //https://www.roboindia.com/tutorials/ const int ProxSensor=A0; int LED = 16; void setup() { pinMode(LED, 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() { long state = analogRead(ProxSensor); if(state == HIGH) //Check the sensor output { digitalWrite(LED, HIGH); // set the LED on Serial.println(state); delay(1000); } else { digitalWrite(LED, LOW); // set the LED off Serial.println(state); delay(1000); } }
6. 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