Project 2.6.33: Smart Water Quality Proxy System
Intermediate Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
This project builds a proxy water-quality monitor that compares sensor readings against a clean-water baseline and reports changes.
Students will connect an analog proxy sensor, capture a baseline from a known clean sample, classify new readings as GOOD, WATCH, or POOR, and add a recalibration button.
The final system should show when a test sample stays close to the clean baseline, when it drifts into a watch zone, and when the change becomes large enough to trigger a poor-quality proxy alert.
Required Components
![]() Analog water-quality proxy sensor |
![]() Red LED and 220 Ω resistor |
![]() Raspberry Pi Pico 2 W |
![]() Push button |
![]() Green LED and 220 Ω resistor |
![]() Yellow LED and 220 Ω resistor |
![]() Breadboard and jumper wires |
Circuit Connections
| Component terminal | Connect to | Pico physical pin | Notes |
|---|---|---|---|
| Proxy sensor VCC | Module dependent | Follow sensor label | Use a safe supply arrangement for your sensor |
| Proxy sensor GND | GND | Any GND pin | Common ground |
| Proxy sensor analog output | GPIO 26 | GPIO 26 / physical pin 31 | Make sure the signal stays within 0 to 3.3V |
| Baseline button one side | GPIO 5 | GPIO 5 / physical pin 7 | Uses internal pull-up |
| Baseline button other side | GND | Any GND pin | Pressing pulls the input low |
| Green LED anode | GPIO 16 through 220 Ω resistor | GPIO 16 / physical pin 21 | Good indicator |
| Yellow LED anode | GPIO 17 through 220 Ω resistor | GPIO 17 / physical pin 22 | Watch indicator |
| Red LED anode | GPIO 18 through 220 Ω resistor | GPIO 18 / physical pin 24 | Poor indicator |
| LED cathodes | GND | Any GND pin | Return path |
Wiring Diagram

