What follows is a summary of how some of the key sensor and control functions are coded in the Arduino sketches constructed for Arduinos AR1, AR2 and AR3. In total this quite a substantial set of programs amounting to just under 5,000 lines of code.
Further information can be found in the Coding Technical Appendix. The code itself is publicly available as open source. You may access it here at the ARMAC Source Code Repostitory. Use of the code is subject to the same caution that you use it at your own risk as the other information available from this site.
In order to develop and test coding whilst the system was actually deployed a small module of 3 Arduinos "TestSys" was constructed, where in lieu of relays LEDs were turned on and off. The communication system was the same as in the production system, and a separate Raspberry Pi, actually installed for other purposes at home, was used to provide Home Assistant connectivity. Sketches were made aware of which system they were operating by the simple expedient of grounding one Arduino pin.
The TestSys module for code development
It is Arduino AR2 in Module 3 which is responsible for processing sensor inputs as they arrive. The sensor processing pipeline runs at 10 hertz in AR2's main loop. Each iteration begins by requesting temperature conversions from all three DS18B20 sensors via the Dallas library, a blocking operation that takes approximately 750 milliseconds at 12-bit resolution.
While the sensors convert, AR2 performs other tasks: reading the water level analog voltage, sampling the battery voltage analog input, reading the oil pressure digital state, and reading the water pressure analog voltage.
When temperature conversions complete, AR2 retrieves all three values and validates them against the acceptable range, substituting defaults if any sensor has failed.
For more background and technical detail refer to Sensors, Sensor Failure Fallback.
<< Sensors cont | | Coding cont >> |Table of Contents>

