- import time
- import sys
- import RPi.GPIO as GPIO
- import Adafruit_DHT
- # Pin Definitions
- soil_moisture_pin1 = 37
- soil_moisture_pin2 = 38
- dht_sensor_pin = 22
- dht_sensor_type=Adafruit_DHT.DHT11
- led_pin = 27 # Example LED pin, change as needed
- # GPIO Setup
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- GPIO.setup(soil_moisture_pin1, GPIO.IN)
- GPIO.setup(soil_moisture_pin2, GPIO.IN)
- GPIO.setup(led_pin, GPIO.OUT)
- # Sensor Reading Functions
- def read_soil_moisture1():
- return GPIO.input(soil_moisture_pin1)
- def read_soil_moisture2():
- return GPIO.input(soil_moisture_pin2)
- def read_dht_sensor():
- humidity, temperature = Adafruit_DHT.read_retry(dht_sensor_type, dht_sensor_pin)
- return humidity, temperature
- try:
- while True:
- soil_moisture1 = read_soil_moisture1()
- soil_moisture2 = read_soil_moisture2()
- humidity, temperature = read_dht_sensor()
- if soil_moisture1 == 0:
- print("Dry soil detected in Soil moisture 1 ")
- GPIO.output(led_pin, GPIO.HIGH) # Turn on LED for dry soil
- else:
- print("Soil is wet in soil moisture 1")
- GPIO.output(led_pin, GPIO.LOW) # Turn off LED for wet soil
- if soil_moisture2 == 0:
- print("Dry soil detected in soil moisture 2")
- else:
- print("Soil is wet in soil moisture 2")
- print(f"Temperature: {temperature} C, Humidity: {humidity}%")
- time.sleep(1)
- finally:
- GPIO.cleanup()
[text] smart irrigation
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: