Menu Close

NodeMCU LDR on Arduino IDE

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.ItemQuantity
1NodeMCU 1
2Breadboard 1
3LDR 1
4Resistor 10k 1
5Jumper 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

Leave a Reply