This tutorial of Robo India explains how to use IR LED and photo diode as a color detection sensor and as a proximity detection sensor.
Detailed Tutorial
1. Introduction:
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.
This tutorial is for NodeMCU on Arduino IDE. Please note that the same tutorial can be performed on LUA as well.
1.2 Hardware required
S.No. | Item | Quantity |
1 | NodeMCU | 1 |
2 | Breadboard | 1 |
3 | IR LED & Photo Diode pair | 1 |
4 | Resistor 1k | 1 |
5 | Resistor 10k | 1 |
6 | Jumper Male to male | 7 |
2. Building Circuit
Schematic Diagram:
Circuit Layout:
3. Programming
Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run this circuit on NodeMCU.
You may download this code (Arduino Sketch) from here.
// Robo India Tutorials // Hardware: NodeMCU // Just simple ADC tutorial for reading Photo Diode values. const int photo_diode = A0; int inputVal = 0; void setup() { Serial.begin(9600); } void loop(){ inputVal = analogRead(photo_diode); Serial.print("Input Value: "); Serial.println(inputVal); delay(1000); }
4. Output
Place an object in front of the IR LED & Photo diode. The analog input values from photo diode are displayed on the serial monitor. Try using different colored surfaces and varying distance of object from the IR LED & photodiode.
5. Troubleshooting
Values are not changing: See the IR LED through a camera if it is not emitting any light, try changing polarity if still does not work try changing the IR LED. If values are still not changing by varying the distance or color of the surface then try changing polarity of the photo diode.
If still not working pull the led out and test it may be defective
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com