NodeMCU With LDR




About: " Work until you no longer have to introduce yourself " Show some love on Instagram & Motivate me on YouTube @TheCircuit

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!



    • Comfort Food Challenge

      Comfort Food Challenge
    • Safe and Secure Challenge

      Safe and Secure Challenge
    • Faux-Real Contest

      Faux-Real Contest

    3 Discussions

    Tài Nguyễn

    Question 10 months ago

    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

    2 answers
    S. JacobPTài Nguyễn

    Answer 6 months ago

    I also thought that, I think that is correct (the photoresistor will not be able to output more than 3.3 V since it is connected to 3.3, so I think that solves it)

    RunePS. JacobP

    Reply 5 weeks ago

    In the fritzing its connected to the 3.3 but in the picture its conected to vin...
    vin is 5v i think..