KanyonKris edited this page Apr 30, 2017 · 10 revisions

About relay_board

The relay_board plugin for OSPi allows you to use one or more relay boards to control sprinkler valves. Some features:

  • Control up to 12 stations
  • Inexpensive relay boards reduce the cost of building your sprinkler controller


The easiest way to install the relay_board plugin is to use the plugin manager in OSPi (version 2.2.28 or newer). Connect to OSPi with your web browser then select the Plugin menu and select Manage Plugins, then select the Browse More Plugins button. Find relay_board in the list and check the box on the right and select the Install button. Go back to Manage Plugins, find relay_board in the list and check the box to the right to enable it then select the Update Enabled button.

To install the plugin manually, download it from the OSPi Plugin Repository and copy the relay_board.py file into the OSPi/plugins directory, then copy the relay_board.html file to the OSPi/templates directory.

Plugin Settings

Use your web browser to connect to OSPi running on your Raspberry Pi. After logging in, select the Plugins menu then select Relay Board.

Web page screen shot

Relay channels: From the drop-down list select the total number of relay channels you have connected. Often this is just one relay board but you can use as many boards as you want up to 12 total channels.

Active: Select Low if your relays are activated (switched on) by taking the input low (0 Volts). Select High if the Raspberry Pi should change it's output (input of the relay board) from low to high (3.3 Volts).

IMPORTANT: If Active is changed, Relay channels will be set to 1 to prevent all the relays being switched on, and possibly damaging the power supply (see the wiring section below for more information). After verifying that the first relay is off, return to the Settings page and set Relay channels to the correct number.

Relay Boards

Many relay boards are capable of being driven by a Raspberry Pi to turn sprinkler valves on. They are commonly available with 1, 2, 4, 8 and 16 channels.

Mechanical Relay Boards

Boards with mechanical relays are the least expensive option and work fine. Mechanical relays contain a switch that is pulled closed by an electromagnetic coil - the switch turns the sprinkler valve on or off, and the electromagnetic coil is activated by the Raspberry Pi.


3.3 Volt Capable - The relay board must have circuitry that amplifies the 3.3 Volt output from the Raspberry Pi into enough power to activate the relay coil. Few relay boards for sale state that they can be driven by 3.3 Volts. Many relay boards are advertised as having 5 Volt inputs or Arduino compatible (Arduinos have 5 Volt outputs) and most of the time these will work with the 3.3 Volt output of the Raspberry Pi.

Power In - Most boards have a power input (usually labeled VCC) used to run the amplification / protection circuits and energize the relay coils. The relatively weak outputs of the Raspberry Pi can't provide enough power to activate the relay. Make sure the relay board has power (VCC) and ground (GND) inputs.

Load Rating - The switch output of the relay must be capable of handling the electrical current, or load, of the sprinkler valve. A typical sprinkler valve will activate with 0.2 Amps of 24 Volt AC power, so the relay must be able to handle this load. To be safe I recommend relays that can switch at least 0.5 Amps. Most relay boards use 10 Amp relays.

Protection - Most boards also have optoisolated inputs to protect the fairly sensitive outputs of the Raspberry Pi from being blown out by power spikes and voltages higher than 3.3 Volts. While not required, optosiolator inputs are strongly encouraged - they usually don't add much to the cost of the board. Also the coils of the relays should have diodes across them to protect from voltage spikes generated by a coil when it de-energizes - almost all boards have protection diodes.

Indicators (LEDs) - Although not required, it's nice to have LED indicators on the board so you can see when a relay is activated.


Keyes funduino relay board - This 4 channel relay board meets all the requirements above. It is active high, meaning a relay is switched on when the Raspberry Pi output changes from 0 Volts to 3.3 Volts. I particularly like how the indicator LEDs are powered by external power (Vcc) and not the Raspberry Pi output signal like some boards. If the Keyes board is not available, this board is electrically the same and works the same (I bought one and tested it). There is also an 8 channel version. Schematic

