Implementation of a universal aquarium controller
In the following presentation, I would like to demonstrate and share my achievements on the aquarium controller. In my opinion, the topic is very popular among aquarists, but not all aspects and problems are considered. Perhaps someone will be interested in something, or someone will want to repeat the design, so the topic contains all the necessary files. For those who want to delve into the software component of the device, all source codes are attached.
I must make a reservation right away that everything was created to fit the own needs and the needs of aquarium friends. Everything described below is IMHO and does not pretend to be the “truth” or globalization of the solution to all existing problems.
The prerequisites for the creation of the controller are very banal - an aquarium of 450 liters was purchased, and in addition to it there was a cover with installed lamps, electronic ballasts, coolers, a PH electrode with an amplifier, and controlling all this multi-channel controller. At first, everything worked without failures, but then the controlling triacs began to die, the current time was reset, and the functionality did not quite meet the increased requirements. After prolonged use and analysis of the existing controller, it was decided to make its own governing body, and the functionality of the future device was thought out:
1. Control of 8 channels (+1 PWM channel):
- 4 lighting channels;
- CO2 solenoid valve;
- automatic filling pump / solenoid valve;
- 12V cooler (PWM).
2. Connection of 3 temperature sensors DS18B20.
3. Connection of PH electrodes and Redox potential.
4. Connection of the water level sensor (analog sensor).
5. Use electromechanical relays as a switching element.
6. Connecting a 4-line LCD on the HD44780 controller.
7. Availability of real time clock DS1307Z.
8. Communication with a PC can be organized in 2 ways:
- a radio module using Bluetooth HC-05 (main channel);
- USB connection (backup channel).
9. Rated power of the switched load of 650 watts.
10. The presence of electric filters of supply voltage and protective elements of the main circuits of the device.
11. Mark all sockets and conclusions of connections.
Features of PC software:
- manual load control mode;
- 4 automatic modes (temperature mode, PH / CO2 mode, cover ventilation mode, automatic water filling mode);
- use of 3 timers for each channel, with the possibility of setting intervals by the second;
- calibration of electrodes;
- limiting time intervals for LCD backlighting, operation of coolers and a CO2 system;
- data recording in non-volatile memory of the controller and various indication of the current system parameters.
With some amendments, this functionality can be classified as universal devices. This of course is not entirely correct, because aquarium controllers can be divided into 2 subgroups - for freshwater and marine inhabitants. In this case, the lighting modes differ, as well as the presence of various electrodes that determine the parameters of water, and program modes that stabilize these parameters, etc. The hardware component of the aquariums is also very different. Lighting can be arranged by fluorescent lamps, and LEDs or LED strips can be used. IMHO - the use of LEDs is a more attractive approach, both in terms of obtaining the necessary spectral composition, and in the organization of control modes. However, the use of high-quality components, current stabilizers, power sources and the issue of heat dissipation makes this approach more expensive. In view of this, a large number of aquarists still use fluorescent lighting, and they are not going to change it yet. There can be a great many differences, because ready-made solutions are acquired extremely rarely, and most of the aquariums are assembled to the individual tastes of their owners. In this case, 3 aquariums were considered, and the requirements for them were combined / averaged. As a result, we got a system for a freshwater aquarium (or herbalist), with fluorescent lighting, up to 500 l., Autonomous operating mode, outputting the necessary information to the LCD and connecting to a PC for configuration. There can be a great many differences, because ready-made solutions are acquired extremely rarely, and most of the aquariums are assembled to the individual tastes of their owners. In this case, 3 aquariums were considered, and the requirements for them were combined / averaged. As a result, we got a system for a freshwater aquarium (or herbalist), with fluorescent lighting, up to 500 l., Autonomous operating mode, outputting the necessary information to the LCD and connecting to a PC for configuration. There can be a great many differences, because ready-made solutions are acquired extremely rarely, and most of the aquariums are assembled to the individual tastes of their owners. In this case, 3 aquariums were considered, and the requirements for them were combined / averaged. As a result, we got a system for a freshwater aquarium (or herbalist), with fluorescent lighting, up to 500 l., Autonomous operating mode, outputting the necessary information to the LCD and connecting to a PC for configuration.
Based on personal experience, the experience of other developers and the harmfulness of their IMHO - sandwich-type structures built on the basis of Arduino and others like it, I try not to use it. Generally and never. The same applies to software (low or high level). Exceptions are external libraries that have been personally revised and have passed more than one hundred hours of testing. Well, of course, standard libs, a notepad, a compiler, a programmer / debugger and an oscilloscope.
The hardware is based on the Atmel microcontroller - ATmega32A, powered by an external quartz resonator 11.0592 MHz. The choice is justified by the presence of a large number of flash and RAM, the required number of conclusions, so as not to feel constrained in the means (as a result, ~ 80% of MK resources were used). Load switching is implemented by means of an electromechanical relay. The device used OMRON sealed relays, series - G5LA. Obtaining the current time is organized by means of the DS1307Z microcircuit + a precision thermostable resonator, taken in advance from Swiss industrial equipment. The choice was due to the presence of this chip and a high-quality resonator. In another case, it is preferable to use a DS3231. To control the coolers, a PWM signal is used. As a key element, the field effect transistor LR3714Z is used. A 4-bit bus is used to output data to the LCD; an FMMT717TA transistor is used to switch the backlight. Communication with a PC is organized through a radio channel (RS232-Bluetooth HC05), or an RS232-USB converter CP2102. Data transfer rate 9600 kbit / s. Mains voltage filtering is designed for a rated power of ~ 650 watts. Termination of temperature sensors DS18B20 must be done in the immediate vicinity of the sensor. To increase the reliability of the device, an external supervisor ADM690ANZ was used, which monitors MK clocking and the supply voltage level. The radio channel is implemented as a separate module, connected to the controller board through a 4-pin connector. There is all kinds of indications (channel activity, the presence of supply voltages,
Of course, I would like to use a Wi-Fi connection with an HTTP server. But for this it is necessary to have an Ethernet MAC module available, which also entails the need for a DMA interface - and this is not a task for the AVR. And the cost of an adequate Wi-Fi module is quite high. We will not consider a chain of several boards (I wrote about this at the beginning of the paragraph), or cheap Chinese modules that can do anything, but at the same time fall off every half hour. And from ARM7TDMI to a more recent architecture, I still can’t handle myself. And it makes sense to use ARM for such a task, where AVR is more than enough. Only for Ethernet / Wi-Fi - I don’t see the point. In general, this is a task of a different level. For the current standalone controller, it was decided to limit ourselves to USB / Bluetooth and an external supervisor.
To develop the device, the software product P-CAD 2006 SP2 was used. Below is a schematic diagram of the device (clickable): The printed circuit board of the device was designed for SMD-mounting. Accuracy class - 4. TQFP44, QFN28, SOT23, TAN-A, TAN-B, SMA, 0805, 0603 and other cases are used. The board has two-sided implementation. A general view of the device circuit board is shown below (clickable):
The manufacture of the printed circuit board was entrusted to Chinese experts, because the quality of local manufacturers leaves much to be desired. I can not say which company was engaged in the production of the board, because I ordered it through a friend to whom I simply “fell on the tail” during his order, and sent him all the necessary files. The quality of "heavenly" I was very impressed. The cost of one board cost me about $ 20. The service provided was also very pleased. The cost of the board depended on its accuracy class, dimensions, and other specified requirements. Within one business day, my order was processed, calculated and the exact date of arrival in my city was indicated. On the same day, funds were already transferred to their account. And it was on the indicated day that I received a message about the delivery of my parcel. Order Processing, manufacturing and delivery took a little less than 2 weeks. None of the domestic manufacturers could offer me this closely (within the framework of an adequate cost). Below is a photo of one of the received boards:
After soldering all the components, ultrasonic cleaning from the flux and controller firmware, the device acquired the following form:
An 8-pin socket is provided for installing the supervisor. ADM690ANZ is very sensitive to fluctuations in the supply voltage, and if you cannot install a high-quality stabilized power supply at 5V, it is better not to use a supervisor. Otherwise, you will get more problems than the benefits of using it. Use the jumper to switch between USB and Bluetooth.
Initially, the device was planned to be installed in the lid of the aquarium. Therefore, the organization of the corps is not provided. However, in the future, perhaps, the need for it will appear. To display information, a 4-line LCD WH2004L-TMI-CTW was used, mounted on the front of the aluminum cover. In order to avoid interference with the indicator, during switching the power load, the indicator itself must be isolated from the contacting metal parts of the cover, and the cable going from the controller to the screen must be shielded.
Well, at the end of the description of the hardware component below is a photograph of the aquarium cover. It has a controller with an LCD, an uninterruptible power supply for 5V with a battery, a switching power supply for 12V, 6 electronic ballasts, an amplifier board for a PH electrode (based on CA3140E), 2 80mm coolers and a socket for mains power with a simple input filter.
Realization of communication with the device
The main communication channel is a Bluetooth radio channel (HC-05), the USB connection is redundant. The device does not have galvanic isolation between the microcontroller and the level converter CP2102 (USART-USB). When connecting via USB, you need to make sure that the power source used to get + 5V and the power supply voltage of the PC are included in one power supply node (outlet). Otherwise, incorrect operation of the device is possible, failure of certain structural elements. Below is the diagram and circuit board of the radio module:
The software consists of 2 parts - low level (firmware) and high level (program for PC). To develop the low-level part, the WinAVR software product, the GCC compiler version 4.3.3, was used. For the organization of control routines, a task manager based on a flag machine was implemented. Several time intervals were allocated: 1 - 41ms, 2 - 167ms, 3 - 333ms, 4 - 1.34s, 5 - 2.67s, 6 - 10.6s. In the first time interval, line-by-line display of information on the LCD is implemented. In the second - polling temperature sensors (~ once every 3 seconds), obtaining the current time, polling the ADC and calculating the values of the electrodes, taking into account calibration coefficients. In the third time interval, the main control functions of the controller are implemented:
- data processing of incoming packets;
- conversion of the current time into a numerical value (for convenience, all temporary values in the program are presented in numerical form HHMMSS);
- management of preset channels, in accordance with the selected operating modes (once per second);
- PWM channel management;
- data processing of control modes (temperature mode, PH / CO2 mode, cover ventilation mode, automatic water filling mode);
- setting time limits (LCD backlight, coolers and CO2 systems);
- write data to EEPROM;
- analysis of the current state of each of the channels, selected modes with the corresponding indication;
The fourth time interval is the formation of a clock signal for the supervisor. In the fifth interval - sending a packet of data on the current state of sensors, channel activity and control modes, and other information to be displayed in a PC program. The last time interval is used to check the status of the water level sensor when the auto-refill mode is on.
The project consists of several files: main.c, hd44780.h, i2c.h, USART.h, Functions.h, ds18b20.c, delay.h, crc8.c. Libraries for working with the 1-Wire bus were borrowed from an open source project at one of the German sites and were redesigned for their own needs (unused functions were removed and the indication of the used port and MK output for the corresponding sensor was added). All the rest are written from scratch.
For debugging low-level software, computer simulation of the device was used, using the Proteus 7.7 SP2 software package. The following is an assembled diagram of the device:
For the development of high-level software, the Microsoft Visual Studio 2007 software product was used. The main features of the software are represented by 4 tabs: information display, modes / events, daily timers, electrode calibration. Data is updated every 3 seconds. For data transfer, the transaction method is used. The software sends the data packet to the device, which, in turn, after receiving, sends the received packet back to the PC. If the sent and received packets match, the transaction was successful. If the data is different, then the current data packet is sent again. In case of multiple discrepancies between the sent and received data packets, a connection error with the device is displayed. For data transfer, a string type was used, which allows you to accurately determine the beginning / end of the packet, its type and the data itself.
A complete description of the operation of the AquaController 2014 software can be found in the help materials available through the Help / Help menu. A detailed description of the device is in the file “Technical Description”.
The approximate cost of the device, taking into account the delivery of components, is ~ $ 100.
This is the first implementation of the aquarium controller project. For more than six months, not a single failure has been identified in his work. Some design and software flaws still exist, but this is not enough for the development of the next prototype.
Given the operation of the current controller, a list of what can be further embodied in the following device:
- hardware implementation on ARM Cortex;
- Ethernet / Wi-Fi communication with the organization of an HTTP server;
- the presence of an external keyboard for emergency shutdown or activation of controlled channels;
- Integration of the amplifier for PH and Redox electrodes on the controller board;
- the presence of controlled channels for LED backlight;
- control of additional units (automatic feeder, fertilizer supply system, etc.);
- increased rated load power;
- Replacement of DS1307 to DS3231;
- the ability to install in one of the standard cases.
But for now, these are just plans for the future, since this controller fully meets the requirements of my current aquarium.
The necessary documentation, software and source codes of programs are uploaded to github below: Aquacontroller 2014
Thank you for your attention.