Project 3.9.66: Smart Water Intelligence Dashboard
Advanced Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
The Pico measures water demand and stored supply, then shows a local dashboard that explains whether the system is healthy or under pressure.
Water data is hard to act on when users see raw values but no clear interpretation of what they mean together.
A Pico 2 W prototype with a pulse flow sensor, analog water-level sensor, and OLED dashboard.
Water-system interpretation, dashboard design, and transparent infrastructure-style status labels.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() Water level sensor |
![]() Breadboard |
![]() Jumper wires |
![]() OLED |
|||
| --- |
Circuit Connections
| Component terminal | Connect to | Pico physical pin | Notes |
|---|---|---|---|
| Flow sensor pulse output | GPIO 14 | GPIO 14 / physical pin 19 | 3.3V-safe pulse input |
| Water level analog output | GPIO 27 ADC1 | GPIO 27 / physical pin 32 | Storage level input |
| OLED SDA | GPIO 20 | GPIO 20 / physical pin 26 | I2C0 SDA |
| OLED SCL | GPIO 21 | GPIO 21 / physical pin 27 | I2C0 SCL |
| --- |
Wiring Diagram

Flow pulse output -> GPIO 14
Level analog output -> GPIO 27
GPIO 20 -> OLED SDA
GPIO 21 -> OLED SCL
Common GND -> flow sensor, level sensor, and OLED
Diagram Placeholder [Insert wiring diagram or breadboard image here]
Step-by-Step Assembly
- Connect the flow sensor pulse output to GPIO 14 and confirm it is 3.3V-safe.
- Connect the analog level sensor output to GPIO 27 through a safe ADC path.
- Connect the OLED to Pico 3.3V, GND, GPIO 20, and GPIO 21.
- Upload ssd1306.py and confirm it appears on the Pico before running the dashboard.
- Record low and high storage references before trusting the percentage display.
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: Test flow and level separately so the dashboard is built from believable values.
- Test the output device: Run an OLED hello-world test before adding the water dashboard logic.
- Test the decision logic: Change demand and storage one factor at a time and confirm the status changes logically.
- Run the full system: Run the full dashboard and compare the status with the printed flow and storage values.
- Validate the prototype: Discuss whether a human operator would understand the dashboard quickly enough in a real setting.
- 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.
Upload and run this code after the individual tests work correctly.
from machine import ADC, I2C, Pin
import time
try:
from ssd1306 import SSD1306_I2C
HAS_OLED = True
except ImportError:
HAS_OLED = False
FLOW_PIN = 14
LEVEL_PIN = 27
I2C_SDA_PIN = 20
I2C_SCL_PIN = 21
LEVEL_EMPTY = 12000
LEVEL_FULL = 52000
SAMPLE_WINDOW_S = 5
pulse_count = 0
flow = Pin(FLOW_PIN, Pin.IN, Pin.PULL_UP)
level = ADC(LEVEL_PIN)
i2c = I2C(0, sda=Pin(I2C_SDA_PIN), scl=Pin(I2C_SCL_PIN), freq=400000)
if HAS_OLED:
oled = SSD1306_I2C(128, 64, i2c)
def count_pulse(pin):
global pulse_count
pulse_count += 1
def clamp(value, low, high):
return max(low, min(high, value))
def level_percent(raw):
span = LEVEL_FULL - LEVEL_EMPTY
if span <= 0:
return 0
pct = int((raw - LEVEL_EMPTY) * 100 / span)
return clamp(pct, 0, 100)
def flow_lpm_from_pulses(pulses, seconds):
if seconds <= 0:
return 0.0
return (pulses / seconds) / 7.5
flow.irq(trigger=Pin.IRQ_FALLING, handler=count_pulse)
print('Smart water intelligence dashboard ready')
while True:
pulse_count = 0
start = time.ticks_ms()
while time.ticks_diff(time.ticks_ms(), start) < SAMPLE_WINDOW_S * 1000:
time.sleep_ms(100)
flow_lpm = flow_lpm_from_pulses(pulse_count, SAMPLE_WINDOW_S)
storage_pct = level_percent(level.read_u16())
if flow_lpm > 4.0 or storage_pct < 20:
status = 'CRITICAL'
elif flow_lpm > 2.0 or storage_pct < 40:
status = 'STRESSED'
else:
status = 'HEALTHY'
print('Flow:{:.2f}L/min Storage:{}% Status:{}'.format(flow_lpm, storage_pct, status))
if HAS_OLED:
oled.fill(0)
oled.text('Water Intel', 0, 0)
oled.text('Flow:{:.1f}L'.format(flow_lpm), 0, 18)
oled.text('Store:{}%'.format(storage_pct), 0, 34)
oled.text(status, 0, 50)
oled.show()
time.sleep(2)
How the Code Works
| Code Section | What It Does | Why It Matters | What to Modify During Testing |
|---|---|---|---|
| Pulse and level conversion | Turns the sensor signals into flow and storage values. | Users need meaningful dashboard values rather than raw counts. | Update calibration values only after you measure your own hardware. |
| Status rules | Combines supply and demand into HEALTHY, STRESSED, or CRITICAL. | This is the intelligence layer promised by the project title. | Tune the thresholds after repeated trials with known conditions. |
| OLED dashboard | Shows the current water state on one local screen. | A readable dashboard makes the system easier to validate and explain. | Verify ssd1306.py and the I2C wiring if the display is blank. |
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 works well for classroom demonstrations and local monitoring pilots.
- Before deployment, it needs calibration records, protective mounting, and regular validation checks.
- Display-only systems still depend on correct sensor placement and trained users.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Flow stays at zero | The pulse signal is not reaching GPIO 14 | Print the pulse count during a known flow event and verify the sensor signal path. |
| Storage never changes | The level sensor wiring or calibration is wrong | Print the raw ADC value and re-measure the low and high references. |
| The status is always critical | The thresholds are too strict for your test setup | Collect baseline values and adjust the status thresholds carefully. |
| OLED is blank | The display library or I2C wiring is wrong | Confirm ssd1306.py is present and verify GPIO 20 and GPIO 21. |