SainSmart relay board - This 4 channel relay board meets most of the requirements above. It is active low, meaning a relay is switched on when the Raspberry Pi output changes from 3.3 Volts to 0 Volts. The indicator LEDs are powered by the Raspberry Pi output signal, which isn't ideal but it works. There have been reports of the LEDs on these boards (SainSmart) degrading over time to the point where they prevent the relay from activating - the fix is to either replace the LED or solder a wire jumper over it. There is also an 8 channel version. Schematic

Solid State Relay (SSR) Boards

Boards with SSRs can be used but they are more expensive. SSRs use only electronic components (like transistors) to switch the load so they have no mechanical switch which may wear out. SSRs are a good choice when switching frequently, like many times a day or hour. Mechanical relays will handle years of typical sprinkler switching, but if you'd like higher reliability, go with SSR boards. I haven't tried any SSR boards so have no examples.


There are two wiring steps: Connecting the relay board(s) to the Raspberry Pi, and connecting the relay board(s) to the sprinkler valves and power.

Raspberry Pi wiring

The diagram below shows an example of two relay boards (first an 8 channel board, then a 4 channel board) connected to a Raspberry Pi to control up to 12 sprinkler valves.

Relay Board Wiring Diagram

Step 1 Connect the inputs of the relay board(s) to the outputs of the Raspberry Pi (the 26 pin header labeled P1) in the order shown below. Jumper wires or jumper ribbon cables work well for making these connections.
TIP: Connect only the first relay and make sure everything works properly, then connect the rest of the relays.

Relay - P1
1 - 11
2 - 12
3 - 13
4 - 15
5 - 16
6 - 18
7 - 22
8 - 7
9 - 3
10 - 5
11 - 24
12 - 26

Step 2 Connect GND of the relay board(s) to Ground of the Raspberry Pi (pins 6, 9, 14, 20 or 25).

Step 3 Connect VCC (power in) of the relay board(s) to the 5 Volt output (pins 2 and 3) of the Raspberry Pi.

WARNING: The maximum permitted current draw from the Raspberry Pi 5 Volt pins is the USB input current minus any current draw from the rest of the board and connected USB devices. For example, a typical USB power supply is 1 Amp - 0.7 Amps for the Raspberry Pi = 0.3 Amps for the 5 Volt output. If the maximum permitted current is exceeded it will cause the Raspberry Pi to shutdown. Any USB devices plugged into the Raspberry Pi will take away from the maximum permitted current (for example, a USB WiFi device uses around 0.15 Amps, leaving 0.15 Amps for the relay board). For most relay boards, each relay draws 0.07 Amps when switched on.
The plugin provides some protection by reducing the number of relay channels when Active is changed (see Plugin Settings above). Before connecting any relay boards, set the plugin to 1 Relay channel to be sure at most only 1 relay will turn on while you get things setup. Be sure the plugin is enabled, if it is not enabled the OSPi program will default to OpenSprinkler board mode which will cause 3 relays to be activated if a relay board is connected.
OSPi defaults to sequential mode which means only one station (relay) is on at a time. If sequential mode is disabled (in OSPi: Options, Station Handling), you must be very careful not to exceed the maximum permitted current. If you need to have more than one relay on at a time, you could use a USB power supply capable of higher current output, or use a separate 5 Volt power supply that only powers the relay board(s).

Sprinkler Valve wiring

Connect the sprinkler valves and power to the relay board as shown in the diagram below.

Sprinkler valve wiring

Step 1 Connect one wire of the 24 Volt AC power supply to one wire of all the sprinkler valves (green wires in diagram above). Usually the sprinkler valves are together in a box and one wire from each sprinkler valve is connected together (often with a wire nut or crimp connector) with a single wire that is run from the valves back to the sprinkler controller.

Step 2 Connect the other power supply wire to the common terminal (usually the center) of all of the relays (red wires in diagram above).

Step 3 Connect each sprinkler valve to the normally open terminal of each relay (blue, yellow, violet and orange wires in diagram above). When the Raspberry Pi activates a relay, the normally open terminal is connected to the common terminal to turn the sprinkler valve on. The normally open terminal is usually on the left, but it's a good idea to verify with a multi-meter. The other terminal is normally closed and is connected to the common terminal until the relay is activated, then it becomes open.
TIP: Connect only the first relay and make sure everything works properly, then connect the rest of the relays.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.