The master has two compressors in use, located in different places. For control, he had to measure the vibration and temperature of the compressors every day. Naturally, it takes time. To solve the problem, the master decided to make remote control over their condition. In principle, instead of a compressor, there can be any other device.
Also in the article we will get acquainted with the Blynk application, find out which ESP module to choose, what is the MPU6050 board for and much more.
Tools and materials: -GY module- 521 MPU6050;
– ESP8266 microcontroller; -Breadboard;
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050300_1-4.jpg" rel = "prettyPhoto"> Step first: module GY-521 MPU6050
The MPU-6050 board combines 3 gyroscope axes and 3 accelerometer axes and can be used to control the operation of the compressor.
The principle of operation of the module:
Gyro sensors can monitor orientation, direction, angular movement, and rotation. On a smartphone, a gyro sensor usually performs gesture recognition functions. In addition, smartphone gyroscopes help determine the position and orientation of the device.
An accelerometer is a sensor that measures acceleration, as well as tilt, tilt, rotation, vibration, collision, and gravity. When used on a smartphone, the accelerometer can automatically change the display of the phone vertically or horizontally, since this sensor can check which axis the gravitational acceleration vector is acting on.
This sensor uses the I2C communication protocol.
I2C can work in two modes, Master and Slave.
VCC – positive power contact;
GND – ground;
SDA – I2C data line;
SCL – I2C clock line;
INT – configurable interrupt;
AD0 – I2C address; by default, AD0 is pulled to ground, so the device address is 0x68; if you connect AD0 to the power contact, the address will change to 0x69;
XCL, XDA – additional I2C interface for connecting an external magnetometer
Step two: BLYNK application
new devices that can also be programmed in Arduino , and the use of expansion boards (boards that add functionality to Arduino devices) have added project capabilities that can be developed on Arduino .
At the same time, the emergence of Internet-connected services and the concept of IoT (Internet of Things) have increased the demand for devices that have connectivity and thus enable remote control of those devices over the Internet.
BLYNK is one of those services.
This program allows you to remotely control the firmware, as well as transfer hardware data to the application.
Thus, you can quickly and intuitively create graphical control interfaces that interact with more than 400 boards, mainly based on Arduino .
Blynk App is a program available for Android and iOS that allows the user to create apps that interact with hardware. For each project, the user can insert widgets that implement control functions (such as buttons, sliders, and keys), notifications and read equipment data (display on displays, graphs and maps).
All interaction between the application and the user's equipment takes place through the Blynk cloud. The server is responsible for transferring data to the equipment, saving the states of applications and equipment, as well as storing the sensor data read by the equipment, even if the application is closed.
Data stored on the Blynk server can be accessed externally via the HTTP API, which opens the ability to use Blynk to store periodically generated data, for example, temperature sensor data.
In terms of hardware, we have Blynk libraries for several development platforms. This library is responsible for managing all hardware connections to the Blynk server and managing I/O requests for data and commands.
Blynk is available for free download. Access to the Blynk server is unlimited (and still allows you to implement it locally through the provided open source code), the Blynk Libraries are also free.
However, each widget “costs” a certain amount of energy – a kind of virtual currency. Upon registration, each user is given 2000 units of energy. If you need more energy, you can purchase it additionally.
If the project is “disassembled”, the energy is returned back to the user's backpack.
Step third: installing the application
To install the Blynk app on your smartphone, you need to check if the operating system is compatible with the app. The prerequisites for installation are as follows: Android OS version 4.2+.
IOS version 9+.
You can also run Blynk on emulators.
You can download the app from Google Play or App Store.
After installing the application, the user must create an account on the Blynk server.
You must use a valid email email address as it will be used frequently later.
Step four: creating a new project
After registration, the main screen of the application will appear. Next, you need to select the New Project option, and a new page will open.
Next, in the Project Name column, enter the name of the project. Select the type of device you will use on the Choose Device tab.
This project used the name Project IOT with the ESP8266 option selected.
After clicking the Create button, the user will have access to the project canvas, that is, to the space where you can create your own application.
At the same time, an email with a code will be sent to the email address registered in the application.
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050339_1-13.jpg" rel = "prettyPhoto"> Step five: setting up the project and widget
On the project page, click anywhere on the screen and a list of available widgets will open.
There are 5 types of widgets:
Controllers – are used to send commands to control equipment.
Displays – are used to view data from sensors and other sources ;
Notifications – sending messages and notifications;
Interface – widgets for performing certain functions of the graphical interface;
Other – widgets that do not belong to any category;
Each widget has its own settings.
In this project, the SuperChart widget was selected. The SuperChart widget costs 900 energy units, which will be deducted from the initial 2000 amount shown at the top of the screen. This widget will then be added to the project layout. Since there are two compressors, you need two widgets.
Since this widget is a data viewer, that is, data on temperature and vibration that will sent to Blynk, some settings are needed to display them correctly:
Clicking on this widget displays the configuration options.
On this new screen, click DataStream, name it and click the configuration icon, where you can find the following information:
Digital Pins – These are the physical digital pins on your hardware. PWM-enabled pins are marked with ~.
Analog pins – represent the physical analog I/O pins on your hardware.
Virtual pins – used to transfer any data between the Blynk app and your hardware.
This project uses VIRTUAL V4 for temperature and VIRTUAL V1 for vibration.
After executing the command, the application will try to connect to the equipment through the Blynk server. However, we still don't have the equipment configured to use it.
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050297_1-17.jpg" rel = "prettyPhoto"> < a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050345_1-19.jpg" rel = "prettyPhoto"> < a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050314_1-21.jpg" rel = "prettyPhoto"> < a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050275_1-23.jpg" rel = "prettyPhoto"> Step sixth: installing the library and the code
Now we need to install the Blynk library for the Arduino IDE.
Download the Blynk_Release_vXX.zip file. Then unzip the contents of the file in the Arduino IDE's albums folder. The location of this folder can be found directly from the Arduino development environment. To do this, open the Arduino IDE and in File → Preferences look at the location of the Sketchbook.
After that the contents of the unpacked file should look like this:
After restarting the Arduino IDE, new code samples related to the Blynk library can be found under File → Examples → Blynk. For this hardware example, ESP8266, the wizard selects the example File → Examples → Blynk → Boards_WiFi → ESP8266_Standalone.
Photo below defines an authorization token for equipment management.
This token is a unique number that was generated when the project was created in the application and must be filled in according to the code sent by email.
The lines below must match the name and password of the Wi-Fi network to which the ESP8266 will connect.
After the lines of code have been corrected, download the software to the development board.
The code can be viewed below.
#define BLYNK_PRINT Serial #include #include #include char auth & # 91; & # 93; = & # 34; Código do autor do projeto & # 34 ;; //Your WiFi credentials. //Set password to & # 34; & # 34; for open networks. char ssid & # 91; & # 93; = & # 34; Nome da rede WIFI & # 34 ;; char pass & # 91; & # 93; = & # 34; SSID rede WIFi & # 34 ;; //MPU6050 Slave Device Address const uint8_t MPU6050SlaveAddress = 0x68; //Select SDA and SCL pins for I2C communication const uint8_t scl = D1; const uint8_t sda = D2; //sensitivity scale factor respective to full scale setting provided in datasheet const uint16_t AccelScaleFactor = 16384; const uint16_t GyroScaleFactor = 131; //MPU6050 few configuration register addresses const uint8_t MPU6050_REGISTER_SMPLRT_DIV = 0x19; const uint8_t MPU6050_REGISTER_USER_CTRL = 0x6A; const uint8_t MPU6050_REGISTER_PWR_MGMT_1 = 0x6B; const uint8_t MPU6050_REGISTER_PWR_MGMT_2 = 0x6C; const uint8_t MPU6050_REGISTER_CONFIG = 0x1A; const uint8_t MPU6050_REGISTER_GYRO_CONFIG = 0x1B; const uint8_t MPU6050_REGISTER_ACCEL_CONFIG = 0x1C; const uint8_t MPU6050_REGISTER_FIFO_EN = 0x23; const uint8_t MPU6050_REGISTER_INT_ENABLE = 0x38; const uint8_t MPU6050_REGISTER_ACCEL_XOUT_H = 0x3B; const uint8_t MPU6050_REGISTER_SIGNAL_PATH_RESET = 0x68; int16_t AccelX, AccelY, AccelZ, Temperature, GyroX, GyroY, GyroZ; void setup () & # 123; Serial.begin (9600); Wire.begin (sda, scl); MPU6050_Init (); Blynk.begin (auth, ssid, pass); } void loop () & # 123; double Ax, Ay, Az, T, Gx, Gy, Gz; Read_RawValue (MPU6050SlaveAddress, MPU6050_REGISTER_ACCEL_XOUT_H); //divide each with their sensitivity scale factor Ax = (double) AccelX/AccelScaleFactor; Ay = (double) AccelY/AccelScaleFactor; Az = (double) AccelZ/AccelScaleFactor; T = (double) Temperature/340 + 36.53; //temperature formula Gx = (double) GyroX/GyroScaleFactor; Gy = (double) GyroY/GyroScaleFactor; Gz = (double) GyroZ/GyroScaleFactor; Serial.print (& # 34; Ax & # 58; & # 34;); Serial.print (Ax); Serial.print (& # 34; Ay & # 58; & # 34;); Serial.print (Ay); Serial.print (& # 34; Az & # 58; & # 34;); Serial.print (Az); Serial.print (& # 34; T & # 58; & # 34;); Serial.println (T); delay (1000); Blynk.run (); Blynk.virtualWrite (V1, Ax); Blynk.virtualWrite (V2, Ay); Blynk.virtualWrite (V3, Az); Blynk.virtualWrite (V4, T); } void I2C_Write (uint8_t deviceAddress, uint8_t regAddress, uint8_t data) & # 123; Wire.beginTransmission (deviceAddress); Wire.write (regAddress); Wire.write (data); Wire.endTransmission (); } //read all 14 register void Read_RawValue (uint8_t deviceAddress, uint8_t regAddress) & # 123; Wire.beginTransmission (deviceAddress); Wire.write (regAddress); Wire.endTransmission (); Wire.requestFrom (deviceAddress, (uint8_t) 14); AccelX = (((int16_t) Wire.read () & lt; & lt; 8) | Wire.read ()); AccelY = (((int16_t) Wire.read () & lt; & lt; 8) | Wire.read ()); AccelZ = (((int16_t) Wire.read () & lt; & lt; 8) | Wire.read ()); Temperature = (((int16_t) Wire.read () & lt; & lt; 8) | Wire.read ()); GyroX = (((int16_t) Wire.read () & lt; & lt; 8) | Wire.read ()); GyroY = (((int16_t) Wire.read () & lt; & lt; 8) | Wire.read ()); GyroZ = (((int16_t) Wire.read () & lt; & lt; 8) | Wire.read ()); } //configure MPU6050 void MPU6050_Init () & # 123; delay (150); I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_SMPLRT_DIV, 0x07); I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_PWR_MGMT_1, 0x01); I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_PWR_MGMT_2, 0x00); I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_CONFIG, 0x00); I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_GYRO_CONFIG, 0x00); //set +/- 250 degree/second full scale I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_ACCEL_CONFIG scale, 0x00); //set +/- 2gEGISTER_CONFIG; //set +/- 2g I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_INT_ENABLE, 0x01); I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_SIGNAL_PATH_RESET, 0x00); I2C_Write (MPU6050SlaveAddress, MPU6050_REGISTER_USER_CTRL, 0x00); }
Code (3) .pdf Step Seven: ESP Module
The ESP6050 is a chip that revolutionized its low cost and rapid adoption.
What gets the most attention is the presence of Wi-Fi, which allows multiple devices to be connected to the Internet (or local network), such as sensors, actuators, and etc.
To facilitate the use of this chip, several manufacturers have created modules and development boards.
These modules vary in size, number of pins, or type of connection.
The modules use the same ESP8266 controller, and the number of GPIO ports depends on the module model … Depending on the model, there may be I2C, SPI and PWM interfaces (besides serial).
The modules are powered by 3.3V. They also have a 32-bit processor running at 80MHz, which supports 802.11 b/g/n internet and various security protocols like WEP, WPA, WPA2, etc.
Programming can be done with AT commands or in LUA language. They are ideal for IoT projects as they consume very little power in hibernation.
Now about the differences between the modules.
ESP8266 ESP-01 module.
The ESP8266 ESP-01 module is the most common module in the ESP8266 line.
It is compact (24.8 x 14.3 mm) and has two GPIO pins, which can be controlled on a schedule. The ESP-01 firmware can be rewritten and/or upgraded using the serial interface.
A slight disadvantage of this type of module is the pin arrangement, which makes it difficult to use in the prototype board, but you can use an adapter for the ESP8266 ESP-01 Wi-Fi module (pictured below).
Module ESP8266 ESP-05.
The ESP8266 ESP-05 Wi-Fi module is slightly different from other boards in the ESP8266 line, as it does not have ports that can be used to activate devices or read data from sensors.
On the other hand, it is an interesting alternative for IoT projects when you need a good internet connection at a low cost.
It can be used, for example, to set up a web server with Arduino or for long distance communication between boards.
It does not have a built-in antenna, but it does have a connector for an external antenna, which greatly increases the range of the Wi-Fi signal.
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050300_1-34.jpg" rel = "prettyPhoto"> < a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050320_1-36.jpg" rel = "prettyPhoto"> ESP8266 ESP-07 module.
ESP8266 ESP-07 module is also a compact module (20 x 16 mm), but with a different layout, without connecting contacts.
The module has a built-in ceramic antenna, as well as a U-Fl connector for connecting an external antenna. This module has 9 GPIOS that can act as I2C, SPI and PWM pins.
The layout of the module makes it easy to integrate it into a PCB widely used in home projects automation.
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050366_1-38.jpg" rel = "prettyPhoto"> ESP8266 ESP-12E module.
ESP8266 ESP-12E module is very similar to ESP- 07, but only has an internal antenna (PCB).
It has 11 GPIO pins and is widely used as a base for other ESP8266 modules such as NodeMCU.
Module ESP8266 ESP-201.
The ESP8266 ESP-201 module is a bit easier to use from a prototyping point of view as it can be mounted on a breadboard.
4 side pins, which are responsible for serial communication, a little interfere with this type of assembly, but you can solder these pins on the opposite side of the board or use some kind of adapter.
The ESP-201 has 11 GPIO ports, a built-in antenna, and a U-FL connector for an external antenna. Antenna is selected by changing the jumper (0 (zero) ohm resistor) at the top of the board, next to the U-FL connector.
ESP8266 ESP-12E module.
ESP8266 NodeMCU ESP-12E module is a complete development board that has a TTL-Serial converter and 3.3V voltage regulator in addition to the ESP8266 chip.
It is a module that can be directly connected to a breadboard and does not require an external microcontroller to operate, as it can be easily programmed with LUA.
It has 10 GPIO pins (I2C, SPI, PWM), micro-usb connector for programming/power supply and buttons for reset and firmware of the module.
As we can see in the image, NodeMCU ESP-12E comes with a built-in antenna soldered to the board.
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050290_1-44.jpg" rel = "prettyPhoto"> Step eighth: installation
The master makes the assembly on a breadboard.
A breadboard is a plate with holes and conductive paths used to assemble prototypes and projects. PCB sizes range from 800 to 6000 holes, with vertical and horizontal connections.
There is a plastic base on the surface of the contact matrix, which has holes for installing components. Metal contacts are installed in its lower part. They usually withstand currents from 1 to 3 A.
The MPU6050 uses I2C protocol so only two wires are needed. The SCL and SDA pins of the MPU6050 are connected to the D1 and D2 pins of the NodeMCU, while the VCC and GND pins of the MPU6050 are connected to the 3.3V and GND NodeMCU.
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050339_1-49.jpg" rel = "prettyPhoto"> Then the device is installed directly on the compressor.
< a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050317_1-52.jpg" rel = "prettyPhoto"> < a href = "https://usamodelkina.ru/uploads/posts/2020-12/1609050352_1-54.jpg" rel = "prettyPhoto"> Below you can see graphs compiled on the basis of transmitted data from sensors.
Here you can download and watch a video with an example of how the device works.