How the electronic control system came to be as it is. The present system is described in The Electronic Control Sub-System.
Development history
The electronic design for ARMAC went through several iterations. In the original design the Raspberry Pi - handling the Home Assistant dashboard and MQTT server bridge between the outside world and system - and one Arduino lived in the House. That single Arduino commanded the system valves via relays by direct connection to the relay logic inputs via the multicore cable and also received and processed the sensor data on separate wires and transmitted the whole to the Raspberry Pi.. This proved electrically vulnerable to electromagnetic interference and even with hardening of various sorts components remained vulnerable, notably when the pump starter motor fired up.
In addition, in practice it was found that two Arduinos were needed to process in real time sensor inputs transmitted also to the House over the multicore cable. This was getting pretty cumbersome, data received was not very reliable, and the relays tended to have a mind of their own. And, despite a range of steps to harden the system against electromagnetic interference, including separating power from relays and more fragile components, and the use of ferrite beads, filters, etc, things remained too fragile for a system that needs to be resilient under pressure.
It also became increasingly attractive to incorporate some level of autonomous decision making into the system so that if communication with the outside world was lost, the system could still continue to respond to an increasing (or decreasing) threat. The next move was to shift an Arduino into the pump shed to make autonomous decision making possible. This it was hoped it could when necessary command the relays by wiring the logic side of the relays with two wires, each protected by a one-way rectifying diode. One wire was to come from the house on the red underground multicore cable, and the other directly from the shed Arduino. The relay control wires were biased up by connection via a 10 k Ohm resistor to 5 Volt. In the end this approach still proved inadequate - it was vulnerable to signal collision, and cable noise.
There was also a slightly more sophisticated problem. If you are going to have fairly complex decision making code, how are you to know if or not it is working? It needs testing. Initially I had the code also with test features so that it tested itself. But it is very easy for the test code to become self-verifying rather than actually testing the other parts of the code.
In the end I bit the bullet and decided to create the current system. This required a complete re-vamp of the system's electronic hardware and software. It introduced the current architecture of the House modules being responsible for communication with the external world, and the relays, sensor information, and autonomous decision making being carried out in the shed. The Raspberry Pi was relocated to the same place that the routers are linked to the external optical cable and all of that was supported by a large, continuously charged 12V battery. The rest was packaged into proper enclosures as modules.
As for testing, with the sensors being interrogated and their inputs interpreted by code in AR2, and the outcomes being transmitted to AR3, it became practical to simply have a test program in AR2 which could take over from the actual sensor input with simulated values, then sequentially changed along a scenario that was pre-set. This enabled one to physically switch on the test scenario and see how the rest of the system responded to the test values replacing actual sensor inputs. With this it was possible to robustly check out the faithfulness with which the system responses followed what was intended. Scenario tests could be initiated from the Arduino serial monitor, or the main sequence (scenario 1) could be initiated by pressing a small button on the Autonomous Module (Module 4).
Power between the shed and house was via a robust underground two core cable connecting the large pump battery with the a mains supported Victron 10 amp charger in the house. Properly protected by snubbers and other filters, DC Voltage Regulator modules were used to convert 12V DC to 5V DC or 24V DC as required.
NB As the notes that follow are a development log they sometimes address features of the prior stages in this. For example, there is occasional consideration of the number of wires of the multicore wire to be utilised, although ultimately all functions are addressed with the two wires of the RS485 communication system.
The first integration: an Arduino coupled to a Raspberry Pi
After considerable investigation (and learning C and a host of other things such as Docker and MQTT) It was decided to integrate all the read-outs and controls for the system into one panel. The choice was to use an Arduino coupled to a Raspberry pi micro computer (running Linux). The Arduino is perfect for input of sensors and activation of relays and motors. It is also easy to incorporate into its program the intermittent requirement for the low-pressure intermittent mode, also switchable and dileable.The Raspberry Pi is well suited to running Home Assistant which has excellent integration and display characteristics. A development of the prototype and the control dashboard panel (using available sensors) is shown below. Arduino1 with multicore cable running with Home Assistant on Raspberry Pi.
Currently it is intended to retain the other components in parallel with the above to add resilience through multiple redundancy. This includes the pump module which can be controlled by sms messages.
Two Arduinos driving the same relays
In the intermediate design both the house Arduino (AR1) and the shed Arduino (AR3) could command the relays, depending on the mode of operation. Parallel Drive Protection - The Arduino control architecture places both house-based Arduino AR1 and shed-based Arduino AR3 in position to command relays under different operational modes.
To prevent GPIO conflicts if both Arduinos simultaneously attempt to drive the same relay line (one HIGH, one LOW), each Arduino's output connects through an IN5819 Schottky diode to the shared relay control line, with a 10kΩ pull-down resistor to ground.
This wired-OR configuration ensures that if either Arduino drives HIGH, the relay sees HIGH, while both must release for the line to fall to LOW, preventing the direct short circuit that would occur if two GPIOs were directly paralleled.
This arrangement was later abandoned: AR3 alone now drives the relays, and AR1's relay pins are left over from it (see Arduino pin allocations).
Multicore cores in the early design
Initially the following cores were required: Relays SFS-01 Remote Start – switch remotely from Arduino pin Starter Motor Relay Output Valve control: High/Low Flow Motor Valve Intemittent Motor Valve Shed cooling control Motor Valve Gel injection solenoid. Sensors Shed internal temperature External temperature Water Flow Rate Water level in tank (2 cores) Oil Pressure Sensor Water Pressure Switch Total cores: = 12 Polypropylene Toro 13 core 0.5mm = $51.72 was chosen
However in the later design all of the sensors transmitted directly into AR2 in the shed, whilst the valve relays were directly operated by AR3 also in the shed. Only two wires were required for communication by RS485 to the house, with a further two wires reserved as a backup serial communication channel.
RS-485 transceivers
Note. We initially tried using very cheap MAX485 transceivers but had unreliable results. So we replaced them with the slightly more expensive but robust Gravity transceivers. The MAX485 has DE (Driver Enable) and RE (Receiver Enable) connections that determine the signal direction of each message, and are typically tied together driven by a single pin on each Arduino. The tied DE and RE wires, driven by a single pin, is standard configuration, and suffices provided there is no rapid toggling between sending and receiving data adopting a simple control protocol of (both HIGH for transmit, both LOW for receive). However, the Gravity transceiver does not require a RE/DE connection. The Gravity module has automatic direction control built-in. It detects when data is being transmitted on the TX line and automatically switches to transmit mode, then returns to receive mode when idle. Currently in the sketches the D8/D12 are still reserved to a pin even though with the Gravity module they aren't actually doing anything. This is pure laziness and will be cleaned up.... one day!
The Tuya smart switch
A Tuya smart Wifi 4channel 4-way relay was purchased on Alibaba for $29.76. It is wifi app controlled, has 4 relays maximum current 10 A at 220V but running itself at 7-32 V DC/AC and operating in WiFi at 2.4 ghz b/n/g. It is controlled remotely by the Tuya Smart app available for iOS. The above unit has been utilised in the house control system to provide an alternative means of re-setting the microcomputers (see below) if the primary communication system they run encounters a glitch.
<< Development history: sensors | | Development history: Autonomous mode >> |Table of Contents>
