NodeMCU With LDR

54,487

34

4

Introduction: NodeMCU With LDR

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

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.

Attachments

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!

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

3 People Made This Project!

Recommendations

  • For the Home Contest

    For the Home Contest
  • Make It Bridge

    Make It Bridge
  • Big and Small Contest

    Big and Small Contest

4 Comments

0
Tài Nguyễn
Tài Nguyễn

Question 5 years 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

0
jnissen
jnissen

Answer 3 years ago

The ADC measures relative to 1V internally. The NODEMCU and WeMOS type devices use external resistors to scale a 3.3V full scale input so that it will be measured from 0 to 1V as required by the ADC. So the 0-1024 possible codes should be mapped to 3.3V as Tai stated in order to associate a code with a coresponding voltage.

0
S. JacobP
S. JacobP

Answer 4 years 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)

0
RuneP
RuneP

Reply 4 years ago

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