This tutorial of Robo India explains how to use LDR on NodeMCU using Arduino IDE.
Detailed Tutorial
1. Introduction:
An LDR (Light Dependent Resistor) or a photo resistor is a photo conductive sensor. It is a variable resistor that changes it’s resistance in a proportion to the light exposed to it. Its resistance decreases with the intensity of light.
1.3 Hardware required
S.No. | Item | Quantity |
1 | NodeMCU | 1 |
2 | Breadboard | 1 |
3 | LDR | 1 |
4 | Resistor 10k | 1 |
5 | Jumper Male to male | 5 |
2. Building Circuit
Schematic of circuit
Layout of circuit
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 Tutorial // Digital Input and Output on LED // Hardware: NodeMCU const int LDR = A0; // Defining LDR PIN int input_val = 0; // Varible to store Input values void setup() { Serial.begin(9600); } void loop() { input_val = analogRead(LDR); // Reading Input Serial.print("LDR value is : " ); Serial.println(input_val); // Writing input on serial monitor. delay(1000); }
4. Output
Values of LDR depend upon the light exposed on it. These values are displayed on the serial monitor.
5. Troubleshooting
Values are not changing: Control light exposing on LDR by covering it. LDR values change on the amount of light exposed on the LDR.
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com