daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest May 24th, 2017 327 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import RPi.GPIO as GPIO
  2. from MCP3008 import MCP3008
  3. import time
  4.  
  5. ##################################################################
  6. ##################### CUSTOMIZEABLE SETTINGS #####################
  7. ##################################################################
  8. SETTINGS = {
  9.     "PLANTS": [
  10.         {
  11.             "NAME":                 "Tomaten",
  12.             "MOISTURE_CHANNELS":    [1, 2],     # of MCP3008
  13.             "MOISTURE_THRESHOLD":   50,         # if the average analog value of all sensors is above of this threshold, the Pump will turn on
  14.             "WATER_PUMP_GPIO":      23,         # GPIO Number (BCM) for the Relais
  15.             "WATERING_TIME":        10,         # Seconds, how long the pump should be turned on
  16.         },
  17.     ]
  18. }
  19. ##################################################################
  20. ################# END OF CUSTOMIZEABLE SETTINGS ##################
  21. ##################################################################
  22.  
  23.  
  24. def wateringPlants():
  25.     # read moisture
  26.     adc = MCP3008()
  27.     for plantObject in SETTINGS["PLANTS"]:
  28.         value = 0
  29.         for ch in plantObject["MOISTURE_CHANNELS"]:
  30.             # read 10 times to avoid measuring errors
  31.             v = 0
  32.             for i in range(10):
  33.                 v += adc.read( channel = ch )
  34.             v /= 1.0
  35.             value += v
  36.        
  37.         value /= float(len(plantObject["MOISTURE_CHANNELS"]))
  38.        
  39.         if value > plantObject["MOISTURE_THRESHOLD"]:
  40.             # turn pump on for some seconds
  41.             GPIO.setup(plantObject["WATER_PUMP_GPIO"], GPIO.OUT)
  42.             GPIO.output(plantObject["WATER_PUMP_GPIO"], GPIO.HIGH)
  43.             time.sleep(plantObject["WATERING_TIME"])
  44.             GPIO.output(plantObject["WATER_PUMP_GPIO"], GPIO.LOW)
  45.  
  46. if __name__ == '__main__':
  47.     try:
  48.         GPIO.setwarnings(False)
  49.         GPIO.setmode(GPIO.BCM)
  50.  
  51.         # execute functions
  52.         checkLight()
  53.         wateringPlants()
  54.         checkWindow()
  55.     except:
  56.         GPIO.cleanup()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top