LDR (Light Dependent Resistor)
In this section, we will use an LDR (Light Dependent Resistor) with the Raspberry Pi Pico 2 W. An LDR changes its resistance based on the amount of light falling on it. The brighter the light, the lower the resistance, and the dimmer the light, the higher the resistance. This makes it ideal for applications like light sensing, automatic lighting, or monitoring ambient light levels.
How LDR Works
An LDR changes its resistance based on the amount of light falling on it. The brighter the light, the lower the resistance, and the dimmer the light, the higher the resistance. Think of the LDR as Dracula: in sunlight, he gets weaker (resistance gets lower), but in the dark, he gets stronger (resistance gets higher).
Components Needed
- LDR (Light Dependent Resistor)
- Resistor (typically 10kΩ) - needed to create voltage divider
- Jumper wires
Prerequisites
Before working with LDRs, you should understand:
- Voltage divider circuits
- ADC (Analog to Digital Converter)
Voltage Divider with LDR
We use an LDR in a voltage divider circuit to convert resistance changes into voltage changes that the Pico 2 W can read via its ADC. The output voltage changes based on ambient light levels.
Pico 2 W Considerations:
The Pico 2 W has GPIO 23, 24, 25, and 29 reserved for wireless functionality. Use other GPIO pins (like GPIO 26-28) for ADC readings with sensors.
Circuit Connection
Connect the LDR and resistor in series between 3.3V and GND, with the midpoint connected to an ADC pin (GPIO 26). As light intensity changes, the voltage at the midpoint changes, which the Pico reads as an ADC value.
3.3V → LDR → GPIO26 (ADC0) → 10kΩ Resistor → GND
Next Steps
In the next chapter, we'll create a project that automatically turns on an LED when ambient light levels drop below a threshold - perfect for automatic night lights!