Auto-LED Using LDR With NodeMCU

by CodeChamp in Circuits > Sensors

23469 Views, 19 Favorites, 0 Comments

Auto-LED Using LDR With NodeMCU

Main.jpeg

This is a simple NodeMCU project.

This circuit will turn ON the LED when it's dark and turn OFF when there is light.

Generally, LDR is a Light Dependent Resistor, whose resistance changes depending upon the intensity of the light incident on it.

What You Will Need

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

List of parts required for this instructable :

Hardware Required

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

Software Required

  • Arduino IDE (with ESP8266 Library installed)

Circuit Connection

a.jpeg
b.jpeg
c.jpeg
d.jpeg
e.jpeg
f.jpeg

LDR : Output is analog in nature, so it gets connected to the A0 pin of the NodeMCU.

LED : Anode is connected to D1 pin and Cathode to Ground (GND) pin of NodeMCU.

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

To know how LDR works with simple code you can check out my previous Instructable.

"NodeMCU With LDR"

Coding Time

const int ledPin = 5;
const int ldrPin = A0;

void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

pinMode(ldrPin, INPUT);

}

void loop() {

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <=300) {

digitalWrite(ledPin, HIGH); Serial.print(ldrStatus); Serial.println("LDR is DARK, LED is ON");

}

else {

digitalWrite(ledPin, LOW); Serial.println("LED is OFF");

}

}

Download the "LDR_2.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_1.jpg
Out_2.jpg

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!