Whether you’re building a robot or configuring a monitor, begin your project by noticing the ambient light in your workspace. This reading may lead you to adjust the brightness of a clock or other display, or even set up an automatic nightlight that senses a darkening room. Light-dependent resistors (LDRs) are the key to building automated lighting. LDRs are useful and inexpensive, making them an excellent choice if you’d like to experiment without breaking the bank. We’ll pair an LDR with an Arduino Uno board to demonstrate how they operate together.
First, here’s a quick demonstration of how to use an LDR:
What’s Happening Here?
You may wonder why you’re unable to hook the LDR straight from the +5V pin to the A0 pin. While the LDR’s resistance does change, you don’t have a voltage divider in this setup. Whether resistance is relatively high or low, it’s all “seen” across the LDR component, fixing A0 at +5V. When you add the resistor to ground, it forms a voltage divider. Now the LDR must “spread” the voltage across the two resistors in series, and A0 senses the middle value.
The equation at work here is:
To see what happens without a voltage divider, pull the ground pin out of the circuit board temporarily. You’ll see the serial monitor number jump up to 1023, indicating that the full 5V of potential is set at that pin.
The resistor on the left is 2 kilohms, and the resistor on the right is 220 ohms.
The easiest way to measure voltage is to use a multimeter. The magic of Arduino and other dev boards is that you can program them to react automatically to changing conditions. For example, your LDR and Arduino can adjust the intensity of an LED in response to the ambient lighting in the room. You can build this device in a few steps:
Depending on the amount of light that the LDR sees (and thus the voltage at A0) the LED will brighten or dim as needed. Pairing the LDR with an Arduino Uno helps make sure your LED doesn’t shine too brightly for its environment. This application is just one example of how to use these inexpensive sensors in your workshop.