Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Tutorial: Setting up a valve controller
Setting up a valve controller
This tutorial requires preliminary knowledge of sending digital output signals from a microcontroller.
Note on feedback control
Reading the position of the actuator for feedback control is not covered in this tutorial---please see Reading an analog sensor. To get familiar with the potentiometer, connect the Blue wire (Position Signal) to the Analog input wire terminal; connect the White wire to V+; and the Yellow wire to GND. Try switching the White and Yellow wires and observing the change in output.
[Fig. 1] Circuit diagram of potentiometer for feedback control.
The first core component of remotely controlling a valve is the motorized actuator. In the case of a gate valve, a linear actuator is used to raise and lower the gate. This document will focus on controlling a linear actuator for a gate valve. The process for a butterfly valve is similar.
[Fig. 2] A linear actuator. https://www.servocity.com/sda8-67
To extend the actuator, apply a voltage across the power wires by:
- Connecting the Positive Power Wire to the positive battery terminal (+)
- Connecting the Negative Power Wire to the negative battery terminal (-)
Reversing the connection will cause the actuator to retract.
[Fig. 3] Example wiring of the linear actuator.
The second core component of controlling a valve is a mechanical relay. By using a relay, the process of connecting the Power Wires to a battery can be done electronically.
[Fig. 4] 12 Volt DC Relay (Left) and Relay circuit diagram (Right)
Relays are useful as switches for mechanically connecting and disconnecting electronic components that draw a lot of power. The switch is controlled by a magnetic coil which is activated by applying a voltage across the coil. The activation voltage varies, typically between 5 volts DC to 12 volts DC, depending on the part selected.
Using the circuit diagram in Fig 3, the natural state of the relay is to connect Pin 87a to Pin 30. Activating the magnetic coil will cause the switch to flip and connect Pin 87 to Pin 30.
Apply a voltage across the coil by:
- Connecting the Positive Relay Wire (Pin 85) to the positive battery terminal (+)
- Connecting the Negative Relay Wire (Pin 86) to the negative battery terminal (-)
The relay will still close the switch if the Positive and Negative Relay Wires are switched.
The third core component of controlling a valve is the transistor. Transistors are useful for interfacing high voltage electronics (such as actuators and relays) with low voltage electronics (such as microprocessors).
[Fig. 5] Pre-biased NPN transistor. https://www.digikey.com/short/31r35b
In this the case of controlling a valve, transistors can also be thought of as switches. In Fig. 5, the transistor opens and closes a “switch” between the Collector pin (C) and the Emitter pin (E). Note, this switch is naturally opened. This project uses NPN transistors to enable a microcontroller to activate the relay and cause the actuator to move.
Connecting the Base pin (B) to a positive terminal (typically 3.3 - 5 Volts DC) and the Emitter pin (E) to the negative terminal (Ground) will activate the transistor to close its “switch”. Correctly wiring the pins is important for ensuring proper expected behavior.
Tying everything together
Now we will discuss connecting these three components together in order to control an actuator using a microcontroller.
[Fig. 6] Circuit diagram for wiring the transistor.
First, we start with a pre-biased transistor, which is a transistor with built-in resistors. This reduces the number of electrical components as well as simplifies design. While the circuit diagram in Fig. 5 shows resistors R1 and R2, these are built-in and the user need only:
- Connect the Collector pin (C) to the relay
- Connect the Base pin (B) to the signal pin from the microcontroller
- Connect the Emitter pin (E) to Ground / the negative pin of the battery.
[Fig. 7] A previous prototype board with external resistors. Top view (Left) and Bottom view (Right)
The 12 Volt power supply may come from a lead acid battery and the 5 Volt signal may come from different source, such as a microcontroller. This is okay as long as both the battery and microcontroller have a wire connecting negative terminal from the battery to the negative terminal from the microcontroller. This establishes a common Ground amongst the electronic components.
The transistor can now be connected to the relay
[Fig. 8] Circuit diagram connecting the relay to the transistor.
A diode (D1) is necessary for protecting the electronics such as microcontrollers from flyback current which occurs when the magnetic coil is discharging. Otherwise, this reverse current can damage and break the microcontroller.
A 10A fuse (Fuse1) is important for preventing the actuator from drawing too much power from a battery, especially from lithium-ion batteries. For example, this can happen when the actuator is struggling to close because it is blocked by debris. An inline fuse such as the one seen in Fig. 8 is an affordable, easily replaceable component that will break the circuit if too much power is drawn.
[Fig. 9] Where to add an override switch to manually control the actuator
This setup can be modified so that an operator can bypass the microcontroller and manually activate the relay. Fig. 9 illustrates the location for where to insert the switch.
[Fig. 10] Fuse assembly for connecting the 12 volt DC battery to the solar charge controller and the interface board.
[Fig. 11] Circuit diagram for bidirectional control of an actuator using a microcontroller.
By adding a second transistor and a second relay, a second signal pin from the microcontroller can be used to enable bidirectional control of an actuator.
[Fig. 12] Assembled actuator enclosure (including interface board, relays, battery, and solar charger)