In this tutorial we will show how to build WiFi internet controlled switch connected to EasyIoT Cloud. This tutorial is improved version of ESP8266 internet connected switch. We will use ESP8266, solid state relay and Arduino IDE. AP can be configured in WEB interface.

This internet controlled switch uses few components and it's connected to EasyIoT Cloud. You can control your devices on computer in EasyIoT Cloud WEB interface or with native Android application. Internet controlled switch is connected to internet with WiFi connection. Switch can also be controlled locally with push button. 

This tutorial is improved version of ESP8266 internet connected switch. It works with latest version of EasyIoT Cloud MQTT broker. Two main improvements regarding previous version of switch are that this uses switch information to update state of UI interface. If connection to switch is broken, then state in UI will not update. Next improvement is that in this switch you can configure AP username and password with mobile phone or computer.

This internet switch is "plug and play" - it will automatically set all EasyIoT Cloud settings, so no configuration in EasyIoT Cloud is needed. 

WARNING!! You will play with LIVE MAINS!! Deadly zone!!

If you don't have any experience and are not qualified for working with MAINS power I will not encourage you to play around!

Do NOT use it without proper Knowledge about MAINS circuits !

Do NOT use it without a proper FUSE on MAINS line!

Max current for solid state in this tutorial is 2A - suitable for room light only. 

 

Contents

1. Introduction

2. Materials

3. EasyIoT Cloud configuration 

4. Program

5. Hardware

5. Configuring ESP8266 Internet switch

6. Buying guide

 

Introduction

 

ESP8266 internet switch

Finished ESP8266 internet controlled switch

 

Materials

  • ESP8266 WiFi relay module
ESP8266 Wifi Relay ModuleESP8266 Wifi Relay Module
$8.64
$7.61
ESP8266 Network Relay WIFI ModuleESP8266 Network Relay WIFI Module
$5.03

 

  • ESP8266 WiFi module
ESP8266 ESP-01 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-01 Serial WIFI Wireless Transceiver Module
$2.45
$17.00
ESP8266 ESP-03 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-03 Serial WIFI Wireless Transceiver Module
$2.07
$2.15
ESP8266 ESP-12 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-12 Serial WIFI Wireless Transceiver Module
$2.08
$1.81
ESP8266 ESP-05 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-05 Serial WIFI Wireless Transceiver Module
$1.88
$3.89
ESP8266 ESP-07 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-07 Serial WIFI Wireless Transceiver Module
$2.18
$1.87
ESP8266 Lua Nodemcu WIFI Network Development BoardESP8266 Lua Nodemcu WIFI Network Development Board
$7.43
$2.85

 

  • Solid State Relay 2A 240V

Solid State Relay 2A 240VSolid State Relay 2A 240V
$0.99
 

 

  • 3.3V 600mA AC-DC step down module
3.3V 600mA AC-DC step down module3.3V 600mA AC-DC step down module
$1.99
$1.94

 

  • Push Button switch
10Pcs Push Button switch10Pcs Push Button switch
$1.64
$1.80

 

  • NPN Transistor TO-92 2N2222
100Pcs NPN Transistor TO-92 2N2222100Pcs NPN Transistor TO-92 2N2222
$3.42
$1.90

 

  • Electrolytic capacitor
210Pcs 25 Value 0.1uF-220uF Electrolytic Capacitors Assortment Kit Set210Pcs 25 Value 0.1uF-220uF Electrolytic Capacitors Assortment Kit Set
$3
$6.52
  • Resistor
400X 0.25w 1/4w Metal Film Resistor Pack Kit 1% 20 Value Each 20 Pcs 10 ~ 1M ohm400X 0.25w 1/4w Metal Film Resistor Pack Kit 1% 20 Value Each 20 Pcs 10 ~ 1M ohm
$1.77
$3.99

 

See buying guide at the end of tutorial for details.

EasyIoT Cloud configuration 

No EasyIoT Cloud configuration is needed, just register to EasyIoT Cloud service. You will need username and password to access your internet switch on WEB application or in Android application. Switch will be automatically added to EasyIoT Cloud and will be visible in WEB interface or in Android application after power on.

Program

Program is written in Arduino ESP8266 IDE. See Arduino ESP8266 IDE tutorial how to connect ESP8266 module to computer to upload program. Program can be downloaded from our GitHub. You will also need MQTT client library. Add this library to library folder in Arduino IDE. Program uses EasyIoT Cloud MQTT API.

In program change following lines EasyIoT Cloud username and password:

#define EIOTCLOUD_USERNAME "xxx"

#define EIOTCLOUD_PASSWORD "xxx"

You can also change access point name and password, but this is not necessary. You can later change AP username and password in WEB interface. 

 

At beginning of the program it reads EEPROM settings. Then it tries to connect to AP. If connection to AP is not successful after 10 s switch to AP mode to change configuration. If connection to AP is successful switch checks module ID. If module ID is 0 it means switch is not configured on EasyIoT Cloud. In this case it adds module to EasyIoT Cloud and saves module ID to EEPROM settings. After successful configuration module subscribe to specific topic to listen switch changes.

The easiest way to test program is to use ESP8266 LUA node MCU board. Just connect it to USB port and you can test program. If you use this board you can also uncomment #define DEBUG to see debug messages. Flash button on ESP8266 board will work as button to manually change switch state. Onboard LED displays switch state.

 

Hardware

In our case we use ESP8266 01, but you can use any other type of ESP8266. GPIO2 is connected to NPN transistor to control SSR. Max current for our type of solid state relay is 2A - this is suitable for room light and not for applications which consume more power - for example heater.

For power supply we use 3.3V step down module. It's very important to add 1000uF capacitor to 3.3V power line - in our case switch didn't work if we skip this capacitor.

GPIO0 is connected to push button for local control of internet switch.

 

ESP8266 internet switch schematic 

 

After power on, switch will be automatically added to EasyIoT Cloud and it will be visible in WEB interface or Android application. 

ESP8266 internet switch

Android application

 

You can manually rename name of your switch and group in EasyIoT Cloud configuration to suits your need.

Configuring ESP8266 internet switch

When internet switch is switched on it tries to connect to AP. If after 10 s connection to AP is not successful it will switch in AP mode. With mobile phone search for AP named Thing-xx-xx-xx-xx where xx-xx-xx-xx is random value. Connect to this AP and then in WEB browser address enter 192.168.4.1. In WEB page displayed you can configure AP name and password. After changing AP name and password click submit button and internet switch will reboot and connect to AP.

ESP8266 internet switch configuration

See more tutorials at http://iot-playground.com/build

Buying guide

To support this site and EasyIoT framework development please buy in our store.

 

ESP8266 Wifi Relay Module

ESP8266 Wifi Relay Module Transmission Distance 400m 10A/30V DC For Smart Home

ESP8266 Network Relay WIFI Module

ESP8266 10A 220V Network Relay WIFI Module Input DC 7V~30V

ESP8266 ESP-01 Serial WIFI Wireless Transceiver Module

ESP8266 Serial WIFI Wireless Transceiver Module

ESP8266 ESP-12 Serial WIFI Wireless Transceiver Module

ESP8266 serial Port WIFI wireless module ESP-12

ESP8266 ESP-03 Serial WIFI Wireless Transceiver Module

ESP8266 serial WIFI model ESP-03

ESP8266 ESP-05 Serial WIFI Wireless Transceiver Module

ESP8266 ESP-05 Serial WIFI Wireless Transceiver Module

ESP8266 ESP-07 Serial WIFI Wireless Transceiver Module

ESP8266 with external antenna

ESP8266 Lua Nodemcu WIFI Network Development Board

ESP8266 Lua Nodemcu WIFI Network Development Board

Solid State Relay 2A 240V

G3MB-202P-5VDC DC-AC SSR In 5V DC Out 240V AC 2A Solid State Relay

3.3V 600mA AC-DC step down module

3.3V 600mA AC-DC step down module

10Pcs Push Button switch

10Pcs Push Button switch

100Pcs NPN Transistor TO-92 2N2222

All purpose NPN transistor.

210Pcs 25 Value 0.1uF-220uF Electrolytic Capacitors Assortment Kit Set

