Photoresistors, also known as light dependent resistors (LDRs) or photocells, are low-cost variable resistors where the resistance changes depending on the amount of light hitting its surface. In dark environments the resistance is high; in light environments the resistance is lower. Due to the imprecise nature of photoresistors, they are unsuitable for measuring exact levels of light but are capable of detecting changes. They can be used to respond to events such as the transition from daytime to night-time (and vice versa) for home automation and gardening applications, and are often used to control street lighting. Photoresistors placed inside an enclosure can detect when it is opened or, with careful design, detect the presence of objects that block the sensor when inserted.
The code and circuits below describe the use of a photoresistor with an Arduino. Although a straightforward process, this is not an in-depth guide and beginners who are unfamiliar with that platform may wish to look at a step-by-step guide to learning the basics of the Arduino. People from an electronic engineering background might prefer a more advanced course that covers wiring, installation and programming of the Arduino and interfacing with LabView.
To complete the tutorial, you will need:
An Arduino or Arduino-compatible board with analog inputs.
The Arduino IDE (integrated development environment).
A photoresistor (photocell/light dependent resistor) such as the ones from Adafruit (USA) or Maplin (UK).
One 10Ko resistor.
One 10Ko potentiometer (variable resistor).
A breadboard and connecting wires (or suitable stripboard and soldering equipment).
Working with electricity, even at low voltages, can be dangerous – follow the connection diagrams and instructions carefully, and always seek advice from a qualified and experienced adult if you are unsure.
Theory of Operation
Shown below is a diagram of a breadboard circuit that you can use to begin experimenting. The photoresistor and the 10Ko resistor are powered by the Arduino’s 5V power supply and form a potential divider, which protects the Arduino from short circuits and ensures that at least some resistance is always present on the line.
A wire is connected from this circuit to analog input 0 on the Arduino. Resistors lower the voltage passing through them, and so to read changes in light from this circuit, you can use the Arduino’s analog to digital converters (ADCs) to measure the voltage level of the input. The ADCs convert the analog value to an integer in the range 0 through 1023.
When the photoresistor is exposed to light, its resistance decreases and so the voltage reading will be higher. When light is blocked, the resistance of the photoresistor increases and so the voltage reading will be lower.