Guest User

Watering Pico

a guest
May 27th, 2021
35
246 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from machine import Pin
  2. from time import sleep
  3. import machine
  4. import utime
  5.  
  6. led = Pin(25, Pin.OUT)
  7. led.high()
  8. utime.sleep(1.5)
  9. led.low()
  10.  
  11. SENSOR_MIN = 38000
  12. SENSOR_MAX = 58500
  13.  
  14. analog_value = machine.ADC(26)
  15.  
  16. sleep(1.5)
  17.  
  18. relay1 = Pin(2, Pin.OUT)
  19.  
  20. while True:
  21.     reading = analog_value.read_u16()
  22. #   print("ADC: ",reading)
  23.     percent = round(((reading - SENSOR_MAX) / (SENSOR_MIN - SENSOR_MAX)) * 100)
  24.     print("Percent:", percent)
  25.  
  26.     if (percent == 0):
  27.         print("Alert, No Water!")
  28.         utime.sleep(1)
  29.  
  30.     if (percent >= 70):
  31.         print("Alert, Too Much Water!")
  32.         utime.sleep(1)
  33.  
  34.     if (percent <= 30):
  35.         print("Watering")
  36.         relay1.toggle()
  37.         utime.sleep(.5)
  38.         relay1.toggle()
  39.         utime.sleep(2)
  40.  
  41.  
  42.     utime.sleep(2)
RAW Paste Data