|
| 1 | +--- |
| 2 | +title: Connecting and Controlling a Motorized Ball Valve |
| 3 | +coverImage: assets/ec_ard_3wirevalve_cover.svg |
| 4 | +tags: [Edge Control, Motorised Valve, Irrigation] |
| 5 | +description: This tutorial will give you an overview of the core features of the board, setup the development environment and introduce the APIs required to program the board. |
| 6 | +--- |
| 7 | + |
| 8 | +# Connecting and Controlling a Motorized Ball Valve |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +A ball valve is a form of quarter-turn [valve](https://en.wikipedia.org/wiki/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. |
| 13 | + |
| 14 | +***Tip : If this is for your first Edge Control project, we recommend you to take a look at the [Getting Started Tutorial](https://www.arduino.cc/pro/tutorials/portenta-h7/ec-ard-gs) to setup the development environment before you proceed.*** |
| 15 | + |
| 16 | +### You Will Learn |
| 17 | + |
| 18 | +- How to connect a motorized valve to the Edge Control board |
| 19 | +- How to control the valve through basic commands provided by the `Arduino_EdgeControl` library |
| 20 | +- How to power the board with an external power supply |
| 21 | + |
| 22 | +### Required Hardware and Software |
| 23 | + |
| 24 | +- 1 x [Arduino Edge control board](https://store.arduino.cc/edge-control) |
| 25 | +- 1 x [US Solid Motorised Ball Valve (9 - 24 V)](https://ussolid.com/u-s-solid-motorized-ball-valve-1-2-brass-electrical-ball-valve-with-full-port-9-24-v-ac-dc-3-wire-setup.html) (or compatible) |
| 26 | +- External power source: 12V battery (LiPo / SLA) or power supply |
| 27 | +- 1 x Micro USB cable |
| 28 | +- Arduino IDE 1.8.10+ |
| 29 | +- 2 x Phoenix connectors 1844646 |
| 30 | +- 2 x Jumper cables |
| 31 | + |
| 32 | +## Instructions |
| 33 | + |
| 34 | +### 1. Connecting the Valves |
| 35 | + |
| 36 | +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. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +You need to ensure that the Phoenix connectors are in place before plugging in the wires to the respective pins. If you havent link |
| 41 | + |
| 42 | +Connect the red and the blue wire to any of the 8 pairs of `LATCHING OUT` pins. In this example we will use `1N` and `1P` of your Edge Control board. Latches allow you to store the state of the pins based on the previous output. As the valve doesn't come with internal drivers to store the state of the motor, we will use the `Latching_out` pins (instead of `Latching_out_cmd`) that are the ones that include drivers on the Edge Control. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +Connect the yellow wire to the nearby `GND` pin. Ensure that the wires are fastened securely and tightly to the Phoenix connectors so that they make contact with the pins. |
| 47 | + |
| 48 | +### 2. Opening And Closing the Valves |
| 49 | + |
| 50 | +Open a new sketch file on the Arduino IDE and name it `ValveControl.ino`. Add the header file `Arduino_EdgeControl.h` to your sketch |
| 51 | + |
| 52 | +```cpp |
| 53 | +#include <Arduino_EdgeControl.h> |
| 54 | +``` |
| 55 | + |
| 56 | +Inside `void setup()` , after enabeling the serial communication, run the initialization routine `EdgeControl.begin()` . This routine is in charge of enabling the default power areas of the board. Then use `Latching.begin()` to configure the expander pins as outputs. |
| 57 | + |
| 58 | +```cpp |
| 59 | +void setup() |
| 60 | +{ |
| 61 | + Serial.begin(9600); |
| 62 | + while(!Serial); |
| 63 | + |
| 64 | + delay(1000); |
| 65 | + |
| 66 | + Serial.println("3-Wire Valve Demo"); |
| 67 | + |
| 68 | + EdgeControl.begin(); |
| 69 | + Latching.begin(); |
| 70 | + |
| 71 | + Serial.println("Starting"); |
| 72 | +} |
| 73 | + |
| 74 | +``` |
| 75 | + |
| 76 | +Inside the `loop()`you will add the instructions to open and close the valve. `Latching.channelDirection()` is used to control the signal to a particular pin using the parameter `LATCHING_OUT_1` and its direction using the parameters, `POSITIVE` or `NEGATIVE`. Hence, if you want the valve to open you will use the instruction, |
| 77 | + |
| 78 | +```cpp |
| 79 | +Latching.channelDirection(LATCHING_OUT_1, POSITIVE) |
| 80 | +``` |
| 81 | + |
| 82 | +and to close the valve, you need to send a signal in the opposite direction using the command, |
| 83 | + |
| 84 | +```cpp |
| 85 | +Latching.channelDirection(LATCHING_OUT_1, NEGATIVE) |
| 86 | +``` |
| 87 | + |
| 88 | +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, `Latching.strobe(4500)` you can adjust the duration (milliseconds) of signal passing through a particular pin. |
| 89 | + |
| 90 | +```cpp |
| 91 | +void loop() |
| 92 | +{ |
| 93 | + Serial.println("Closing"); |
| 94 | + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); |
| 95 | + Latching.strobe(4500); |
| 96 | + delay(2500); |
| 97 | + |
| 98 | + Serial.println("Opening"); |
| 99 | + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); |
| 100 | + Latching.strobe(4500); |
| 101 | + delay(2500); |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +### 3. Connecting To A Power Source |
| 106 | + |
| 107 | +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 onboard relay ports of the edge control board. Connect two jumper wires to the **GND** and **B** pins of the **Relay ports** |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +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 |
| 112 | + |
| 113 | +### 4. Uploading the Sketch |
| 114 | + |
| 115 | +Connect the board to your computer, upload the `ValveControl.ino` 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 `Open` or `Close` on the serial monitor |
| 116 | + |
| 117 | +## Conclusion |
| 118 | + |
| 119 | +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 which periodically control the valves which can be installed in your fields. |
| 120 | + |
| 121 | +### Complete Sketch |
| 122 | + |
| 123 | +```cpp |
| 124 | +#include <Arduino_EdgeControl.h> |
| 125 | + |
| 126 | +void setup() |
| 127 | +{ |
| 128 | + Serial.begin(9600); |
| 129 | + while(!Serial); |
| 130 | + |
| 131 | + delay(1000); |
| 132 | + |
| 133 | + Serial.println("3-Wire Valve Demo"); |
| 134 | + |
| 135 | + EdgeControl.begin(); |
| 136 | + Latching.begin(); |
| 137 | + |
| 138 | + Serial.println("Starting"); |
| 139 | +} |
| 140 | + |
| 141 | +void loop() |
| 142 | +{ |
| 143 | + Serial.println("Closing"); |
| 144 | + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); |
| 145 | + Latching.strobe(4500); |
| 146 | + delay(2500); |
| 147 | + |
| 148 | + Serial.println("Opening"); |
| 149 | + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); |
| 150 | + Latching.strobe(4500); |
| 151 | + delay(2500); |
| 152 | +} |
| 153 | + |
| 154 | +``` |
| 155 | + |
| 156 | +**Authors:** Ernesto E. Lopez, Lenard George Swamy |
| 157 | + |
| 158 | +**Reviewed by:** Ernesto E. Lopez [2021-03-18] |
| 159 | + |
| 160 | +**Last revision:** Lenard George Swamy [2021-04-06] |
0 commit comments