
The LDR (Light Dependent Resistor) is a simple but powerful sensor that detects light intensity. Its resistance decreases when light falls on it, and increases in darkness. By connecting an LDR with an ESP8266 Wi-Fi microcontroller, you can build smart IoT projects like:
In this tutorial, you’ll learn how to connect an LDR with ESP8266, read light levels in Arduino IDE, and understand the code step by step.
An LDR’s resistance:
Since ESP8266 cannot directly measure resistance, we use a voltage divider circuit to convert resistance changes into voltage that the ESP8266 can read using its ADC pin (A0).
This forms a voltage divider where the LDR and resistor share voltage depending on light intensity.

// LDR with ESP8266 Example
// Reads light intensity and prints to Serial Monitor
int ldrPin = A0; // LDR connected to analog pin A0
int ldrValue = 0; // Variable to store LDR value
void setup() {
Serial.begin(115200); // Start serial communication
}
void loop() {
ldrValue = analogRead(ldrPin); // Read value from LDR
Serial.print("Light Intensity: ");
Serial.println(ldrValue); // Print value on Serial Monitor
delay(1000); // Wait 1 second
}
int ldrPin = A0;
int ldrValue = 0;
void setup()
Serial.begin(115200); → Opens serial communication at 115200 baud rate to see values on Serial Monitor.void loop()
analogRead(ldrPin); → Reads light level (value between 0 and 1023).
Serial.print & Serial.println → Show the sensor value in Arduino Serial Monitor.delay(1000); → Updates reading every 1 second.In this tutorial, you learned how to:
This simple setup is the foundation of many IoT projects like automatic lights, smart homes, and energy-saving systems. 🚀
It ranges from 0 (dark) to 1023 (bright light).
No, you must use a resistor to form a voltage divider.
No, it only gives relative light intensity. For exact lux values, use sensors like BH1750.






