Dual relay control over WiFi for $6 ?

I’m a great fan of the ESP8266 boards, having several running with various sensors. I also enjoy the idea of home automation but have never liked the idea of paying so much for the off the shelf hardware. That all changes when I found this:

Wifi IoT Relay Board Based on ESP8266

You can read the spec yourself but in a nutshell it exposes 2 relay points you can wire two devices into, taking in mains power and outputting it when the relays are activated.

My only problem with the device is the build in firmware and accompanying Android app is all in Chinese (or a rather badly translated English).

Long story short I managed to get this to work with the aRest library (http://arest.io) using an FTDI programmer and Arduino (1.6.8) and this is a quick post to let other people know how I did it (because I couldn’t find anything to help me, maybe I can help others).

  1. The device exposes numerous pins, the pin layout is printed on the underside of the board. You want to wire the FTDI like this: TX <> RX, RX <> TX. Power the board separately off 5v directly on the 5v/G pins. Wire the Ground of the FTDI to the Ground powering the board. Now you’re ready to program it.
  2. Fire up Arduino, use this code:

Simple script exposing relays on WiFi IOT Relay Board sold by ElectroDragon

// Import required libraries
#include <ESP8266WiFi.h>
#include <aREST.h>

// Create aREST instance
aREST rest = aREST();

// WiFi parameters
const char* ssid = "<ssid>";
const char* password = "<pwd>";

// The port to listen for incoming TCP connections
#define LISTEN_PORT 80

// Temperature Pins
#define RELAY_1 13
#define RELAY_2 12

// Create an instance of the server
WiFiServer server(LISTEN_PORT);

// Variables to be exposed to the API
float result = 0;

void setup(void)
//Start Serial
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
// Init variables and expose them to REST API

// Give name and ID to device

// Connect to WiFi
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() {

// Handle REST calls
WiFiClient client = server.available();
if (!client) {
while (!client.available()) {



  • Next, make sure your copy of Arduino is capable of burning to ESP boards, look at these instructions: https://github.com/esp8266/Arduino
  • Make sure you have the aRest libraries (see https://github.com/marcoschwartz/aREST) and the ESP8266WiFi libraries (see https://github.com/ekstrand/ESP8266wifi)
  • Before burning the firmware, on the board you’ll notice 2 switches below the relays, you need to use BTN2 to put the board into the correct mode to accept the new firmware by unplugging power, pushing and holding in BTN2, repowering the device and letting BTN2 go , see instructions here: http://www.electrodragon.com/w/ESP_Relay_Board.
  • Burn the firmware from Arduino, use the board starting with NodeMCU 0.9…..
  • Once it’s written, you should be able to pick up the board on your network and access the pins to toggle them with http://ip/digital/<pin>/<1 or 0> eg. turns on relay on pin 13

That’s it, dual relays over wifi for $6

Please note I take no responsibility with what you do with this device, mains power should always be respected. I haven’t actually USED this device other than to get it powered (from mains) and switching the relay, so I know it works. The one thing that concerns me is the lack of earthing wire, and I’m not sure if that’s an issue, someone more knowledgeable should answer that (hint hint)

Leave a comment

Your comment