Introduction: Auto-LED Using LDR With NodeMCU

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.

Step 1: What You Will Need

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)

Step 2: Circuit Connection

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"

Step 3: 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.

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!

Comments

About This Instructable

499views

14favorites

License:

Bio: Work until you no longer have to introduce yourself.
More by TheCircuit:Carrot Almond MilkshakeDIY - Flower VasePotato Stuffing - Who's Hungry
Add instructable to: