Garden Watering System – Part 3 – Electronics

Controlling the Solenoids

Electrically, the solenoid valves used in the watering system are fairly simple: The valve is normally closed, and no water flows. When power is applied to the solenoid, it opens the valve. The valve stays open as long as the solenoid is held on by the electrical current, and is then closed by the water pressure when the electrical current stops. The solenoids typically run at 24 volts AC, or 12 volts DC. Each solenoid draws about 500mA current at 12VDC when switched on. This means that to turn the water on and off electronically, you need a way to switch 24VAC/12VDC at up to 500mA.

I’m using an old PC Parallel port relay board which has 8 relays rated up to 240VAC. I’ve modified the board to connect easily to an Arduino nano. Pull-down resistors keep the relays switched off when nothing is connected – this avoids the relays switching on and off rapidly when disconnecting or connecting wires, and when the Arduino nano is switched off. The relays themselves are controlled by a transistor array.

I was using a single 12v 1A power supply at first, but the Arduino would become unresponsive after switching a solenoid on, so now I’m using one 12V supply for the relays and Arduino (regulated using VIN), and another 12v supply to power the solenoids. What I realize now, six months after building the controller, is that the solenoids probably induce a large back-EMF, enough to upset the low voltage electronics. I assumed they didn’t need EMF-suppression diodes because they are switched by relays, but they do. Powering two solenoids and two relays also used slightly more than the 1A rating of the 12V power supply.

Experimenting

The relay board. This is an old one so I had to make a few modifications. Newer boards are easier to use.

The relay board that switches 12V on and off for each solenoid. This is an old board designed for use with a PC parallel port, so I had to make a few modifications. Newer relay boards are easier to use.

Relay board modifcations. I've the inputs to a pin header, added pull up/down resistors so the default state is off, and added an LED for each relay.

Relay board modifications. I’ve the inputs to a pin header, added pull up/down resistors so the default state is off, and added an LED for each relay.

Relay board modifications. - top side Relays numbered, Added a 12V regulator, the wires coming into the header are latch enable, output enable, and 1 wire for each relay.

Relay board modifications – top side. Removed unncessesary ICs, Numbered the relays, and added a 12V regulator. The wires coming into the header at top left are latch enable, output enable, and one wire for each relay.

Experimenting with switching the solenoid valve on and off with a relay. Ready for automatic control

Experimenting with switching the solenoid valve on and off with a relay. Ready for automatic control

Building a prototype controller

The first prototype using a Raspberry pi. I'm re-using an old set-top box, powering the circuit from the original power supply. This works fine but the Raspberry pi kept losing wi-fi connectivity.

The first prototype using a Raspberry pi. I’m re-using an old set-top box, powering the circuit from the original power supply (note: best a low voltage plugpack rather than doing this). This works fine but the Raspberry pi kept losing wi-fi connectivity, so I switched to using an arduino, controlled by a Raspberry pi using a radio data module.

The first prototype - back. You can see the USB wifi module protrudig, and the terminal block wired up to the relay outputs

The first prototype (Raspberry Pi inside) – back. You can see the USB Wifi module, and the terminal block wired up to the relay outputs

The second prototype. This one is still in use. The arduino nano is plugged into a breadboard and wired up to the relay board. The arduino receives commands from a Raspberry pi through a 2.4ghz radio data module.

The second prototype controller. This one is still in use. The Arduino nano is plugged into a breadboard and connected to the relay board using jumper wires. The Arduino receives commands through a 2.4ghz radio data module. I’ve switched to using a 12V plug-pack for power. This is safer as all the power coming in and out of the controller box is low voltage.

Closeup of watering system controller microcontroller board

Closeup of watering system controller microcontroller board. Regulated 12V from the relay board come in on the bottom left, and to VIN of the microcontroller after going through a diode. I’ve added lots of capacitors so that the microcontroller maintains power while the relays and solenoids switch on. This looks like a mess; it is a prototype, but once closed up in the case you can’t tell!.

Connections

The back of the second prototype controller. You can see the radio module on the left, terminal block for relay outputs in the middle. The blue wire goes to the solenoid valves.

The back of the second prototype controller. You can see the radio module on the left, terminal block for relay outputs in the middle. The blue wire goes to the solenoid valves.

The back of the controller. Here you can see the terminal block connection to the wire that goes to the solenoids. The four zone solenoids share a common ground, as only one is on at a time. The master solenoid valve has its own ground.

The back of the controller. Here you can see the terminal block connection to the wire that goes to the solenoids. The four zone solenoids share a common ground, as only one is on at a time. The master solenoid valve has its own ground.

Close-up of terminal block

Close-up of terminal block

Relay board connections

Relay board connections. This is just the way I’ve set it up, it will vary if you have a different relay board.

When I was using a Raspberry Pi connected directly to the relay board, I used the following connections:

Relay board Raspberry Pi
Output Enable 3 – GPIO 2
Latch Enable 12 – GPIO 18
1 26 – GPIO 7
2 5 – GPIO 3
3 11 – GPIO 17
4 13 – GPIO 27
5 15 – GPIO 22
Gnd 6 – Gnd

Connections using the Arduino nano are:

Relay board Arduino
Output Enable D2
Latch Enable D3
1 D4
2 D5
3 D6
4 D7
5 D8
Gnd Gnd
Watering System Controller schematic diagram

Watering System Controller schematic diagram (click to enlarge)

nrf24 Module pin Raspberry Pi pin
1 – Gnd 25 – Gnd
2 – Vcc 17 – 3v3
3 – CE 22 – GPIO25
4 – CSN 24 – GPIO 8/CE0
5 – SCLK 23 – GPIO 11/SCLK
6 – MOSI 19 – GPIO 10/MOSI
7 – MISO 21 – GPIO 9/MISO

Future Improvements

There are a few improvements I want to make to the controller in future:
1.  A much smaller case.
2. Using transistors instead of relays
3. Solar powered
4. I might go back to an all in one WiFi box, rather than having the separate Raspberry Pi.

Stay tuned for part 5, the software component of the system.

Previous posts:

Part 1 – Introduction

Part 2 – Pipes

Author: Paul

Share This Post On

Leave a comment