📜 ⬆️ ⬇️

We water the flowers - simply and quickly

image

Hello, dear Habrozhiteli!
Recently my father called me, told me that he had a flower, which he constantly forgets to water or pours too much water, eventually he dries up, then suffers from an excess of moisture.

We will solve this problem with a microcontroller and C #.


')
Not long after consulting, it was decided to automate this process. We identified for ourselves the basic requirements for what we would like to see:


Part 1. Hardware

Asking a question on Habré ( question ), I received a lot of suggestions about Arduino and other devices, however, I stopped at AVR-USB-MEGA16 (thanks to Andrew for the advice and assistance in mastering, as well as for the speed of delivery).



As a result, the following components were purchased:


Total not counting all sorts of trifles got about 2,200 rubles.



All parts are very compact, the biggest is the pump:



So, everything is bought, it's time to build. The circuit for switching on the relay was advised by @AlekseyNovikov, for which many thanks to him. Here is the diagram:



The only thing that decided to remove the diode. Having spent the evening on the ration, it turned out quite sane result:



Now we come to the most interesting - the logic of work.

Part 2. Software part


Before the start of this venture, the main fear or fear was the complexity of microcontroller programming, the absence of normal debugs and other difficulties, so the main purpose of this article is not to describe the idea as such, because it is not new, but to promote the simplicity of using such devices with the help of modern languages programming such as C #.

We only need two things from the board:


So, I used WPF in conjunction with Sergey's Kukhteksky's firmware (for details, you can read how it works here ).
The program is a tray icon and a small unobtrusive window.



Program settings are also as simple as possible:



The main problems in the software include the following problems:
  1. The pump performance indicated on the pump has almost nothing to do with reality.
  2. The pump performance depends very much on the height of the water rise, for example, if the pump just drains water, then the performance of my pump specifically reaches 350 liters per hour, but at a height of 80 cm, it hardly reaches 40 liters per hour.
  3. It's hard to determine the capacity of the container in which the pump will work
  4. Before the water reaches the flower, it must not pass a simple way up the tube.


To solve these problems, a simple measurement-based algorithm was invented. After everything is in place, water is drawn into the tank:


Everything, the system is ready to work. According to the first parameter of the settings - the amount of watering, it is determined automatically based on the soil moisture sensor and the optimum humidity for this type of plant (unfortunately, I did not bring it into the interface, it is installed in the XML file)

The algorithm of the APC (Automatic Flower Polylka) is simple:

Once every ten minutes readings are taken from the soil moisture sensor (a number of measurements occur, the arithmetic average is taken). Based on the testimony, a decision is made to irrigate the soil, if the deviation from the norm is more than 5%, then watering occurs. Data on all actions are recorded in the database, based on them, an irrigation forecast is subsequently constructed, a graph and the required amount of irrigation is determined. The algorithm for determining the volume of poured liquid is also very simple. There is a certain standard of humidity, say 74% (indicated in the XML file for a specific plant), the first irrigation of 100 ml occurs, after 10 minutes the next measurement of humidity occurs and we look at the deviation from the reference humidity level, if the humidity is less than necessary, then the next watering is added in increments depending on the deviation (100 ml, 50 ml, 10 ml, 3 ml). If the level of humidity has not changed + -5 units, then we consider that the water in the reservoir has run out, send SMS.

Unfortunately, I do not like flowers , I simply don’t have them, so I didn’t succeed in running around the system on a real plant, I bought an experimental chrysanthemum, which successfully died in the first week of experiments. The mechanism was successfully sent to my father (hello to the Post of Russia, the parcel should have reached within a week, it is already three and it is not known what is with it), as soon as he installs and launches everything, he will definitely make a video and I will add it.

The disadvantages of this system include a lot, first of all, dependence on the PC, secondly, all this is quite massive, a large reservoir, wires go to it, a thick tube goes from it to the top of the pot, wires come out of the pot from the sensors, all this included in the outlet, because 220V pump.

The plans for the near future to eliminate all the shortcomings, I want to draw a 3D model that will include everything in one pot - tank, pump, water channels, sensors, LCD screen, etc., I want it all to work on batteries for at least six months This pot will work on the Arduin Mini Pro.

At the moment, I master Blender (I have a lot of experience in 3D Max), because I decided to completely abandon pirated software, after I finish, I pass the model into 3D printing, eliminate all the flaws, launch the prototype and will definitely write a continuation of this article.

UPD: I am attaching the current device circuit (without a diode, later it must be added)


The most interesting points are the preparation of the device:

public static bool Init() { dev = new ATMega16(vid, pid); //   dev  ATMega16. if (!dev.IsOpen()) //     USB { return false; } else //   ,    USB { dev.DDRD |= 0x80; //  7  D -   dev.PORTD &= 0x7F; //     dev.ADMUX = (3 << ATMega16.REFS0); //       //       200 .     //     128 ( ADPS0, ADPS1  ADPS2   1). ..  125 . //    (1/125000)*13 = 104 ,   - 9.6  //   ADEN  1    dev.ADCSRA = (1 << ATMega16.ADEN) | (1 << ATMega16.ADPS2) | (1 << ATMega16.ADPS1) | (1 << ATMega16.ADPS0); } return true; } 


Readings from the sensor:

  dev.ADMUX = (byte)((dev.ADMUX & 0xE0) | 0); //    - ADC0 dev.ADCSRA |= (1 << ATMega16.ADSC); //   //    ( 100 ).       while ((dev.ADCSRA & (1 << ATMega16.ADIF)) == 0) ; return (dev.ADCL + (((int)dev.ADCH) << 8)); //   


Conversion of readings from the sensor in% humidity, and later in line value:

  var persantage = (int)(stateOfSoil / 8.4); if (persantage < 10) result = ""; else if (persantage < 20) result = " "; else if (persantage < 30) result = ""; else if (persantage < 40) result = ""; else if (persantage < 50) result = ""; else if (persantage < 60) result = ""; else if (persantage < 70) result = ""; else if (persantage < 80) result = ""; else if (persantage < 90) result = ""; else result = ""; return String.Format("{0} ({1}%)", result, persantage); 


Turn on the pump:
  dev.PORTD |= 0x80; 


Disconnect the pump:
  dev.PORTD &= 0x7F; 

Source: https://habr.com/ru/post/195998/


All Articles