Переглянути джерело

untested code from the internet as an example

es 1 місяць тому
батько
коміт
30e82fcfa6
1 змінених файлів з 28 додано та 0 видалено
  1. 28 0
      watering_from_nife_io.py

+ 28 - 0
watering_from_nife_io.py

@@ -0,0 +1,28 @@
+import RPi.GPIO as GPIO
+import time
+
+# Pin setup
+SENSOR_PIN = 17  # Soil moisture sensor pin
+PUMP_PIN = 27    # Relay + pump pin
+
+GPIO.setmode(GPIO.BCM)
+GPIO.setup(SENSOR_PIN, GPIO.IN)
+GPIO.setup(PUMP_PIN, GPIO.OUT)
+
+print("Smart Plant Watering System Started...")
+
+try:
+    while True:
+        soil_state = GPIO.input(SENSOR_PIN)
+        if soil_state == 0:  # Dry soil
+            print("Soil is dry → Watering plant...")
+            GPIO.output(PUMP_PIN, True)
+            time.sleep(5)  # Run pump for 5 sec
+            GPIO.output(PUMP_PIN, False)
+            print("Watering complete")
+        else:
+            print("Soil is wet → No need to water.")
+        time.sleep(10)  # Check every 10 sec
+except KeyboardInterrupt:
+    print("Exiting program...")
+    GPIO.cleanup()