Simple WiFi relay board (1): an overview of two popular modules on Chinese Websites

In his video nr 107 youtuber Ralph Bacon describes his ‘frustration’ with an ESP8266-01 based wireless relay he got from AliExpress.

Wifi relay with ESP8266-01 and STC15F104 microprocessor

His frustration is understandable as that particular module is needlessly complicated. It seems the ESP8266-01 is mainly there to make the WiFi connection, while the relay is triggered by yet another microprocessor, the STC15F104. Communication between the two is via the serial port of the ESP8266, as if the designers thought, how can we make this in the dumbest way possible.
If you want to use this relay, this is how to do it:

Set the serialport to 9600 with : Serial.begin(9600);

To enable the Relay send the proper command bytes to serial port:

const byte ReBufferON[] = {0xA0, 0x01, 0x01, 0xA2};
Serial.write(ReBufferON, sizeof(ReBufferON));

To disable the Relay send the following bytes to the serial port:
const byte reBufferOFF[] = {0xA0, 0x01, 0x00, 0xA1};
Serial.write(ReBufferON, sizeof(ReBufferOFF));

Apparently it will also work with AT commands.

The circuit looks like this

If you expereince problems with this board, you may want to check here. There is also a 4 channel version (check here for more info).

###

An even simpler board

The ‘simple’ relay board

In his follow up video # 110  Ralph describes another, simpler relay board (pictured), that also frustrated him as the manufacturer apparently had not included the necessary pull-up resistors on the Chip Enable and on GPIO0 and GPIO2. (Edit: this turned out not to be entirely true as the board comes with an ESP8266-01S that has the necessary pullups on board)

Both videos came in my focus again, when i discussed the ‘simpler’ board with a diy mate and frequent commenter. It is very cheap to buy and once you add the resistors (to make it start up correctly) factually you have a Sonoff SV.
Ofcourse the Sonoff SV is less than 5 Euro (plus shipping), as opposed to the ‘brandless’ relay board only costing some 2.60 euro, so you might as well get the real thing, but it opens some interesting perspectives, especially as I had most of the stuff laying around namely an ESP8266-01 a relay module and a 3.3Volt power module, all fairly cheap. Just a couple of DuPont cables to connect the three, and it should be fine. I know it is all nickles & dimes stuff but lets do a quick calculation.

Total 2.08 euro as opposed to 2.62 euro (in a nicer package), so not really cost effective to ‘DIY’  but if you have the stuff laying around, better to use it than for it gather dust. It also allows you to choose another pin than GPIO2 to drive the relay.
Ralph also offers a program to replace the existing firmware in the ESP8266, as well as a phone app (all found in the description of his video). Ofcourse it is also possible to replace the firmware with MQTT responsive firmware. For that you could e.g. use my Sonoff Touch program, albeit that in line 17, you have to change “TouchLED=12;”  to “TouchLED=2;

But why stop there? the ESP8266-01 has 4 I/O pins, if we ad a small 220->5V power module and a 4 channel relay board, we could make a sonoff 4ch. These cost about 22 Euro. So that would be more rewarding to build.
That however will be for part 2.