400X 0.25w 1/4w Metal Film Resistor Pack Kit 1% 20 Value Each 20 Pcs 10 ~ 1M ohm

 


Comments   

#27 Aleksandar Aleksandrov 2017-02-17 19:38
To fix this problem upload blank_1MB.bin at 0x000000
0x100000
0x200000
addresses
then upload your firmware and the program again
that will clear your ESP from any software problems or change your power supply it must be at least 500mA or 1A with 1000mF capacitor to prevent voltage drops and the last thing is to make sure you have solid connections and short cabels.
#26 Marvin Fuenmayor 2017-02-17 18:21
Quoting Aleksandar Aleksandrov:
Quoting Marvin Fuenmayor:
Hi, I did everything like says in this page, but I culdn't see my esp8266 in the EasyIot. What could be the problem?
Thanks by the way.

Turn ON Debuging and see where your ESP stops


Hi I did that but the problem is the ESP don't run the program. I tried with 2 diferent esp-01, but is the same problem. This is the message that I received on the arduino IDE monitor:
When finished programming the esp-01 this is the message:

ets Jan 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
When I press the reset buton on the esp-01 this is the message:

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

thanks for your help.
#25 Aleksandar Aleksandrov 2017-01-30 19:34
Quoting Marvin Fuenmayor:
Hi, I did everything like says in this page, but I culdn't see my esp8266 in the EasyIot. What could be the problem?
Thanks by the way.

Turn ON Debuging and see where your ESP stops
#24 Kuba 2017-01-30 12:41
Hi Aleksandar,
short and simple "hardware" question - could you give me hint, where can I find (or what should I look for) an electric outlet/socket case, similar (concerning functionality/dimensions) to the one used by you?
Kuba
#23 Marvin Fuenmayor 2017-01-27 20:26
Hi, I did everything like says in this page, but I culdn't see my esp8266 in the EasyIot. What could be the problem?
Thanks by the way.
#22 Bruno 2017-01-22 01:13
Has anyone used EasyIoT server instead of the cloud server ?? What changes are needed in the code ?
+1 #21 Dave Brunner 2016-12-25 05:43
Quoting Adrian:
Can you recommend a Solid State Relay that will work with ESP8266 & U.S. 120V power? Would this work - Omron G3MC-202P-VD DC5

I would think any 100-240VAC relay will work but here is one.
https://www.amazon.com/CJRSLRB-8-channel-Resistive-Duemilanove-Mega2560/dp/B00SGHM3GI/ref=sr_1_1?s=pc&ie=UTF8&qid=1482640934&sr=1-1&keywords=Solid+state+5V+relay+arduino
+1 #20 Dave Brunner 2016-12-25 05:40
Quoting Aleksandar Aleksandrov:
Quoting Steve:
Has anybody modified this project to work with a relay instead of a solid state relay? The similar server (non cloud) project is that way. I would like to control some motors that are larger than 2A.


You can just add a mono phase or 3 phase contactor after the Solid state relay.


I'm using a standard relay w/o a problem. I have GPIO going right to the relay input terminal. My problem is my relay coil is engaged when grounded (LOW) but the GUI
has LOW as off but in my case it's actaully ON.
#19 Dave Brunner 2016-12-25 05:37
Do you know if there is a way to change the switch "Off" status to have GPIO2 HIGH instead of LOW. My relays are switched on w/ a LOW signal. I could use a relay to resolve this but I'm hoping to find a way to do this w/in the sketch. I looked through it and also the web GUI and could not find a way to change the default power on to LOW and off to HIGH.
#18 Aleksandar Aleksandrov 2016-11-22 00:24
Quoting Steve:
Thanks Aleksandar.

How would that work? The SSR is rated for 240 V AC. Most of the relays I have seen have an input voltage of 5 or 7 volts DC. Can the SSR control 5-7 volts DC?


You just need:
SSR (input:5V,output 240V/2A)
Contactor (Xamps ,1phase or 3 phase depent on your motor with control circuit 240V)
Connect:
Wifi Module to SSR (3,3V to 240V/2A)
SSR(240V/2A) to Contactor control coil
Contactor to the motor

You have no rights to post comments