Introduction: ESP8266 WiFi Relay Switch
In this tutorial we will show how to build ESP8266 WiFi relay switch with Arduino and EasyIoT server. You can use relay switch to remotely (computer or mobile smartphone) control your devices like light, heater, garage door,... You can also combine relay switch with other sensors like temperature, humidity...
EasyIoT server supports secure SSL connection - ESP8266 does not.
There is also EasyIoT Cloud internet controlled switch tutorial:
See more tutorials at http://iot-playground.com/build
Step 1: Materials
ESP8266 WiFi module
Arduino Pro Mini 8Mhz, 3.3V
5V Relay module
NPN transistor 2N2222
resistor 5K1
AMS1117 3.3V regulator
1000uF capacitor
EasyIoT server ( Raspberry Pi or Windows machine)
WiFi network (WiFi router)
Buying guide for materials:
http://iot-playground.com/blog/2-uncategorised/16-esp8266-wifi-relay-switch
Step 2: Build ESP8266 WiFI Relay Node
Be sure to use ESP8266 V0.9.9.2 firmvare available here.
Connect Arduino Pro Mini 8Mhz 3.3V and ESP8266 module.
VCC 3.3 V to Arduino pro mini
VCC 3.3V to ESP8266 VCC module
VCC 3.3V to CH_PHD pin on ESP8266 module
connect GND on Arduino, ESP8266 and power supply GND
connect pin 3 on Arduino to pin RST pin on ESP8266
connect pin 10 on Arduino to pin UTXD pin on ESP8266
connect pin 11 on Arduino to pin URXD pin on ESP8266
Connect relay module to Arduino
Because relay module uses 5V we must connect relay VCC to 5V power supply. Between Arduino pin and relay IN we add resistor and 2N2222 tranzistor. In our example code we use Arduino pin 13, but you can use any free digital Arduino pin or more pins if you are using more relays. See datasheet for details.
After connecting wires program Arduino with ESP8266 WiFi relay switch example available on GitHub. Don't forget to set correct access point and password and EasyIoT server IP address in Esp8266EasyIoTConfig.h.
Step 3: Build EasyIoT Server
Raspberry Pi EasyIoT server: Download latest version of EasyIoT server image and write it to SD card. Put SD card in Raspberry Pi and switch it on. Windows users can write EasyIoT server image to SD card with Win32 Disk Imager.
Or if you are using Windows machine: just download latest release of EasyIoT server win release and unzip it to Windows machine. Run EasyIoT.exe under administrator privileges.
Step 4: Add ESP8266 Relay Switch to EasyIoT Server
On computer enter Raspberry Pi IP address in browser. After login with username admin and password test go to Configuration->Drivers->ESP8266 EasyIoT Driver and enable driver. Press button Add node and switch on ESP8266 relay node. After 15s you should see newly added node (no timeout message). Then add new module to groups and modules to see it on front page.
Step 5: Control ESP8266 WiFi Switch
In web browser go to front page and find newly added module. Click on module and test relay switch.
Check also ESP8266 only internet connected switch:
https://www.instructables.com/id/ESP8266-5-internet...
See also other ESP8266 tutorials.
12 Comments
6 years ago
well done! that really great post. I really enjoyed while reading. good going and keep working. we also use usb relay board for lighting purpose.
8 years ago on Introduction
Why do you use an arduino, with NodeMCU firmware, the ESP8266 can manage this task standalone. In this Blog http://blog.quindorian.org/2014/12/esp8266-wifi-le... someone describes howto switch and dim 2 led stripes. I think this is a good starting point.
Reply 8 years ago
I was about to say the same ;)
The esp is a million times more powerfull than the overrated 'duino.
You can easily clock the esp to over 100MHz and it is a 32-bit RISC cpu compared to the 'duinos 8-bit risc cpu @ 8mhz.
Using nodeMCU the esp does support ssl!
8 years ago on Introduction
good job
8 years ago on Introduction
Hello,
I would love to succed in this project, but I cant!! Please help me :)
cannot succeed to make this working...
In one computer (pc1) I have easyIoT running, and also an ad hoc access point called reso1, without password or encryption, a totally open ad hoc wifi network.
when I run ipconfig, in pc1, i got: ipv4 adress 10.188.242.111, so in Esp8266EasyIoTConfig.h I have this:
#ifndef EasyIoTEspConfig_h
#define EasyIoTEspConfig_h
#define AP_SSID"reso1" //ACCESS POINT ID
#define AP_PASSWORD "" //ACCES POINT password
#define SERVER_IP"10.188.242.111" //EasyIoT server IP address
//#define SERVER_IP"192.168.1.5" //EasyIoT server IP address
#define SERVER_PORT"37602" //EasyIoT server port
#define DEBUG
#endif
Meanwhile , PC2 is running is connected to arduino and running the serial monitor, error in the serial monitor is:
Request node ID
FAIL
Response error
Thank you very much for your help :)
Reply 8 years ago on Introduction
Response: Request node ID FAIL Response error means, that you do not get ID from server. Did you press button Add node in web interface? You get new id from server only if you press button Add node.
If you have more questions please join forum on our website http://iot-playground.com/ for quicker response.
8 years ago
Great work, thanks to share.
Could you advise, please, what to use (type of power supply,...) to connect the espe8266/arduino/relay to 220v or 110v?
Thanks a lot,
Reply 8 years ago on Introduction
I'm using phone charger. You can get it on ebay for 1 or 2 USD.
8 years ago
Great project. Just a thought but as i undestand it the esp8266 has 2 (or more depending on version) gpio pins of its own. Would it not be possible to drive the transistor circuit directly without the need or expense of using an arduino at all? Same goes for digital sensors but obviuosly not analog ones as the 8266 doesnt support that. Could save considerable cost?
Reply 8 years ago on Introduction
Yes it's possible without Arduino. Here is example how to do it:
http://iot-playground.com/forum/suggestion-box/93-add-tcp-relay-node-esp8266-only-needed?start=6#619
8 years ago on Introduction
"EasyIoT server supports secure SSL connection - ESP8266 does not."
What does this mean in practice?
That its completely SSL because of your service?
Or that it's not end to end SSL because of the ESP8266?
Thanks in advance!
Reply 8 years ago on Introduction
Communication without SSL is problematic on internet, because every body can see your communication. It also means that it can control your devices in case of relay switch. On internal network (home network) this is not so problematic.
So EasyIoT server is usually connected on your home network and also all ESP8266 devices. Communication to outside world (internet) goes trough EasyIoT server and secure SSL connection and nobody can see your communication and control your devices.