Wi-Fi Relay Module Based on ESP8266 - Overview and Connection

Wi-Fi Relay Module Based on ESP8266 - Overview and Connection

Daniil Zhuk

In this article, we will explain how to use the ESP8266 module with a relay to control home appliances.

This is a single-channel relay module with a WiFi interface based on the ESP8266 microcircuit. It controls the operation of the relay through the application. The ideal tool to manage all the appliances in your home using your phone, wherever you are.

FEATURES AND FEATURES

  • The built-in WiFi module with an ESP8266 microcircuit operating in the access point mode can be connected to 5 ‑ and clients simultaneously.
  • The relay module with WiFi has two modes of operation:
  • 1. The smartphone is directly connected to the WiFi module;
  • 2. The smartphone and the WiFi module are connected to the same router.
  • Transmission range: In open space, the maximum transmission distance is 400 m in the case where the smartphone is directly connected to the WiFi module. If the WiFi module and the smartphone are connected to the same router, the transmission distance depends on the signal strength of the router.
  • The built-in relay for 1 channel with an input voltage of 5 V for output circuits 10, A, 250 V AC and 30 V DC, withstands up to 100,000 operations in continuous mode, has a short response time.

The block diagram of the module is shown in the drawing below:

INSTRUCTIONS FOR SETUP WI-FI MODULE ESP8266
1. WiFi module ESP8266 has three modes of operation:

  • STA (client)
  • AP (Access Point)
  • STA + AP (access point + client
The WiFi mode of the ESP8266 module is selected based on the selected mode of the relay module.

INSTRUCTIONS FOR SETUP WI-FI MODULE ESP8266
2. WiFi module ESP8266 has three modes of operation:

STA (client)
AP (Access Point)
STA + AP (access point + client)
The WiFi mode of the ESP8266 module is selected based on the selected mode of the relay module....

3. The data transfer rate of the WiFi module can be 115.200 or 9600 baud. To change the speed, you can use AT commands, for example: AT + CIOBAUD = 115200. In general cases, we recommend using a speed of 115.200, but you will need to change the speed to 9600 if you use a smartphone to control the relay (as the speed of the STC15F104W microcontroller integrated in the module is 9600 baud).

 OPERATION MODE 1 - SMARTPHONE CONNECTED TO MODULE DIRECTLY

Run the USR-TCP232-Test-V1.3 debugging program on the PC and send the following AT commands, one by one:

  • AT+CWMODE=2 - select the mode of the access point AP;
  • AT+RST - restart the module;
  • AT+CIPMUX=1 - establish several connections;
  • AT+CIPSERVER=1.8080 — configure the TCP server, set the port number;
  • AT+CIFSR - look at the IP address for the AP mode, like this: APIP, “192.168.4.1”;
  • AT+CIOBAUD=9600 - set the baud rate of the serial port to 9600 baud.

 Now we connect to the access point created by the WiFi module using a smartphone with Android OS.

 

 Install the EasyTCP_20 application on your smartphone with Android OS and launch it; Click the "CONNECT" button and enter the device address (IP Address) and port number (Port).

Click on function blocks and enter the names and contents of commands sent via the serial port. For example, using the command “A00101A2” - you can set the opening of the relay, and the command “A00100A1” - closing the relay.

All commands must be given in hexadecimal.

 

Now, by clicking on the function blocks, you can send commands to the serial port and thus control the relay located on the card.

OPERATION MODE 2 - SMARTPHONE AND WIFI MODULE CONNECTED TO ONE ROUTER

Run the USR-TCP232-Test-V1.3 debugging program on the PC, send the following commands one by one:

  • AT+CWMODE=1 - select the STA client mode;
  • AT+RST - restart the module;
  • AT+CWJAP=<ssid>,<password> - let the WiFi module connect to the router, for example: AT + CWJAP = "LCTECH", "12345678";
  • AT+CIPMUX=1 - establish several connections; For example:
  • AT+CIPSERVER=1.8080 - set up a TCP server, set the port number;
  • AT+CIFSR - look at the IP address for the STA mode, like this: STAIP, “192.168.1.103”;
  • AT+CIOBAUD=9600 - set the baud rate of the serial port to 9600 baud.

Now connect from your smartphone to your router.

Install the EasyTCP_20 application on your smartphone with Android OS  and launch it; Click the "CONNECT" button, enter in the fields the IP address (Address) of the module and the port number (Port).

Click on function blocks and enter the names and contents of commands sent via the serial port. For example A00101A2 is an open relay, A00100A1 is a closed relay. Commands must be written in hexadecimal.

Now, by clicking on the function blocks, you can send commands to the serial port to control the relay.

 

TIPS

  1. After restarting, the relay module with WiFi needs to be reconfigured. If your firmware is written in the Arduino IDE, then the minimum set of commands needed when running can be placed in the setup () function
  2. The ESP8266 module has an idle function; If the smartphone does not send commands to the WiFi module for a certain period of time (the default is 180 seconds), then it goes into standby mode and disconnects from your smartphone. To change this period, you can send the command “AT + CIPSTO =” from the PC (“time” can be from 0 to 7200 seconds), for example: AT + CIPSTO = 3600.
  3. If the module in response, instead of “OK”, sends the command that you sent using the USR-TCP232-Test-V1.3 program, then the module must be reconfigured. Before sending commands, you can press the ENTER button.
  4. If there is no response when working through the USR-TCP232-Test-V1.3 program, then look at the speed when communicating with the module - it may be configured incorrectly. You can try 115200 or 9600, but if you use a smartphone to control the relay, the speed must be 9600 baud (you can change the speed by sending AT + CIOBAUD = 9600), since the transfer rate of the built-in microcontroller STC15F104W is 9600 baud.
  5. If you want to use the computer to control the relay directly (the baud rate is 9600 baud), you can do the following: disconnect the WiFi module with the ESP8266 chip; connect the TX, RX and GN terminals from the USB to TTL converter and connect them to the TX, RX and GND terminals of the relay module; IN + and IN- terminals connect to 5V DC power supply. Send commands to the serial port (A00101A2 - open relay, A00100A1 - closed relay, commands must be in hexadecimal) using a debugging program installed on the PC to control the relay.
  6. If the relay does not open or close, you may need to remove the resistor R4 and connect the VCC power output from the USB-TTL converter to the 5V output of the relay module.

Add a comment

* Comments must be approved before being displayed.