Introduction: LinkNode R4: Arduino-compatible WiFi Relay Controller Powered by LinkSpriteIO

About: Let's play together! All about pcDuino,Arduino,Raspberry pi and technology. My facebook :Sherry Wu

LinkNode R4 is a WiFi relay controller and it is powered by ESP-12f ESP8266 WiFi module
which is comptiable with Arduino programming. There are 4 relay channels and each channel allows you to control high-power devices (up to 10 A) via the on-board relay. LinkNode R4 can be used to remotely turn lights, fans and other devices on/off. The WiFi interface will allow you to associate the board with your existing WiFi network and send the commands over the network.

Step 1: Control Logic

ESP8266 Pin
Control Signal Relays’status Indicator LED

GPIO12 0 S3 off D6 off

GPIO12 1 S3 on D6 on

GPIO13 0 S4 off D7 off

GPIO13 1 S4 on D7 on

GPIO14 0 S2 off D8 off

GPIO14 1 S2 on D8 on

GPIO16 0 S1 off D9 off

GPIO16 1 S1 on D9 on

Step 2: Software

Arduino IDE, (the latest version is 1.6.8 )The Arduino core for LinkNode R4 ** Hardware**

12V/1A-15V/1A DC power is recommanded.USB TTL UART cable The following section will tell you how to remotely control the LinkNode R4 with Arduino programming and IoT platform.

Step 3: Tutorial

LinkSprite IO
is an IoT platform which supports RESTful API and WebSocket. These make the mobile APP, website application or device connect it very easily. The following I will introduce is about how to use LinkNode R4 to communicate with LinkSprite IO platform.

1. Create a new account and device on

Go to and sign upEnter your Email and password to create a new accountGo to My Account to get your own API Key. The API Key is fatal because only add the Key in your codes, can the data sync to your IoTgo account.

Click My Device, and choose Create DIY Device.

2. Install Arduino core for ESP8266
Install Arduino 1.6.8 from the Arduino website.Start Arduino and go to File –> Preferences .Enter into Additional Board Manager URLsfield. You can add multiple URLs, separating them with commas.

Open Boards Manager from Tools –> Board menu –> Boards Manager.

Search and install esp8266 platform (and don’t forget to select your ESP8266 board from Tools –> Board menu after installation).

Check the configuration of Board
Because the LinkNode R4 has not been added into the offcial ESP8266 Arduino core repository yet, so you can’t find this board on the boards list, but you can use the Generic ESP8266 Module, and select Flash Mode as QIO.

3. Install WiFi Manager library
To make it more convinent, we add WiFi manager library in this demo.

The ESP8266 WiFi Connection manager with web captive portal, this Arduino library can make configure AP’s SSID and password via web page when you want LinkNode R4 to connect to AP.

Open Arduino IDE and go to Sketch –> Include Library –> Manage LibrariesSearch the wifimanager and install it

4. Develope source code
Device API which the LinkSprite IO support is JSON-based, which means all request and response data is enclosed in JSON format. Currently it supports 3 kind of request.

Update: Update device status to LinkSprite IOQuery: Get device status from LinkSprite IO This demo will send http POST request to query the param–light on, if the light is on, then turn one relay on, if off, then turn off the relay.

Enter the following source codeConfigure your apikey and deviceID in the source code



#include //the library are needed for autoconfig WiFi #include #include #include // replace with your own API key and device ID, String apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; const char* deviceID="xxxxxxxxxxxxx"; const char* server = ""; WiFiClient client; void setup() { Serial.begin(115200); pinMode(12, OUTPUT); WiFiManager wifiManager; wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); wifiManager.autoConnect("LinkNodeAP"); Serial.print("WiFi Connected ...\n"); Serial.println("WiFi connected"); } void loop() { if (client.connect(server,80)) { String postStr ="{"; postStr +="\"action\":\"query\","; postStr +="\"apikey\":\""; postStr += apikey; postStr +="\","; postStr +="\"deviceid\":\""; postStr += deviceID; postStr +="\","; postStr += "\"params\":"; postStr += "["; postStr += "\"light\""; postStr +="]"; postStr +="}"; client.print("POST /api/http HTTP/1.1\n"); client.print("Host: "); client.print(server); client.print("\nContent-Type: application/json\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); } delay(1000); Serial.println("Store response..."); String request = ""; while (client.available()) { char c =; request +=c; } if (request!= NULL) { int index1 = request.indexOf(":{"); int index2 = request.indexOf("},"); String param = request.substring(index1, index2 + 1); Serial.print("The param is "); Serial.println(param); if(param.indexOf("off")>0){ digitalWrite(12, LOW); Serial.println("OFF"); } else if(param.indexOf("on")>0){ digitalWrite(12, HIGH); Serial.println("ON"); } client.stop(); Serial.println("Waiting..."); delay(2000); }

Step 4: 5. Test

Jump out the S5 on LinkNode R4 and select program via UARTConnect DC power to LinkNode R4Connect USB TTL UART cable to UART port of LinkNode R4Connnect the other side to PCCheck your serial port which your PC recognizeClick the **Upload* on Arduino IDEAfter finished, jump out the S5 on LinkNode R4 and select boot from flash
Configure to accece WiFi AP

Take the step above to upload the program, the LinkNode R4 will create a AP called LinkNodeAPUse your mobile phone to connect this APOpen a browser and enter the ip address and you will see the following website:

Click the button configure WiFiSelect your WiFi AP which you want to connect and enter your wifi password.If connecting failed, you can go to the same website to configure it again.Also, you can use Serial Monitor in Arduino IDE to check the status.After that, LinkNode R4 will connect to Linksprite IO via the internet.
Control on the website

Open the serial monitor to check the status

Open your light device which is create on linksprite.ioClick the button ON and OFFCheck the status of relay on LinkNode R4, is it following your control?

IoT Builders Contest

Participated in the
IoT Builders Contest