44 thoughts on “Simple WiFi relay board (1): an overview of two popular modules on Chinese Websites”

  1. After playing with the second type of relay board (the one without the STM controller), I can confidently say it is a great idea, with slightly lousy execution. Lack of pull-ups is actually not a problem as the board is shipped with the ESP-01S indeed, which has it’s own pull-ups.

    The problems, in sequence of mild to severe are:
    – relay driver pin is GPIO0 different than on the Sonoff SV
    – button is wired to RST. A GPIO would be nicer
    – GPIO is pulled down by the relay driver. The ESP won’t even boot!

    To tackle all, I made the following modifications on the relay PCB:
    – remove the 2K pull down resistor
    – cut the PCB tracks going to the button and the relay driver
    – re-wired the button to GPIO0 and the relay driver to GPIO2 using thin coil winding wire.

    The only downside is that the relay is ON during boot. A side effect of the new Tasmota configuration is that the LED on the ESP01S shows the inverse of the on-off state.

    All in all, way too much work to save 2-3 euro. In my defense, I only needed a spare ESP01 but was intrigued by the relay board. It was less than a euro more expensive than the bare ESP01.

    1. Thanks for your concise review. I haven’t received the board yet but I would guess that it might be possible to reroute the relay fet to the Rx or Tx pin (and ofcourse remove the 2k resistor). That way you could pull that pin down and and avoid the problem.

      Indeed, not a straight forward board for the novice. but the ESP8266-01S is surely an interesting development. I am tempted to get a few for ‘small jobs’
      I would guess though that if you want a ready, no fuss relay board, the SonOff SV is a better choice at around 2-3 euro higher price
      No need to ‘defend’ yourself: I for instance dont need the board at all, just was intrigued by it 🙂

      1. Claudio, thank you for yr reply but Amr Ali is referring to a different relay module as none of the two mentioned here (or the one on instructables) has an optocoupler

  2. 4way variant:
    Open relay 1: A0 01 01 A2
    Close relay 1: A0 01 00 A1
    Open relay 2: A0 02 01 A3
    Close relay 2: A0 02 00 A2
    Open relay 3: A0 03 01 A4
    Close relay 3: A0 03 00 A3
    Open relay 4: A0 04 01 A5
    Close relay 4: A0 04 00 A4

      1. HI,

        I bought this one 12V 4-CH ESP8266 WIFI Relay from https://www.ebay.co.uk/itm/ESP8266-APP-Controled-Smart-Home-Automation-WiFi-Wireless-Switch-Relay-Module-UK/202481485564?_trkparms=aid%3D111001%26algo%3DREC.SEED%26ao%3D1%26asc%3D20160908105057%26meid%3D3c309f45d8c449f2b41db5a55b5170ec%26pid%3D100675%26rk%3D1%26rkt%3D15%26sd%3D202481485564%26itm%3D202481485564&_trksid=p2481888.c100675.m4236&_trkparms=pageci%3Af794bfd1-4838-11e9-aa08-74dbd180bfc4%7Cparentrq%3A8892bd9e1690a9cae90f16c1fff87065%7Ciid%3A1. It works via preconfigured esp8266 which was included. I hope, that I will use your ino file and it will work. But it doesnt work. I tried to change HEXs for relays. It looks like, that cmd via serial port is not send (wrong pin?). I really dont know.

        Please, do you have some hints?

      2. I never worked with that module. Do I understand correctly that you had a working ESP8266-01 but that you reflashed it? Hmm that is slightly unwise as one never knows of the same pins are used.
        In this case it is even worse because as far as I know, that relayboard has a seperate chip (possibly the STC15F104) that operates the relays am I correct? and it is connected to the ESP8266 via its serial port I seem to remember.
        My program is made to directly control the relays, not to control that seperate chip.
        So it is going to be quite a job to find out how you must control the ESP8266 in order to control the STC15f04 chip.

        However, try to put the following test program in your ESP8266
        // Turn ON Command
        byte ReON[]={0xA0,0x01,0x01,0xA2};

        // Turn Off Command
        byte ReOFF[]={0xA0,0x01,0x00,0xA1};

        void setup() {
        Serial.begin(9600);
        delay(500);
        }

        void loop() {

        // Turn ON the relay for 1 Second
        Serial.write(ReON, sizeof(ReON));
        delay(1000);

        // Turn OFF the relay for 2 Seconds
        Serial.write(ReOFF, sizeof(ReOFF));
        delay(2000);
        }

  3. hi,

    I used different esp8266 chip (better make backup firstly).

    And I tried to analyse comunnication between esp8266 and the second chip STC15F104. There is also some log information on rxtx board pins:
    —————————–
    Ai-Thinker’ ‘Technology’ ‘Co.’ ‘Ltd.

    ready
    WIFI’ ‘CONNECTED
    AT+CWMODE=1\r

    OK
    AT+RST\r

    OK
    WIFI’ ‘DISCONNECT
    —————————–
    I used logic analyzer and this is output. Esp8266 send theses bytes to STC chip.
    RELAY 1:
    0x0D 0x0A 0x2B 0x49 0x50 0x44 0x2C 0x30 0x2C 0x34 0x3A 0xA0 0x01 0x00 0xA1 ON 1
    0x0D 0x0A 0x2B 0x49 0x50 0x44 0x2C 0x30 0x2C 0x34 0x3A 0xA0 0x01 0x01 0xA2 OFF 1

    RELAY2:
    0x0D 0x0A 0x2B 0x49 0x50 0x44 0x2C 0x30 0x2C 0x34 0x3A 0xA0 0x02 0x01 0xA3 ON 2
    0x0D 0x0A 0x2B 0x49 0x50 0x44 0x2C 0x30 0x2C 0x34 0x3A 0xA0 0x02 0x00 0xA2 OFF 2

    there is pretty different prefix: (not sure why)
    0x0D 0x0A 0x2B 0x49 0x50 0x44 0x2C 0x30 0x2C 0x34 0x3A

    I will try to make simple program with theses buffers.

    with best regards, jiri

    1. Yes, I will fix the necessay link when I get home.
      You can create a socket with socket_create, open it with socket_connect and write with socket_write. socket_write documentation on php.net

    2. can you please share the firmware code you’ve used to make the esp8266-01 module working with your app. That would help us a lot.

       Thank you.

      1. Nandeep, Mohammed’s comment is from 2019. Not sure if he will read yr request. I hope so. The firmware you are asking to share would probably be very app dedicated so i am not quite sureif the one is good without the other

      2. Thank you Mr. E for your humble response. The thing is I have my own app developed to operate firmwares and its been using with other ESP32 and ESP8266 modules. The problem is that I’m not able to know how to trigger the relays of the ESP-01 4 relay module.

        The supplier provided nothing other than the following:
        Open relay 1: A0 01 01 A2
        Close relay 1: A0 01 00 A1
        Open relay 2: A0 02 01 A3
        Close relay 2: A0 02 00 A2
        Open relay 3: A0 03 01 A4
        Close relay 3: A0 03 00 A3
        Open relay 4: A0 04 01 A5
        Close relay 4: A0 04 00 A4

        I have the data to send to the ESP-01 but dont know how to send it to trigger the Relays.

        I will be thanful to anyone who provides the useful data to me regarding my request.

        Thank you.

      3. It has been a while since i looked at that particular relay. I’ll look into it again. I seem to remember though that the codes you mentioned is what the ESP has to send to the other mcu (the STC15F104.) on this board, via de serial port. I do not know what exactly your app does, but you need to make sure that yr app connects to the esp and that your esp can receive 8 codes from your app, it then has to translate these codes into the codes you mentioned above and sends them to the serial port.The code in the ESP therefore is not really the problem, just need to know what your app does.
        So what does your app do? does it make http requests? or TCP? if so, suppose yr app can make an http request or a TCP connectionto a specific IP nr and then you can send a code between 1 and 8. Then you have to program your esp such that it connects to wifi and can receive http requests/ has TCP connection. When it receives say a ‘1’ then that is a sign for your esp to send the ‘relay 1 ON’ code to the serial port. if it receives code ‘2’, it has to send the ‘relay 1 OFF’ code to the serial port, etcetera

      4. Yes, my app can make http requests and that request sends some data to the MQTT broker and that MQTT will communicate with the ESP.

      5. Yes, my app can make http requests and that request sends some data to the MQTT broker and that MQTT will communicate with the ESP.

      6. Yes, my app can make http requests and that request sends some data to the MQTT broker and that MQTT will communicate with the ESP.

      7. Yes, my app can make http requests and that request sends some data to the MQTT broker and that MQTT will communicate with the ESP.

      8. What i need to know is how to turn ON/OFF the relays in a loop from time to time using delays in between without any conditionby using the Serial Port like you’ve said or somehow. If i came to know this, then i can use it conditionally like when something is received to the ESP.
        Thankyou.

      9. But that is in fact quite simple:
        Switch relay on command
        delay(time in msec)
        Switch other relay on
        delay(time in msec)
        Etc
        Put that in your loop and they will be switching on (or off)
        That said, it might not be wise to have yr loop lie in wait most of the time, better to set a timer and count time passed

      10. I need that Switch relay on and off commands. I’ve already tried the following:

        // Turn ON Command
        byte ReON[]={0xA0,0x01,0x01,0xA2};

        // Turn Off Command
        byte ReOFF[]={0xA0,0x01,0x00,0xA1};

        void setup() {
        Serial.begin(9600);
        delay(500);
        }

        void loop() {

        // Turn ON the relay for 1 Second
        Serial.write(ReON, sizeof(ReON));
        delay(1000);

        // Turn OFF the relay for 2 Seconds
        Serial.write(ReOFF, sizeof(ReOFF));
        delay(2000);
        }

        and also tried many other ways. Nothing worked out.

      11. If you got the 4 way relay modulevthat you think i have, those would be the proper comnands. Have you tried just sending 1 command rather than 2

      12. Yes, I’ve sent one command rather than 2. But no response from the relay.

      13. Well, we do know the board is working, as the manufacturers app is ok, so at least we know what to focus on. Anyway, i will wait for the chipnumber and take it from there

      14. Right next to the big capacitor is a chip. Can you tell me the name of that chip?

      15. There is nothing printed on thae chip that i’ve provided.

        when i look into the board’s internal circuit diagram i came to know the name of it as STM8S103F.

      16. Not the chip i expected but it night be a drop in. Did you try the program i sent?

      17. Yes, I’ve tried the program you’ve sent.
        #include
        // UART settingsconst int baudRate = 9600; // Baud rate for serial communication
        void setup() {// Initialize the serial communication with the specified baud rateSerial.begin(baudRate);}
        void loop() {// Send the first set of UART codesbyte code1[] = {0xA0, 0x01, 0x00, 0xA1};Serial.write(code1, sizeof(code1));
        // Wait for 1 seconddelay(1000);
        // Send the second set of UART codesbyte code2[] = {0xA0, 0x01, 0x01, 0xA2};Serial.write(code2, sizeof(code2));
        // Wait for another 1 second before the loop restartsdelay(1000);}
        But, I didn’t find any triggers in the relays.

      18. I start to think your STM chip expects other commands then. Niw let me get this straight: you said that the manufacturer provided app worked, so you must have had a program for your esp8266 that actually worked. What codes does that one send to the STM chip?
        For now tey setting the baudrate to 115200 bps and try my program again.
        Send this to the TX pin using the UART 115200 bps:
        Relay 1 ON: 0xA0, 0x01, 0x01, 0xA2
        Relay 1 OFF: 0xA0, 0x01, 0x00, 0xA1
        Relay 2 ON: 0xA0, 0x02, 0x01, 0xA3
        Relay 2 OFF: 0xA0, 0x02, 0x00, 0xA2
        Relay 3 ON: 0xA0, 0x03, 0x01, 0xA4
        Relay 3 OFF: 0xA0, 0x03, 0x00, 0xA3
        Relay 4 ON: 0xA0, 0x04, 0x01, 0xA5
        Relay 4 OFF: 0xA0, 0x04, 0x00, 0xA4

        so for now:
        #include <Arduino.h>

        // UART settings
        const int baudRate = 115200; // Baud rate for serial communication

        void setup() {
        // Initialize the serial communication with the specified baud rate
        Serial.begin(baudRate);
        }

        void loop() {
        // Send the first set of UART codes
        byte code1[] = {0xA0, 0x01, 0x00, 0xA1};
        Serial.write(code1, sizeof(code1));

        // Wait for 1 second
        delay(1000);

        // Send the second set of UART codes
        byte code2[] = {0xA0, 0x01, 0x01, 0xA2};
        Serial.write(code2, sizeof(code2));
        delay(500)
        // try diferent codes:
        byte code3[]={0xA0, 0x04, 0x01, 0xA5};
        Serial.write(code3,sizeof(code3));
        delay(500);
        byte code4[]={0xA0, 0x04, 0x00, 0xA4};
        Serial.write(code3,sizeof(code4));

        // Wait for another 1 second before the loop restarts
        delay(1000);
        }

      19. I’ve tried by mentioning the baud-rate as 115200 for all commands but none of them got any response from the relay.

      20. What about the program that responded to the commercial app. That should tell you what the commands are

      21. They just uploaded the code into the ESP and provided the device. They did not give their code separately to flash it again. They provided just these commands:

        Relay 1 ON: 0xA0, 0x01, 0x01, 0xA2
        Relay 1 OFF: 0xA0, 0x01, 0x00, 0xA1
        Relay 2 ON: 0xA0, 0x02, 0x01, 0xA3
        Relay 2 OFF: 0xA0, 0x02, 0x00, 0xA2
        Relay 3 ON: 0xA0, 0x03, 0x01, 0xA4
        Relay 3 OFF: 0xA0, 0x03, 0x00, 0xA3
        Relay 4 ON: 0xA0, 0x04, 0x01, 0xA5
        Relay 4 OFF: 0xA0, 0x04, 0x00, 0xA4

        conclusively, there is no particular raw code provided by those suppliers.

      22. Sure, but if you upload that code and leave the esp attached to your serial port, use the suppliers app, you should see the proper codes appear in your serial monitor

      23. There us no data printing in the serial monitor in their code.

      24. You may want to look into the Esp_touchDemo app. If you bought he relay with an accompanying ESP8266, chances are it is already configured correctly and the esp_touch app shuld be able to control it

      25. I’ve looked into some app provided by the suppliers from whom i’ve purchased the module.
        Yes, it controls, but i dont have any code to control it on my own with my own mobile app conditionally which i needed the most.

      26. If the manufacturers app controls it, then your relay board is working, so the problem indeed must be in your program.

        Try this:
        #include <Arduino.h>

        // UART settings
        const int baudRate = 9600; // Baud rate for serial communication

        void setup() {
        // Initialize the serial communication with the specified baud rate
        Serial.begin(baudRate);
        }

        void loop() {
        // Send the first set of UART codes
        byte code1[] = {0xA0, 0x01, 0x00, 0xA1};
        Serial.write(code1, sizeof(code1));

        // Wait for 1 second
        delay(1000);

        // Send the second set of UART codes
        byte code2[] = {0xA0, 0x01, 0x01, 0xA2};
        Serial.write(code2, sizeof(code2));

        // Wait for another 1 second before the loop restarts
        delay(1000);
        }

  4. Is there a data packet that would send actual state of STC chip back to ESP? I assume my program may keep some variable but I want to be sure if relay is open or closed really.

    1. Not that i know of. For that youvwould need to reprogram the STC chip and reprogram the ESP. Given that it is an overengineered board to begin with, it would be simpler to get the simpler board with just the esp8266 and let that handle driving the relay and provide the feedback you require

Leave a reply to Jiří Svatoš Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.