NodeMCU With LDR





Introduction: NodeMCU With LDR

Wassup Makers!

I'm with another simple Instructable. In this Instructable we will learn how to interface LDR called as Light Dependent Resistor with NodeMCU.

What is a Light Dependent Resistor or a Photo Resistor?

A Light Dependent Resistor (LDR) or a photo resistor is a device whose resistivity is a function of the incident electromagnetic radiation. Hence, they are light sensitive devices. They are also called as photo conductors, photo conductive cells or simply photocells. They are made up of semiconductor materials having high resistance.

Step 1: What You Need

List of parts required:

Hardware Required

  • NodeMCU
  • LDR / photoresistor
  • 10k ohm resistor
  • Breadboard
  • Micro USB cable
  • Connecting Wires

Software Required

  • Arduino IDE (with ESP8266 Library installed)

Step 2: Circuit Connections

The LDR output is actually analog in nature, so it gets connected to the A0 pin of the NodeMCU.

Really quite simple right, just wire your prototype up like the schematic.

Before you get started with coding you need Arduino IDE.To download Arduino IDE and for NodeMCU setup, you can check my previous instructacle.

"Interfacing Servo Motor With NodeMCU"

Step 3: Coding Time

void setup() {
	Serial.begin(9600);   // initialize serial communication at 9600 BPS
void loop() {

	int sensorValue = analogRead(A0);   // read the input on analog pin 0

	float voltage = sensorValue * (5.0 / 1023.0);   // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V)

	Serial.println(voltage);   // print out the value you read


Download the "LDR.ino" file and open it up in the Arduino IDE.

Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload.

You can tinker with it if you like based on the application, or just use it as it is.

Step 4: Output

That's all makers!

It takes less time to create this instructable, and its fun too.
Thank you for taking your time to read my instructable. I hope you enjoy it as I enjoy making it and documenting it to show and tell to other fellow makers here.

CIAO!! with another interesting Instructables!



    • Trash to Treasure

      Trash to Treasure
    • Paper Contest 2018

      Paper Contest 2018
    • Science of Cooking

      Science of Cooking

    We have a be nice policy.
    Please be positive and constructive.



    I have seen a problem in your program. You are using 3.3 V in your circuit so you want to convert the analog reading of 0-3.3 V range of voltage, not 0-5 V. Am I right? Correct me if I'm wrong. Thanks