Now, let's get down to making the robot. Firstly, you need to make the water connection from the tap to the solenoid and from the solenoid to the sprinkler. You also have to make the connection, as follows:
Now let's start programming. We will be interfacing a soil moisture sensor in this robot. The job of this sensor is to determine the amount of water in the soil. By determining this, we can understand if the garden needs water or not. This soil moisture sensor is an analogue sensor, hence we will be using an ADC to convert the analogue reading to Pi-understandable digital values. So let's get going:
import time
import RPi.GPIO as GPIO
import Adafruit_ADS1x15
water_valve_pin = 23
moisture_percentage = 20
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(water_valve_pin, GPIO.OUT)
adc = Adafruit_ADS1x15.ADS1115()
channel = 0
GAIN = 1
while True:
...