NodeMCU With LDR

by CodeChamp in Circuits > Sensors

65093 Views, 35 Favorites, 0 Comments

NodeMCU With LDR

Main.jpeg

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.

What You Need

4.jpeg
5.jpeg
3.jpeg
2.jpeg
0.jpeg
6.jpeg
1.jpeg

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)

Circuit Connections

CKT.png
ldr-nodemcu.png
4.jpg
2.jpg
0.jpg

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"

Coding Time

Capture.PNG
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.

Downloads

Output

Out.jpeg
2.PNG
3.PNG
1.PNG

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!