Trying to create a simple watering system, not quite finished yet. Got it going.
Currently connected to Mac via USB, though seems to lock when the program is run after a few seconds when the pump is powered, if I switch off the external pump power sublimed by three AA rechargeable batteries it is fine.
With the battery pack connected to the pump, Mu stops responding, or rather the Pico does?? and I have to unplug the usb to stop the program running and reset.
Any suggestions or errors I am making? The code is not tidy or complete yet.
Parts List
Pico: https://thepihut.com/products/raspberry-pi-pico
Relay board: https://thepihut.com/products/gravity-relay-module-v3-1
Capacitive soil moisture: https://thepihut.com/products/capacitiv ... ure-sensor
Water Pump:https://thepihut.com/products/submersib ... tical-type
Photos: https://www.icloud.com/photos/#0JNuWUAM ... etruibDI_g
# code here :-)
Code: Select all
from machine import Pin
import machine
import utime
SENSOR_MIN = 38000
SENSOR_MAX = 58500
analog_value = machine.ADC(26)
relay1 = Pin(2, Pin.OUT)
while True:
reading = analog_value.read_u16()
# print("ADC: ",reading)
percent = round(((reading - SENSOR_MAX) / (SENSOR_MIN - SENSOR_MAX)) * 100)
print("Percent:", percent)
if (percent == 0):
print("Alert, No Water!")
utime.sleep(1)
if (percent >= 70):
print("Alert, Too Much Water!")
utime.sleep(1)
if (percent <= 30):
print("Watering")
relay1.toggle()
utime.sleep(.5)
relay1.toggle()
utime.sleep(2)
utime.sleep(2)