from machine import Pin, ADC, I2C
import time
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
# Simulated sensors (for demo)
pH_sensor = ADC(0)
turbidity_sensor = ADC(1)
tds_sensor = ADC(2)
# LCD Setup (simulated)
I2C_ADDR = 0x27
i2c = I2C(0)
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
def read_ph():
return round(7.0 + (pH_sensor.read_u16() / 65535 * 2 - 1), 2)
def read_turbidity():
return round(turbidity_sensor.read_u16() / 655.35, 1)
def read_tds():
return round(tds_sensor.read_u16() / 65.535, 0)
def analyze_water():
ph = read_ph()
turbidity = read_turbidity()
tds = read_tds()
lcd.clear()
lcd.putstr("pH: {:.1f} Tur: {:.1f}\n".format(ph, turbidity))
time.sleep(1.5)
if ph < 6.5 or ph > 8.5 or turbidity > 5 or tds > 500:
lcd.putstr("RESULT: UNSAFE!\nHigh Contamination")
print("⚠️ WATER IS NOT SAFE")
else:
lcd.putstr("RESULT: SAFE TO DRINK")
print("✅ WATER IS SAFE")
print("Blue Pulse Water Tester Ready")
print("Change sensor sliders in Wokwi to simulate different water samples")
while True:
analyze_water()
time.sleep(3)