Analog proxy sensor output -> GPIO 26
Baseline button -> GPIO 5 and GND
GPIO 16 -> 220Ω -> Green LED anode
GPIO 17 -> 220Ω -> Yellow LED anode
GPIO 18 -> 220Ω -> Red LED anode
LED cathodes -> GND
Step-by-Step Assembly
Step 1: Place the Raspberry Pi Pico 2W
Place the Raspberry Pi Pico 2W on the breadboard so it sits across the center gap. Keep the USB port facing outward so you can easily connect it to your computer.
Step 2: Position the Water-Quality Proxy Sensor
Place the proxy sensor so only the sensing area or approved probe area reaches the test sample. Identify VCC, GND, and analog output before wiring.
Step 3: Connect the Proxy Sensor
Connect sensor VCC to the safe supply required by the module label. Connect sensor GND to GND. Connect the sensor analog output to GPIO 26. Confirm the signal reaching GPIO 26 stays within 0V to 3.3V.
Step 4: Place the Baseline Button
Place the baseline push button across the breadboard center gap. Connect one side of the baseline button to GPIO 5. Connect the opposite side of the button to GND.
Step 5: Place the Three Quality LEDs
Place the green, yellow, and red LEDs on the breadboard. For each LED, identify the long leg as the anode (+) and the short leg as the cathode (-).
Step 6: Connect the Quality LEDs
Connect the green LED long leg through a 220Ω resistor to GPIO 16. Connect the yellow LED long leg through a 220Ω resistor to GPIO 17. Connect the red LED long leg through a 220Ω resistor to GPIO 18. Connect all LED short legs to GND.
Wiring Check
- [x] Pico 2W is placed correctly across the breadboard center gap
- [x] Proxy sensor analog output connects to GPIO 26
- [x] Proxy sensor output is confirmed 3.3V-safe before connecting to the Pico
- [x] Baseline button connects between GPIO 5 and GND
- [x] Green LED long leg connects through a 220Ω resistor to GPIO 16
- [x] Yellow LED long leg connects through a 220Ω resistor to GPIO 17
- [x] Red LED long leg connects through a 220Ω resistor to GPIO 18
- [x] All LED short legs connect to GND
- [x] No loose jumper wires
Intermediate Note Use a clean reference sample first and press the baseline button to store the calibration reading. Compare changed samples only after the baseline is stable.
Safety Note Keep the Pico, breadboard, USB cable, and jumper wires away from liquids. This project is a proxy monitor only and must not be used to declare water safe for drinking.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring, library, or code problems.
Hardware Setup
- Build the sensor and button wiring first, then add the status LEDs
- Keep the sample container away from the Pico so only the sensing part is near the liquid
Test the Input Sensor
- Read the raw ADC value in a clean reference sample and then in a changed sample to see how much the sensor moves
- Press the baseline button and confirm the serial monitor reports the new baseline value
Test the Output Device
- Force the code into GOOD, WATCH, and POOR states briefly and confirm the LEDs respond correctly
- Check that the red alert does not trigger from only one unstable reading
Test Communication
- Watch the Thonny Shell and confirm it prints the raw reading, baseline, delta, and current proxy state
- Use the printed delta values to tune the watch and poor thresholds
Run the Full System
- Capture a clean-water baseline and then test one or more changed samples
- Confirm the state changes as the sample moves farther away from the clean baseline
Save the Project
- Save the final code and record the baseline and threshold values that worked with your sensor
- Write down the limits of this proxy method before using it in a real sanitation discussion
Additional Testing and Calibration Checks
- Baseline test: press the button in a clean sample and record the stored baseline value
- Normal condition test: keep the sensor in the same sample and confirm the state stays stable
- Threshold condition test: test one slightly changed sample and one strongly changed sample to compare WATCH and POOR behaviour
- Output response test: confirm the LEDs match the printed state
- Calibration note: different proxy sensors respond differently, so WATCH_DELTA and POOR_DELTA must be tuned to your sensor
Full Project Code
After completing and checking the circuit connections, open Thonny IDE. Copy and paste the code below 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
proxy_sensor = ADC(26)
baseline_button = Pin(5, Pin.IN, Pin.PULL_UP)
green_led = Pin(16, Pin.OUT)
yellow_led = Pin(17, Pin.OUT)
red_led = Pin(18, Pin.OUT)
WATCH_DELTA = 4000
POOR_DELTA = 9000
CONFIRM_READS = 3
DEBOUNCE_MS = 250
baseline = proxy_sensor.read_u16()
poor_hits = 0
last_button_ms = 0
def button_pressed():
global last_button_ms
now_ms = time.ticks_ms()
if baseline_button.value() == 0 and time.ticks_diff(now_ms, last_button_ms) > DEBOUNCE_MS:
while baseline_button.value() == 0:
time.sleep(0.02)
last_button_ms = now_ms
return True
return False
print('=== Smart Water Quality Proxy System ===')
print('Press the button while the sensor is in a clean reference sample to store the baseline.\n')
while True:
raw = proxy_sensor.read_u16()
delta = abs(raw - baseline)
if button_pressed():
baseline = raw
poor_hits = 0
print('New baseline stored:', baseline)
if delta >= POOR_DELTA:
poor_hits += 1
else:
poor_hits = 0
if poor_hits >= CONFIRM_READS:
state = 'POOR'
green_led.value(0)
yellow_led.value(0)
red_led.value(1)
elif delta >= WATCH_DELTA:
state = 'WATCH'
green_led.value(0)
yellow_led.value(1)
red_led.value(0)
else:
state = 'GOOD'
green_led.value(1)
yellow_led.value(0)
red_led.value(0)
print('Raw: {} | Baseline: {} | Delta: {} | Poor hits: {} | State: {}'.format(
raw, baseline, delta, poor_hits, state
))
time.sleep(2)
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
| Baseline storage | Saves a clean reference value when the button is pressed | Students can compare change against a real starting point instead of a random number |
| Delta calculation | Measures how far the current sample is from the baseline | This is the main quality-proxy comparison step |
| Watch and poor thresholds | Separate small changes from larger changes | The system can show early drift before a strong alert |
| Confirmation count | Requires several large-delta readings before the POOR state is confirmed | This reduces false alerts from one noisy sample |
Expected Result
With the sensor in the clean reference sample, the green LED should stay on and the state should report GOOD.
When the sensor moves to a changed sample, the system should move into WATCH or POOR depending on how far the reading shifts from baseline.
Pressing the baseline button in a clean reference sample should store a new baseline and recalculate future comparisons from that point.
Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| The state is always POOR | The baseline was captured in the wrong sample or the thresholds are too small | Store a new baseline using a clean reference sample and increase the delta thresholds if needed |
| The button does not store a new baseline | The GPIO 5 wiring is wrong or the button is not pulling low | Recheck the button wiring and test the input state in the Shell |
| The readings are very noisy | The sensor wiring is unstable or the sample is moving around the sensor too much | Secure the wiring and keep the sensor position consistent while measuring |
| The Pico becomes unstable | A sensor output above 3.3V may be connected to the ADC | Use only a 3.3V-safe analog output or add proper signal conditioning |




