Programming the Electrodragon IoT Relay

Introduction: Programming the Electrodragon IoT Relay

I recently bought Electrodragon's IoT Relay ( and was surprised at the ease of use and feature available.


  1. Based on ESP-12F ESP8266 Wifi Board
  2. Supports two relay AC output.
  3. Relays are rated at 250 VAC - 10A, however I have seen concerns from others that the PCB traces may not be thick enough to suppport 10A. Even the site mentions that the R1.1 boards have a "2MM trace width to let 2A current pass through roughly for two relays together, so either 2A for running one channel device or 1A for two devices" They further go on to say that you can add more solder to the existing masks to increase the current capacity. However, I would limit the use of this device to 2A at the most - which is good enough for bulbs, small fans, electronics, etc (~100-200W)
  4. Comes with a plastic case, however the case has to be modified (i.e. cut open) slightly to allow access to both the output relays.

The device comes installed with the AT firmware - which is absolutely of no use, as you are not going to connect this wifi device using a serial adapter all the time. You want to control your device using wifi. The least they could have done was provided a firmware similar to the sonoff module, or at least their demo code. However, with a little bit of hit and trial, I was able to upload a new simple firmware that allows me to control the relay using wifi.

The ElectroDragon site has a wiki for this relay ( - however there are some inaccuracies to the image for the R1.0 board which caused me a few headaches. Also, the demo code and instructions for re-programming assume that you are going to use the LUA language. I haven't even tried to learn LUA, and luckily the ESP8266 boards can be programmed with the Arduino IDE as well - so that's not too big a problem.

Step 1: Setting Up the Software (Arduino IDE)

The latest version of the Arduino IDE has made it easier to program these boards and you no longer have to go through multiple hoops to get it to work with the ESP8266 boards. The steps are as follows:

  1. Download the latest IDE from
  2. Open the IDE and go to Tools -> Boards -> Boards Manager...
  3. Search for ESP8266 and click install (see image above)

That's it - you're ready to program the IoT Relay

Step 2: Connecting the IoT Relay to Your Computer for Programming

This module does not come with a USB interface, so you need to use a USB-TTL module / arduino to handle the USB communication with the computer. You can buy any one of the cheap modules available on ebay ( - all work the same - only caveat being finding the correct drivers so that your computer detects the module.

This is the step that caused the most headache, as the image on the wiki has errors. I have used the image from the wiki, however have provided comments - so that you get it correct.

The connections are pretty simple (once you know which pins to use):

  1. Connect the GND from USB-TTL to the pin marked GND on the image (first pin on the left bottom)
  2. Connect the 3.3V from the USB-TTL to the pin marked VCC on the image (it's the pin above the GND pin)
  3. Connect the RX from the USB-TTL to the pin marked RX on the image (this is opposite of what you would normally expect wherein you connect the RX to the TX pin and vice-versa)
  4. Connect the TX from the USB-TTL to the pin marked TX on the image (this is opposite of what you would normally expect wherein you connect the TX to the RX pin and vice-versa)

The module is now ready to be programmed. Holding down BTN2 (marked as BTN1 on the wiki image) and then plugging the module into the USB port puts it in the programming mode and you can upload the new firmware (keep the BTN2 pressed till the software shows that the firmware has been fully uploaded).

Please note, I have the v1.0 boards and hence cannot vouch for the correctness of the V1.1 diagram on the wiki.

Step 3: The Firmware

As the IoT Relay is based on the ESP8266, there are a whole host of firmwares available for you to use. Some of these include:

  1. Souliss:
  2. ESPEasy:
  3. Blynk:
  4. MQTT:

And many more. There are many instructables already present and you can see them by following this link:

However, I went with the simplest possible solution - and that's to run a simple webserver on the IoT relay itself. This is based on the 'WifiWebServer' example that comes with the ESP8266 library.

Things to note:

  1. Change the wifi SSID and password to your setup
  2. The IoT relay has the two relays connected to GPIO13 and GPIO12

Copy and paste the following code to a new "sketch" in the arduino IDE

#include <ESP8266WiFi.h>

const char* ssid = "SSID";
const char* password = "Password";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {

  // prepare GPIO13
  pinMode(13, OUTPUT);
  digitalWrite(13, 0);
  // prepare GPIO12
  pinMode(12, OUTPUT);
  digitalWrite(12, 0);
  // Connect to WiFi network
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  // Start the server
  Serial.println("Server started");

  // Print the IP address

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
  // Wait until the client sends some data
  Serial.println("new client");
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  // Match the request
  if (req.indexOf("/gpio/1/0") != -1){        // GPIO 13 Low
    client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO 13 is now Low </html>\n");
  else if (req.indexOf("/gpio/1/1") != -1){        // GPIO 13 High
    client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO 13 is now High </html>\n");
  else if (req.indexOf("/gpio/2/0") != -1){        // GPIO 12 Low
    client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO 12 is now Low </html>\n");
  else if (req.indexOf("/gpio/2/1") != -1){        // GPIO 12 High
    client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO 13 is now High </html>\n");
  else {
    Serial.println("invalid request");

  Serial.println("Client disonnected");


Step 4: Uploading the Firmware and Running the Server

To upload the firmware, you need to follow these steps:

  1. Press BTN2 and connect the USB-TTL to the USB port on your computer
  2. Choose Board 'NodeMCU 0.9 (ESP-12 Module)'
  3. Choose the correct port (it came up as COM9 on my system)
  4. Click on the right arrow to compile and upload
  5. Ensure that you keep the BTN2 pressed till the firmware is fully uploaded

In most cases this should work, however if you get an error, disconnect the USB and start from step 1 again.

Once the firmware is uploaded, you're ready to connect the module to AC power (BE VERY CAREFUL WHILE HANDLING AC CURRENT - it is extremely dangerous and potentially fatal). The IoT Relay will not connect to the wifi when it is powered through the USB, as the USB-TTL does not provide enough current.

  1. Disconnect the IoT Relay from the USB-TTL module
  2. Connect the input wires and output wires
  3. Check connections again
  4. Close the case
  5. Plugin the input wires to an AC outlet

The sketch I have provided sends out the IP address of the IoT Relay via serial, however I don't think it's a great idea to connect your USB-TTL alongwith the AC power to the IoT Relay. So the best bet is to go to your router's home page and find the IP address of the IoT Relay.

Now you can switch on / off the relays using the following commands:

http://<ip address>/gpio/1/1 - switch on relay 1
http://<ip address>/gpio/1/0 - switch off relay 1
http://<ip address>/gpio/2/1 - switch on relay 2
http://<ip address>/gpio/2/0 - switch off relay 2

1 Person Made This Project!


  • Big and Small Contest

    Big and Small Contest
  • Game Design: Student Design Challenge

    Game Design: Student Design Challenge
  • Make It Bridge

    Make It Bridge



6 years ago

Nice work.I want to use something similar for my water garden system. Is it possible to ad to the board 2 humidity sensors? I see there btn 1&2. Maybe not very precise readings but at least to get the feeling when sprinklers need to stop. Or is much better to go with a promini and a esp module?


Reply 6 years ago

The headers provide access to the other GPIOs - so you can easily connect sensors using that.


5 years ago

Nice post!
I wonder if anyone can use te pin4, pin5 or pin15?
I want to do a digitalRead from two pins, but can´t work it out. I want to do something like this:
pinMode(15, INPUT);

status = digitalRead(15);

It could be 15, 4 or 5 or whatever. But I cant do a digital read from any pin.

I would apreciate any souggestion!


5 years ago

I like it, I would like to use this to make a reboot or poweron/off remotely , but the relays keeps stuck on high, and if i try turn off, nothing happens, if i change the pin, the relays turn off, but when i try to set it back, it stuck on the high position. any clues?

firmware issue?, i have a lol1n V3


6 years ago

Super and simle. Thank You!


6 years ago

Great tip!

I am uploading the amazing Homie OTA ( Hopefully it will enable me to upgrade over the air and integrate with my hub via MQTT.


Reply 6 years ago

That's real nice - I have updated the code to include the OTA library - it's still very simple, but works for me.