DIY

Device for monitoring the water level in the tank and transmitting data wirelessly

Device for monitoring the water level in the tank and data transmission over the wireless network  Device for monitoring the water level in the tank and transmitting data wirelessly Device for monitoring the water level in the tank and transmitting data wirelessly On the site, the author of this homemade product has a reservoir with rainwater flowing from the roof during precipitation. This water is used for various household needs of washing, watering plants in the garden, etc. The last three years in this area, the summer has been very dry and the water level in the reservoir had to be constantly monitored. Usually the master did it with a long stick, but in this age of electronics, it would be foolish not to take advantage of its fruits.
Tools and Materials: – ESP8266 ESP-12F; – ESP-12F Expansion Board; – FT232RL FTDI Serial Adapter Module; – HC-SR04-P Ultrasonic Module; Please note that the letter P is important as this is a low minimum operating voltage version 3 V.
-BME280 3.3V version: temperature, pressure and humidity sensor; -n-channel MOSFET-transistor IRL2203N; -Voltage regulator MCP1700-3302E 3.3V; -3 AA batteries; -Battery compartment for 3 batteries; -Project board; Resistors: 1pc .- 470K, 1pc. – 100K, 4pcs. – 10K; -Two ceramic capacitors 1 μF each; -Toggle switch – 3 pcs; -U-shaped breadboard wires; Step one: about the device
The idea is to install an ultrasonic sensor at the top of the tank. This sensor acts as a locator, emitting sound waves that are then reflected off the surface of the water. From the time it takes for the waves to return and the speed of sound, you can calculate the distance to the surface of the water and determine how full the tank is.
Since it does not have an electrical outlet near the tank, it is important that the device works autonomously, from a battery. This means that when designing a device, energy consumption must be taken into account.
To transfer data, the master decided to use the built-in Wi-Fi of the ESP8266 microchip. Although Wi-Fi is quite power-hungry, it has an advantage over other types of radio communication: the user can directly connect to the wireless network.
To save energy, the ESP8266 is in sleep mode most of the time, and only takes measurements once an hour. For this task, this interval is more than enough. After scanning, the data is sent to ThingSpeak (cloud storage), and then it can be read on the smartphone via the application.
The sound speed used in the algorithm of the device depends on temperature and, to a lesser extent, on humidity. For accurate outdoor measurements in different seasons, the wizard added a BME280 sensor that measures temperature, humidity and pressure. As a bonus, this makes this device also a mini-weather station.
Step two: ultrasonic sensor
The device will measure the distance to the water surface using the HC-SR04-P ultrasonic sensor. As with the bat, this sensor uses a locator. It sends out a sound pulse at a frequency too high for the human ear, i.e. ultrasonic, and waits for it to hit the object, reflect and return.
Specifically, if the trigger pin is high for at least 10 μs, the sensor sends a burst of 8 pulses at 40 Hz. The response is then received at the Echo pin in the form of a pulse with a duration equal to the time between sending and receiving the ultrasonic pulse. Then you need to divide by 2, since the ultrasonic pulse goes back and forth, and you need to multiply the travel time in one direction by the speed of sound, which is about 340 m/s.
But, the speed of sound also depends on temperature and, to a lesser extent, on humidity. How relevant is this in this case? In winter, at -5 ° C, the speed is 328.5 m/s, and in summer, at 25 ° C, 347.1 m/s. Suppose the one-way travel time is 3ms. This means that in winter the distance will be 98.55 cm, and in summer 104.13 cm. This is a big difference. This means you need to install a thermometer to track and adjust according to its readings. The master decided to install a BME280 sensor, which measures temperature, humidity and pressure. The code he used in the speedOfSound function contains a formula that calculates the speed of sound given all three parameters.
There is one more important nuance regarding the HC-SR04. There are two versions on the market: the standard version operates from 5V, and the HC-SR04-P can operate in a voltage range of 3 to 5V. Since 3 AA rechargeable batteries provide approximately 3×1.25V = 3.75V, P is needed. -version.
Device for monitoring the water level in the tank and transmitting data wirelessly Device for monitoring the water level in the tank and transmitting data wirelessly Step three: choosing the ESP8266 board < br>To keep the sensor running on battery power as long as possible, you need to save on energy consumption. While Wi-Fi ESP8266 provides a very convenient way to connect the sensor to the cloud, it is also quite power hungry. During operation, the ESP8266 consumes about 80 mA. Thus, with 2600 mAh batteries, the device will be able to work no more than 32 hours.
Fortunately, the ESP8266 has a deep sleep mode in which almost all features are turned off. The idea is to put the ESP8266 into deep sleep most of the time and wake it up periodically to take measurements and send data over Wi-Fi to the cloud. According to this guide, the maximum deep sleep time for the ESP8266 was about 71 minutes, but since the release of the ESP8266 Arduino 2.4.1 core it has increased to about 3.5 hours. The wizard set the interval to one hour.
Most ESP8266 boards use the AMS1117 voltage regulator, which is very power consuming. The only exception is the WEMOS D1 mini, which comes with the more economical ME6211. WEMOS D1 mini consumes about 150 μA in deep sleep.
ESP-12F is even more economical in this regard. This board does not have a USB UART or voltage regulator. Consumption in deep sleep mode is only 22 μA.
Device for monitoring the water level in the tank and transmitting data wirelessly Step four: cloud service
The wizard will use ThingSpeak, an IoT cloud service, to store the data. Go to https://thingspeak.com/and create an account. After logging in, click the “New Channel” button. Enter the name and description in the channel settings. Then we name the channel fields and activate them by checking the boxes on the right. The author's field settings are as follows:
Field 1: water level (cm) – (level)
Field 2: battery level (V) – (battery)
Field 3: temperature (° C) – (Temperature)
Field 4: humidity (%) – (humidity)
Field 5: pressure (Pa) – (pressure)
For further use, you need to write down the channel ID, read API key and write API key, which can be found in the keys menu API.
In the future, you can read data from the cloud on your smartphone using the application. On an Android phone, the wizard uses the IoT ThingSpeak Monitor widget.
Step Four: Programming the ESP-12F
For programming, the wizard will use the Arduino IDE. To prepare it to work with the ESP8266, follow these steps:
Download the Arduino IDE.
Next, in the File – Preferences – Settings menu add the URL http://arduino.esp8266.com/stable/package_esp8266com_index.json to additional Board Manager URLs. Next, in the Tools – Board – Boards Manager menu, install esp8266.
Choose as a board: Generic ESP8266 Module.
To work with the ESP-12F, the master used an expansion board. He soldered the IC to the board and then soldered the connectors to the plate. After mounting, he found that the expansion board was too wide for a standard breadboard. There are no free contacts on the side to connect.
The solution he chose is to use U-shaped wires and connect them like in the photo below. In this way, GND and VCC are connected to the rails on the breadboard and the remaining pins become accessible. The disadvantage is that the breadboard will be braided with wires after the device is installed.
Another solution is to connect the two breadboards together as shown in this video.
Next, you need an adapter to program the ESP-12F through the USB port of your computer. The master used the FT232RL FTDI programmer. The programmer has a jumper to select the voltage between 3.3 V or 5 V. In this case, you need to set 3.3 V. The installation of the drivers should be automatic, but if the programming fails, you can try to install them manually from this page.
The ESP8266 has a programming mode for loading new firmware into flash memory and a flash memory mode for running the current firmware from it. To choose between these modes, the pins must take on a certain value during boot:
Programming: GPIO0: low, CH-PD: high, GPIO2: high, GPIO15: low
Memory: high, CH-PD: high, GPIO2 : high, GPIO15: low
Also, make sure you connect the TX pin of the FT232RL to the RXD pin of the ESP8266.
The programming sequence is as follows:
Set GPIO2 to low by closing the programming switch.
Reset the ESP8266 by closing and then opening the reset switch again. ESP8266 now boots in programming mode.
Set GPIO2 back to high by opening the programming switch.
Download new firmware from the Arduino IDE.
Restart the ESP8266 again by closing and reopening the reset switch. The ESP8266 now boots in flash mode and runs new firmware.
You can now test if the programming is working by uploading the Blink sketch.
The sketch checks the GND, VCC, GPIO2, RST, TXD and RXD pins.
Before proceeding, he would recommend also checking the other pins with a multimeter. To do this, you need to use this sketch, which sets all pins to high level one by one for 5 seconds, and then puts the ESP8266 into deep sleep for 20 seconds. For the ESP8266 to wake up, you need to connect the RST to GPIO16.
Device for monitoring the water level in the tank and transmitting data wirelessly Device for monitoring the water level in the tank and transmitting data wirelessly Step five: download the sketch
You can download the code here.
At the beginning of the file, you need to enter some information: the name and password of the WLAN you are using, the static IP address, and the channel ID and API key of the ThingSpeak channel.
Following the advice on this blog, instead of DHCP, where the router dynamically assigns an IP address, you should use a static IP address. With this setting, data exchange is much faster and therefore we save active time and battery power. Therefore, we have to set an available static IP address as well as the router (gateway) IP address, subnet mask and DNS server. If you are unsure of what to enter, read about setting up a static IP address in the manual for your router. On a Windows computer connected via Wi-Fi to your router, start a shell (Windows-r button, cmd) and type ipconfig/all. You will find most of the information you need in the Wi-Fi section.
Here are the main features of the code:
Upon waking up, the code sets switchPin (GPIO15 by default) high. This action turns on the transistor, which in turn turns on the HC-SR04-P sensor. Before falling into deep sleep, it sets the pin low again, turning off the transistor and the HC-SR04-P.
If modePIN (default GPIO14) is low, the code goes into OTA mode instead of measurement mode. With OTA (Over the Air Update), we can update the firmware over Wi-Fi and not over the serial port. In this case, it is quite convenient, since you do not need to connect the serial port to the USB adapter. Just set GPIO14 low (using the OTA switch in the electronics), reset the ESP8266 (using the reset switch).
The analog PIN (A0) measures the battery voltage. This allows you to turn off the device if the voltage gets too low and replace the battery.
The distance measurement of the HC-SR04-P is performed in the DistanceMeasurement function. To improve accuracy, the measurement is repeated numMeasuresDistance (3 times by default).
There is a function to calculate the speed of sound based on temperature, humidity and pressure measurements from the BME280. The default I2C address of BME280 is 0x76, but if it does not work, you will need to change it to 0x77: BOOL bme280Started = bme280.begin (0x77);
The wizard will use BME280 in forced mode, which means that one measurement is taken and it enters sleep mode again to save power.
If the user sets the tank (L), total distance (cm) and area (m2), the code calculates the remaining tank volume from the measured distance: double the remaining volume = tank + 10.0 * (full distance) * area; and uploads data to the cloud. If you keep the defaults, it loads the distance to the water surface in centimeters.
Step Six: Scheme
Device for monitoring the water level in the tank and transmitting data wirelessly Above is a diagram. It is quite large for a single breadboard, especially with the oversized expansion board and U-shaped wires.
The device is powered by battery voltage (about 3.75V) and 3.3V, which powers the ESP8266 and BME280. The master planned 3.3V to the left side of the board and 3.75V to the right. The voltage regulator converts 3.75V to 3.3V. He added 1uF capacitors to the input and output of the voltage regulator to improve stability.
GPIO15 ESP8266 connects to the gate of the transistor. This allows the ESP8266 to turn on the transistor, and therefore the ultrasonic sensor, when active, and turn it off when falling into deep sleep.
GPIO14 connects to OTA switch. Closing the switch signals to the ESP8266 that we want to start the next mode in OTA mode, that is, after we press (close and open) the RESET switch and upload a new sketch wirelessly.
The RST and GPIO2 pins are connected as shown on the programming diagram. The RST pin is now also connected to GPIO16 to allow the ESP8266 to wake up from deep sleep.
The TRIG and ECHO pins of the ultrasonic sensor are connected to GPIO12 and GPIO13, and the BME280's SCL and SDA pins are connected to GPIO5 and GPIO4.
Finally, the analog output of the ADC is connected to the input voltage via a voltage divider. This allows you to measure the input voltage to check the battery charge. The ADC pin can measure voltage from 0 to 1V. The master chose 100K and 470K resistors as the voltage divider.
Even when the circuit is running on batteries, you can connect the USB to a serial adapter. Just remember to unplug the adapter's VCC and connect GND, RX and TX as shown in the programming diagram. This allows you to open the Serial Monitor in the Arduino IDE to read debug messages and make sure everything is working as expected.
For the whole circuit, the current consumption in deep sleep mode when operating on batteries is 50 μA.
The total activity time is about 7 seconds, of which 4.25 seconds for connecting to Wi-Fi and 1.25 seconds for sending data to the cloud. After a series of calculations, he came to the conclusion that the 2600 mAh battery is theoretically enough for 12400 hours = 515 days.
Step Seven: Hull
The technician placed the sensor in a 1 liter plastic container. At the bottom I made two holes for the “eyes” of the HC-SR04-P sensor. In addition to the holes, the container must be waterproof. Then the device is attached to the tank wall.
Device for monitoring the water level in the tank and transmitting data wirelessly Device for monitoring the water level in the tank and transfer data over the wireless network  Device for monitoring the water level in the tank and transmitting data wirelessly

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button