Connecting and Controlling a Motorized Ball Valve

This tutorial will give you an overview of the core features of the board, setup the development environment and introduce the required APIs to program the board.


A ball valve is a form of quarter-turn valve which uses a hollow, perforated and pivoting ball to control flow of liquids and gasses through it. This tutorial will guide you through connecting the board to a 3 Wire-Valve and writing a sketch that controls the basic operations such as the opening and closing of the valves.

Tip : If this is for your first Edge Control project, we recommend you to take a look at the Getting Started Tutorial to setup the development environment before you proceed.


  • How to connect a motorized valve to the Edge Control board
  • How to control the valve through basic commands provided by the
  • How to power the board with an external power supply

Required Hardware and Software


1. Connecting the Valves

The motorized valve comes with three wires primarily marked as blue, yellow and red. The red and blue cables are for the positive and negative signals and the yellow is for the ground.

Schematics of the 3 wire motor

Before you attach the wires to the board you need to ensure that the Phoenix connectors are in place

The Latching Circuitry A Latching Circuit has 2 inputs for Postive(P) and Negative(N) signals and 1 output. Latches allows you to store the previous state of the signal that passes through either of the pins and maintains the state until you pass a new signal. Signal passed through the positive and the negative pins will also determine the direction of the signal to the valve. The Edge Control board comes with 8 pairs of Latches each labeled from 1N:1P up to 8N:8P.

Connect the red and the blue wire to

of your Edge Control board. As the valve doesn't come with internal drivers to store the state of the motor, we will use the
pins, instead of
, these are the ones that include drivers on the Edge Control.

Connecting the valves to the connectors

Connect the yellow wire to the nearby

pin. Ensure that the wires are fastened securely and tightly to the connectors so that they make contact with the pins.

2. Opening And Closing the Valves

Open a new sketch file on the Arduino IDE and name it

. Add the header file
to your sketch.

1#include <Arduino_EdgeControl.h>


void setup()
, after enabling the serial communication, run the initialization routine
. This routine is in charge of enabling the default power areas of the board. Then use
to configure the expander pins as outputs.

1void setup(){
2 Serial.begin(9600);
3 while(!Serial);
5 delay(1000);
7 Serial.println("3-Wire Valve Demo");
9 EdgeControl.begin();
10 Latching.begin();
12 Serial.println("Starting");

As mentioned earlier, the 2 Input Pins of the latching circuit are primarily used to control the direction of the output signal. The

provides various methods to access and control these pins. The command
Latching.chennalDirection(LATCHING_OUT_1, *direction*)
is a method that can be used to assign a signal direction to a specific pin on the board through the parameters.

Inside the

you will add the instructions to open and close the valve.
with the parameter
to access the 1N:1P pins and the parameters,
for the direction. If you want the valve to open you can use the function as such,

1Latching.channelDirection(LATCHING_OUT_1, POSITIVE)

and to close the valve, you need to send a signal in the opposite direction using the command,

1Latching.channelDirection(LATCHING_OUT_1, NEGATIVE)

As it takes a few seconds for the valve to fully open or close, you need to maintain the signal for a set amount of time. Using the command,

you can adjust the duration (milliseconds) of a signal passing through a particular pin.

1void loop(){
2 Serial.println("Closing");
3 Latching.channelDirection(LATCHING_OUT_1, POSITIVE);
4 Latching.strobe(4500);
5 delay(2500);
7 Serial.println("Opening");
8 Latching.channelDirection(LATCHING_OUT_1, NEGATIVE);
9 Latching.strobe(4500);
10 delay(2500);

3. Connecting To A Power Source

The valves require a power supply of 9 - 12 V and you can either use a regular power supply or a 3 cell LiPo battery to provide the required voltage. Power sources can be connected to the relay ports on the edge control board, ensure that you have a source that can provide 9 - 12 V of power for both the valve and the board. Connect two jumper wires to the GND and B pins of the Relay ports.

The power pins of the Edge Control

Connect the jumper from the B pin to the positive terminal of the battery and the jumper from the GND pin to the negative terminal of the battery.

4. Uploading the Sketch

Connect the board to your computer, upload the

sketch and open the Serial Monitor. If all the connections are done right, the valve opens and closes and you should be able to see the status as
on the serial monitor.


In this tutorial you learned how a 3 wire valve works and the basic operations that the Edge Control board uses to control the valves. With this knowledge you can build irrigation systems that periodically control the valves, which can be installed in your fields.

Complete Sketch

1#include <Arduino_EdgeControl.h>
3void setup(){
4 Serial.begin(9600);
5 while(!Serial);
7 delay(1000);
9 Serial.println("3-Wire Valve Demo");
11 EdgeControl.begin();
12 Latching.begin();
14 Serial.println("Starting");
17void loop(){
18 Serial.println("Closing");
19 Latching.channelDirection(LATCHING_OUT_1, POSITIVE);
20 Latching.strobe(4500);
21 delay(2500);
23 Serial.println("Opening");
24 Latching.channelDirection(LATCHING_OUT_1, NEGATIVE);
25 Latching.strobe(4500);
26 delay(2500);

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.