You want to measure light intensity with a Raspberry Pi and a photoresistor.
Use the same basic recipe and code as Recipe 12.1, but replace the trimpot with a photoresistor.
To make this recipe, you will need:
• Breadboard and jumper wires (see “Prototyping Equipment” on page 380)
• Photoresistor (see “Resistors and Capacitors” on page 380)
• Two 1kΩ resistors (see “Resistors and Capacitors” on page 380)
• 220 nF capacitor (see “Resistors and Capacitors” on page 380)
Figure 12-4 shows the arrangement of components on the breadboard.
Using the same program as Recipe 12.1 (pot_step.py), you will see the output vary as you move your hand over the photoresistor to cut out some of the light.
Discussion
A photoresistor is a resistor whose resistance varies depending on the amount of light coming through its transparent window. The brighter the light, the lower the resistance. Typically, the resistance varies between about 1kΩ in bright light up to perhaps 100kΩ in complete darkness.
The sensors can only really give a rough idea of the light level.
See Also
You could also use an ADC with the photoresistor (Recipe 12.4)
Table A-3. Prototyping equipment | |
Description | Suppliers |
M-M jumper wires | SparkFun: PRT-08431, Adafruit: 759 |
M-F jumper wires | SparkFun: PRT-09140, Adafruit: 825 |
F-F jumper wires | SparkFun: PRT-08430, Adafruit: 794 |
Half-sized breadboard | SparkFun: PRT-09567 Adafruit: 64 |
Pi Cobbler | Adafruit: 1105 |
Table A-4. Resistors and capacitors | |
270Ω 0.25W resistor | Mouser: 293-270-RC |
470Ω 0.25W resistor | Mouser: 293-470-RC |
1kΩ 0.25W resistor | Mouser: 293-1k-RC |
3.3kΩ 0.25W resistor | Mouser: 293-3.3k-RC |
4.7kΩ 0.25W resistor | Mouser: 293-4.7k-RC |
10 kΩ trimpot | Adafruit: 356, SparkFun: COM-09806, Mouser: 652-3362F-1-103LF |
Photoresistor | Adafruit: 161, SparkFun: SEN-09088 |
220nF capacitor | MCM: 31-0610, Mouser: 80-C322C224M5U5HA |