|
|
@@ -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()
|