‘Automate Sprinkler to detect weather through Raspberry Pi’

Nowadays the irrigation systems are used for dust suppression, mining, etc. These systems are also used in homes for watering plants. Irrigation systems that are available in the market are expensive for a little area coverage. The Raspberry Pi is a microprocessor that can be integrated with almost every electronic component to design interesting projects. A method is proposed below to make a low cost and effective irrigation system at home by using a Raspberry Pi.

Raspberry Pi to Automate Sprinkler Control (this image is taken from www.Instructables.com)

How to set up the apparatus and automate it through Raspberry Pi?

The purpose of this technique is to make a system, as effective as the systems available in the market, with comparatively low cost. Go through the steps below to automate your sprinkler control through the raspberry pi.

Step 1: Collecting the Materials

According to the measurements of your garden, gather the exact quantity of pipes, different adapters and electronic components that will combine together with Raspberry Pi to form the whole system.

Electrical Components
Mechanical Components

You can find all the components at Amazon

Step 2: Planning

The best approach is to make a full plan in advance because it is a difficult task to undo the mistakes somewhere between implementing the whole system. It is important to note the difference between NPT and MHT adapters. Ensure that you install the drain valve at the absolute bottom of the framework. A sample system diagram is given below.

System Diagram

Step 3: Dig Trenches and Lay Pipeline

Before digging the trench, check if there is something else that is buried under the soil and dig deep enough so that you can lay a pipe and cover it with some soil. Bury the pipes and connect them with various connectors mentioned above. Don’t forget to install a drain valve.

Step 4: Put Solenoid Valve in Plastic Box and Connect to the Whole System

Screw NPT-slip adapters into both ends of the solenoid valve. Then drill two holes in the plastic box wide enough to pass a pipe through them to the slip adaptors inside the box and apply silicone adhesives on the joints to make the connections strong. Now, an important thing here is to observe the direction of flow on the check valve correct. The arrow should be pointing towards the solenoid valve.

Solenoid Valve (this image is taken from www.Instructables.com)

Step 5: Attach Solenoid Valve Wire

Cut two segments of hookup wire and pass it through the box by drilling appropriate holes and connect it to the solenoid valve with the help of waterproof connectors. Use silicon to seal around the holes. These wires will be connected in the next step.

Step 6: Check for Leakes

Before you go any more remote, you presumably need to check your pipes for leaks. Fortunately, you can do it before connecting the circuit or even the Raspberry Pi. For this, connect the two solenoid valve wires directly to the 12V adapter. This will open the valve and allow the water to flow into the pipes. As soon as the water starts flowing, examine the pipes and joints carefully and check for leaks.

Step 7: Circuit

The image below shows the circuitry integrated with raspberry pi that will make the whole system work. The relay is working as a switch to control 24VAC power to the solenoid valve. As the relay requires 5V to operate and the GPIO pins can only provide 3.3V, Raspberry Pi will drive a MOSFET which will switch the relay which will turn the solenoid valve on or off. If the GPIO is is off, the relay will be open and the solenoid valve will be closed. When a high signal comes to the GPIO pin, the relay will be switched to closed and the solenoid valve will open. 3 status LEDs are also connected to GPIO 17,27 and 22 which will show that if the Pi is getting power and if the Relay is switched on or off.

Circuit Diagram

Step 8: Testing Circuit

Before the whole system is implemented, it is better to test it on the command line using python. To test the circuit, Power up the Raspberry Pi and type the following commands in Python.

import RPi.GPIO ad GPIO
Pin Setup

This will initialize the GPIO pins 17,27 and 22 as output.

Power on

This will turn the other two LEDs on.

Switch on Relay

When you type the above command, the relay will produce a “click” sound which shows that it is closed now. Now, type the following command to open the relay.

Switch off relay

The “Click” sound that the relay produces shows that everything is going good so far.

Step 9: Code

Now as everything is going so good so far, upload the code on Raspberry Pi. This code will automatically check the rainfall update of the past 24 hours and automate the Sparkling system. The code is properly commented, but still, it is explained generally below:

  1. run_sprinkler.py: This is the main file that checks a weather API and decides whether to open the solenoid valve or not. It also controls the I/O of the GPIO pins.
  2. config: it is the configuration file that has the weather API key, the location where this system is installed, the GPIO pins and the threshold of the rain.
  3.  run.crontab: It is the file that schedules the main file to run certain times a day instead of running the python script continuously for 24 hours.

Download  Link: Download

Download the file attached above and upload it to Python. Enjoy your own Automated Sprinkler System.


Hamza Iqbal

Hey! I am Hamza. I am an Electrical Engineer who has a very innovative approach towards daily life stuff. I tend to make life easier by making circuits and designs to automate things around me. I mainly work with printed circuit boards on proteus to bring life to my inventions.