Project 3.1.27: Solar Light Failure Alert
Advanced Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
The Pico reads a scaled lighting-line voltage and warns when a solar-powered light system drops below its expected operating range.
Off-grid lighting systems are hard to maintain if no one notices a weak battery or failed output line until the light is already dark.
A Pico 2 W prototype with a voltage divider module, LED, and buzzer for local maintenance alerts.
Analog voltage monitoring, threshold interpretation, and honest limits around what a simple maintenance prototype can claim.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() Breadboard |
![]() Jumper wires |
![]() LED |
![]() Resistor |
![]() Buzzer |
Circuit Connections
| Component terminal | Connect to | Pico physical pin | Notes |
|---|---|---|---|
| Voltage divider output | GPIO 26 ADC0 | GPIO 26 / physical pin 31 | Scaled analog voltage |
| Voltage divider GND | GND | Physical pin 38 | Common ground |
| LED anode | 220 ohm resistor to GPIO 15 | GPIO 15 / physical pin 20 | Warning LED |
| Buzzer positive | GPIO 16 | GPIO 16 / physical pin 21 | Critical buzzer |
Wiring Diagram

Voltage divider output -> GPIO 26
GND -> divider GND, LED cathode, buzzer negative
GPIO 15 -> 220 ohm resistor -> LED anode
GPIO 16 -> buzzer positive
Step-by-Step Assembly
- Connect the divider module output pin to GPIO 26 and its ground to Pico GND.
- Connect the divider input to the low-voltage DC line you want to monitor.
- Wire the LED to GPIO 15 through a 220 ohm resistor and connect the LED cathode to GND.
- Connect the buzzer positive pin to GPIO 16 and the negative pin to GND.
- Verify the expected maximum line voltage stays within the divider module's safe range before powering the system.
Testing Individual Components
Before running the full project, test each subsystem separately. This makes it easier to find wiring, library, or logic problems before full integration.
- Hardware setup: Assemble the Pico, sensor, indicator, and load wiring exactly as shown in the connection table before applying power.
- Test the input sensor: Measure the divider output at known input voltages so the conversion formula matches your real module.
- Test the output device: Test the LED and buzzer outputs separately before linking them to voltage thresholds.
- Test the decision logic: Confirm that the warning and critical states change at the intended line-voltage values.
- Run the full system: Run the full system across several test voltages and compare the printed estimate with a multimeter.
- Validate the prototype: Check whether noise, weak connectors, or supply sag change the stability of the alert.
- Save the project: Save the validated program on the Pico as main.py and keep a copy on the computer for future edits.
Full Project Code
After completing and checking the circuit connections, open Thonny IDE, copy and paste this code into a new file or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.
from machine import ADC, Pin
import time
VOLTAGE_PIN = 26
LED_PIN = 15
BUZZER_PIN = 16
DIVIDER_RATIO = 5.0
WARNING_VOLTAGE = 10.5
CRITICAL_VOLTAGE = 9.5
voltage_sensor = ADC(VOLTAGE_PIN)
led = Pin(LED_PIN, Pin.OUT)
buzzer = Pin(BUZZER_PIN, Pin.OUT)
def read_voltage(samples=8):
total = 0
for _ in range(samples):
total += voltage_sensor.read_u16()
time.sleep_ms(20)
raw = total / samples
adc_voltage = raw * 3.3 / 65535
line_voltage = adc_voltage * DIVIDER_RATIO
return raw, line_voltage
print("Solar light failure alert ready")
while True:
raw, line_voltage = read_voltage()
if line_voltage <= CRITICAL_VOLTAGE:
status = "CRITICAL"
led.on()
buzzer.on()
elif line_voltage <= WARNING_VOLTAGE:
status = "WARNING"
led.on()
buzzer.off()
else:
status = "NORMAL"
led.off()
buzzer.off()
print("Raw: {:.0f} | Voltage: {:.2f} V | Status: {}".format(raw, line_voltage, status))
time.sleep(1)
How the Code Works
| Code Section | What It Does | Why It Matters | What to Modify During Testing |
|---|---|---|---|
| Voltage conversion | Converts a scaled ADC reading back into estimated system voltage | Maintenance decisions depend on voltage, not just raw ADC units | Measure your real divider ratio before changing DIVIDER_RATIO |
| Threshold constants | Defines the warning and critical maintenance limits | Separate thresholds let the user act before a total failure occurs | Adjust WARNING_VOLTAGE and CRITICAL_VOLTAGE to match your actual low-voltage system |
| read_voltage | Averages several ADC samples for a more stable estimate | Voltage lines can be noisy, especially when loads switch on and off | Increase the sample count if the estimate flickers too much |
| Alert outputs | Turns on the LED for warning and both LED and buzzer for critical voltage | This keeps the alert simple and easy to validate in class | Reserve the buzzer for the critical state if the warning stage is enough for routine checks |
Expected Result
The serial monitor reports the current reading or state clearly.
The hardware output responds when the decision logic changes state.
Subsystem behavior matches the thresholds, timing, or rules described in the document.
Validation Checks
- Normal condition test: confirm the system stays in its safe or idle state under baseline conditions
- Warning condition test: move the input close to the chosen threshold and confirm the transition is sensible
- Critical condition test: trigger the strongest alert or control state and confirm the output response is correct
- Calibration test: compare the sensor or timing against a known reference or repeated trial
- Limitation test: deliberately create an awkward or noisy condition and note how the prototype behaves
Deployment and Limitations
- This prototype can be used for local warning demonstrations and early field trials
- Before deployment, it needs enclosure protection, calibration records, and a clear response procedure
- Alert systems should always be treated as decision-support tools unless they are certified for the application
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Voltage estimate is far from the multimeter | Divider ratio is wrong | Measure the real divider output and update DIVIDER_RATIO accordingly |
| System is always in warning | Thresholds do not match the monitored supply | Set thresholds that make sense for the actual 6V or 12V system under test |
| ADC reading never changes | Divider output or ground is disconnected | Recheck the analog output wire and common ground path |
| Buzzer never activates | Critical threshold is too low or the buzzer is miswired | Raise CRITICAL_VOLTAGE temporarily and verify the buzzer with a direct test |





