ForewordSummer is over, and I would like to share the results of one interesting work - namely, the development, assembly, commissioning and operation of the combined ultrasonic sensor. I want to say at once that the whole device was assembled “on my knees”, because it was important to understand how viable the system could be. Therefore, no protection against rain, sun and wind was done. The device itself was installed outside the room. Looking ahead, I will say that the reliability was very impressive, despite the fact that the device was collected from the remnants of the equipment from the old projects.
Formulation of the problem
The task was set in early spring - along with the acquisition of 120 raspberry bushes in the nursery. As you know, raspberries are very responsive to watering, but at the same time do not like and excess water. Therefore, it was decided to assemble a system from scrap materials that would solve the following questions:
')
1. Control submersible vibration pump.
2. Measuring the water level in a 220 liter barrel.
3. Turn on the solenoid valve on request - start watering. Disconnection is made on the signal from the water level meter.
4. Upon completion of the irrigation cycle, start the filling cycle of the barrel. Disconnection is made on the signal from the water level meter.
Part of the equipment
- US-100 - ultrasonic distance meter. Older brother of the famous HC-SR04. The main difference is the presence of temperature compensation and the ability to work in the mode of data transmission via UART. For accuracy, I could not compare them due to the absence of HC-SR04.
- Board, equipped with a microprocessor STM8S003F3P6.
- LCD 2x16 compatible with HD44780.
- HLK-PM01 is a block compact AC-DC power source. Input voltage 220V AC, output 5V 600 mA DC.
- Solenoid valve with a mounting diameter of 3 \ 4 to 24V DC. Current consumption reaches 2 A.
- Housing for the main device.
- Housing for ultrasonic sensor. The execution of this IP67 housing, and as practice has shown, such a performance was chosen not in vain.
Development tools
I want to say at once that I am the happy owner of two great Arduino Mini boards. But alas, the arduinization of consciousness ended for me when it turned out that even using a real-time operating system, this board doesn’t want to work as a Modbus RTU slave with timeouts less than 100 ms at a speed of 57.6 kbits when only 64 are requested registers and at the same time do at least some useful work. That is why the board was chosen on the STM8 platform with much fewer resources. IAR Embedded Workbench for STM8 was chosen as the programming and debugging environment. This environment works great with the programmer - debugger ST-LINK V2. The programmer has a USB interface and is connected to the item being debugged with just 4 wires. At the same time, the current from the debugger is often enough to power the debugged board. I'm a bit old-fashioned, and so I like to be able to debug online. I just want to see what my code does in runtime. This approach has saved time and money more than once.
operating system
Interesting fact: the famous Russian zodiac manufacturer produces a PLC without a real-time operating system.At the very beginning of the journey, I was faced with the choice of whether or not to use a real-time operating system for a microprocessor with such resources. And the choice was made quite unexpected - ChibiOS RT v2.6.9. I will not consider in this publication all the features of this system - only I note that the creation of two streams with the same priorities took 2547 bytes of flash - memory and 461 bytes of operational. Actually, quite a lot - but the result of this loss was the fact that now I have an 8-bit inexpensive microcontroller that is controlled by a real-time operating system. And therefore, I can manage the execution of my tasks as I need.
Progress: building a prototype and writing a program
The prototype was built quite quickly, there were no special problems. What happened as a result is shown in the picture below:
When programming, the only problem was that no ready-made drivers were found for the display and the ultrasound sensor. The result - I had to write myself. The result of the work has become a stably working program, the source code of which you can find
in the archive .
The appearance of the prototype installed in the case is shown below. The process of tests at home (read - test for a spherical processor in a vacuum) conditions is just visible. It is in these modes that arduinovods are usually tested, and the result is feedback on the exceptional reliability of the “solutions” obtained. The behavior of my product in such a test was just perfect - no failures or deviations were noticed.
Progress: installation and launch of the system
A structure located in the immediate vicinity of the control object was selected for installation. As I said above, no protection against precipitation was provided. In the end, lingering rain did his job - but more on that later. The picture below shows the installation of an ultrasonic sensor.
The device controls the inclusion of the drip irrigation system, and is controlled by a programmable logic controller. The controller has a built-in 1-wire bus with the ability to connect up to 128 devices per communication port. The combined humidity sensor, capacitive, operates at a frequency of 80 MHz and has just a 1-wire interface. Together with the humidity, it transmits the amount of illumination at the level of the sensor installation. Device data is not considered in this publication.
Progress: operation
By feeding, it was nice to see that the algorithm incorporated in the program works the way the developer wanted. The unit measured the distance to the water, determined that the barrel was empty, and turned on the pump for filling. In the process of filling the deviations of the level sensor readings were no more than 15 mm, which is quite acceptable. Filling the barrel, turned off the pump. Now the system is ready to start the watering process. At the initial stage, everything was smooth and beautiful - but many years of experience suggested that the most interesting things would be ahead.
Progress: problems and solutions
As it turned out, the installation of a disk filter for water purification was not at all superfluous - after 3 weeks of operation, the filter was so clogged that it simply did not let water into the system. Picture below.
Despite the fact that the water is clear, it turned out to be quite aggressive for the walls of the iron barrel. The barrel began to rust, and you see the result below. The solution turned out to be simple - we take and paint the barrel from the inside in two layers with durable enamel.
But this is not all - as it turned out, a barrel of water is very attractive for all sorts of algae, and they willingly settle in it. In my case, even such a small ecosystem turned out - the picture below.

The solution is also simple - as you know, sunlight is necessary for the development of algae. Just cover the barrel with opaque material. I was unable to completely stop accessing the light, and therefore, once a month, preventive rinsing of the tank is necessary.
But the solution of one problem causes the appearance of another - condensate began to collect on the covering. And if it were not for the performance of the IP67 sensor, the unit would very quickly become unusable. By the way, despite the apparent delicacy of the design, the ultrasonic sensor showed itself very positively. But I had to modify it, to put a ring reflector in order to compensate for false echoes at some distances. Apparently, the echo signals appear as a result of reflection of a bundle of sound pulses from the walls of the barrel. In my case, this distance was 230-250 mm.
Conclusion: the way forward
As I mentioned above, the downpour stopped testing in the late fall - the sharp cotton marked the failure of the 220V terminal power connector. Yes, and the time of year came when the device itself was no longer necessary.
Analyzing the received material, I came to an unexpected conclusion - there is no need for an instrument in this form. If you modify the sensor itself and give it access to standard exchange protocols such as modbus rtu, you can control it directly from the controller’s program without using any intermediate links. I also considered the option of using the 1-wire bus - but it is better to do the transfer of 4 x 16 bit values ​​on a faster version of the exchange protocol.
In conclusion, I want to say that if this publication arouses interest, then I will be happy to continue a series of publications about the projects that I assembled with a soldering iron and a programmer in my hands.