As discussed, an LDR varies its resistance in relation to the relative light it detects. To detect varying resistance with our Raspberry Pi, we need to take a few steps that were covered in previous chapters:
- We need to turn the varying resistance into a varying voltage because our Raspberry Pi GPIO pins work on voltage, not resistance. This is an application of Ohms law and a voltage-divider circuit, which we learned about in Chapter 6, Electronics 101 for the Software Engineer.
- Our Raspberry Pi GPIO pins can only read digital signals – for example, a high (~3.3 volts) or low (~0 volts) signal. To measure a varying voltage, we can attach an Analog-to-Digital Converter (ADC) such as an ADS1115. We covered the ADS1115 and accompanying Python code in Chapter 5, Connecting Your Raspberry Pi to the Physical World.
We are about to create the circuit illustrated in Figure 9.5 on your breadboard. This circuit and the accompanying code...