📜 ⬆️ ⬇️

Internet of Things (IoT) and plumbing

After publishing about the Internet of Things , we received a letter with the idea of ​​using the ESP-8266 module:

“The Master Kit company has a very interesting thing - a motorized ball valve . This modification is powered from voltage from 3 to 6 volts and perfectly opens and closes the water supply in domestic pipelines.


')
I have a crane at home without a motor and, unfortunately, is located in a terribly uncomfortable place. Every time when it is necessary to block the water, it is necessary to perform a plastic sketch "The Snake Man". Therefore, I decided to install a motorized crane once and forget about gymnastics. But I did not want to pull a bunch of wires to control the faucet in the newly renovated bathroom, so I began to think about a wireless solution.

Attention attracted module ESP-8266,



based on which Master Kit already has a two-channel MP3500 Wi-Fi relay .

But I do not need to manage large currents and voltages, but I wanted to hide the control board in the body of a motorized crane, so I wanted to minimize the size of the device. I decided to use a breadboard and pin components for testing.





The ESP8266 module connected to the motherboard with a cable, for programming the module I used the USB-UART adapter on the PL2303 chip that has already become standard. Drivers for the adapter without any problems found on the Internet.

But for ESP programming, I decided to use nodeMCU firmware, which allows you to control the module using not a set of AT commands, but the high-level scripting language LUA.

To communicate with the crane via Wi-Fi, it was decided to write a program for a smartphone on Android with the help of the project of the Massachusetts Institute of Technology Appinventor.
.
So, in order.

A motorized crane has three terminals: one common and two controllers, by supplying positive voltages from 3 to 6 volts to which you can open or close the valve. So, two GPIO pins (general purpose inputs / outputs) of the ESP module are enough for control. The scheme of the "experiment" is as follows:



The supply voltage of 3.3 V is taken from the USB-UART converter, the RXD and TXD terminals of the converter are connected respectively to the TXD and RXD terminals of the ESP module for programming. Resistors, in accordance with the recommendations of the manufacturer of the ESP module, pull the leads to the supply voltage, transistors serve to amplify the control current of the valve, which reaches 60 mA during opening or closing. At other times, the tap does not consume current.

The ESP module can operate in two modes - as an access point, when a smartphone connects directly to it, and in infrastructure mode, connecting to an existing router, which is now in almost every apartment. Thus, in the second mode, the smartphone is connected to the router. The module mode can be set during the setup process, which also happens with a smartphone.

A simple web-server is raised on the module, which waits for a command, reports a successful reception, processes it, and executes it by switching the corresponding GPIO to 0 or 1 for the time required to turn the crane.

As you can see, this uses only the internal capabilities of the ESP module, and it is not necessary to use any additional microcontroller control circuits. By the way, ESP modules also exist with a large number of GPIO operating in different modes, which can significantly expand the area of ​​its application.

The module firmware is poured using the ESPlorer utility - a very convenient IDE for ESP modules, which allows you to work with the module on LUA, Python and with the help of AT commands - all in one bottle!
The program for the smartphone serves to issue control commands and remotely configure Wi-Fi modes.





As already mentioned, it was created using the Appinventor project. In this project, programming takes place in a visual environment that does not require special knowledge in the field of programming android devices.

Of course, the program is somewhat redundant - the amount of the resulting code is much larger than with traditional programming, but it pays off with the simplicity and speed of development. It is not difficult to master the environment, and you can write quite digestible applications yourself. In addition, the memory of modern smartphones does not impose significant restrictions on the size of the programs loaded into them.

Below is a screenshot of the module management program from a smartphone (all pictures can be opened in a new window in its original size).



There are redundant elements that appeared in the process of mastering the exchange of data, but the basis is the event handlers for pressing the Button3 buttons — change the output state of the GPIO00 for opening the tap for 5 seconds, and Button4 for the output of the GPIO02 for closing, respectively. For example, when you click on Button3, the GET http: // ip_address / mode = cmd & sw0 call is sent to the server raised on the module, the output of the GPIO00 changes its state to 0; Clock2 timer is activated for 4000 ms, and after this time, a timer event is triggered, sending the same command that changes the state of the output of the GPIO00 to 1. The tap is open.



The following screenshot shows the part of the program that is responsible for setting the mode and parameters of the ESP module. Here, besides the Wi-Fi mode, you can change the IP address, port, network mask, gateway, wireless SSID and password. After sending the parameters to the module, it automatically reboots to work with the new parameters.



Module firmware, written in LUA, in a fairly standard way, described in the documentation, organizes a server that receives and processes incoming commands.

Bottom line: a bunch of ESP8266 - water tap works. This internet of things turned out. I will make a board on SMD elements, assemble it into a finished structure and install it. I'll finish - accomplish your goal! ”

Video testing for performance:

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


All Articles