Question 12.2: You want to measure light intensity with a Raspberry Pi and ......

You want to measure light intensity with a Raspberry Pi and a photoresistor.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

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
12.4

Related Answered Questions

Question: 12.11

Verified Answer:

Use the Tkinter library to open a window and write...
Question: 12.10

Verified Answer:

Use a low cost SR-04 rangefinder. These devices ne...
Question: 12.12

Verified Answer:

Write a Python program that writes the data to a f...
Question: 12.9

Verified Answer:

Use the DS18B20 digital temperature sensor. This d...
Question: 12.7

Verified Answer:

Use an MCP3008 ADC chip. However, unless you need ...
Question: 12.8

Verified Answer:

Use an analog accelerometer with a MCP3008 ADC chi...
Question: 12.6

Verified Answer:

Use a potential divider with one fixed resistor an...
Question: 12.3

Verified Answer:

Low-cost resistive gas sensors are available that ...
Question: 12.4

Verified Answer:

The Raspberry Pi GPIO connector has only digital i...
Question: 12.5

Verified Answer:

Use a pair of resistors to act as a voltage divide...