#11Beginner

Reading Light Intensity with Ldr

4.6(78)
119 completed
Reading Light Intensity with Ldr
Project that measures ambient light intensity with LDR sensor and displays it on Serial Monitor. Teaches the basics of analog sensor reading and serial communication.

Video

Circuit Diagram

Reading Light Intensity with Ldr - Circuit

Source Code

Arduino (C++)
1int value;
2
3void setup() {
4  Serial.begin(9600);
5}
6
7void loop() {  
8  value = analogRead(A0);
9  Serial.print("Value: ");
10  Serial.println(value);
11  delay(500);
12}

FAQ

How does LDR work?▾

As the amount of light falling on the LDR (light-dependent resistor) increases, its resistance decreases. When a voltage divider is created using a 10 kΩ resistor, changes in light are converted into changes in voltage and can be read as a value between 0 and 1023 using `analogRead`.

What should the readings be in light and dark conditions?▾

It depends on the connection type; generally, high values are observed in bright conditions and low values in dark conditions (or vice versa). Note the bright and dark values in its natural environment using the Serial Monitor; these will be used to select threshold values in future projects.

I'm seeing garbled characters in the Serial Monitor. Why is that?▾

The baud rate in the Serial Monitor must match the value specified in the `Serial.begin()` function in the code (e.g., 9600). If they differ, garbled characters will appear on the screen.

Is there a more sensitive light sensor than an LDR?▾

Yes, I2C light sensors like the BH1750 measure light directly in lux (lx) and are much more consistent than LDRs. An LDR is sufficient for simple night lights and darkness detection.

Reading Light Intensity with Ldr | BlueGrays