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
$7.9
$7.04
ESP8266 Network Relay WIFI ModuleESP8266 Network Relay WIFI Module
$7.19
$7.25

 

  • ESP8266 WiFi module
ESP8266 ESP-01 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-01 Serial WIFI Wireless Transceiver Module
$2.11
$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.06
$1.75
ESP8266 ESP-05 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-05 Serial WIFI Wireless Transceiver Module
$1.88
ESP8266 ESP-07 Serial WIFI Wireless Transceiver ModuleESP8266 ESP-07 Serial WIFI Wireless Transceiver Module
$2.18
$1.88
ESP8266 Lua Nodemcu WIFI Network Development BoardESP8266 Lua Nodemcu WIFI Network Development Board
$7.43
$2.65

 

  • Solid State Relay 2A 240V

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

 

  • 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.85

 

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

 

  • NPN Transistor TO-92 2N2222
100Pcs NPN Transistor TO-92 2N2222100Pcs NPN Transistor TO-92 2N2222
$1.01
$0.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.36
$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.88
$5.50

 

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   

#31 profile 2018-11-01 16:59
Need cheap hosting? Try webhosting1st, just $10 for an year.

#30 Foad 2017-07-16 09:53
Quoting Parminder Singh:
Quoting Andrea:
in debug mode, on the serial monitor, after the message "create module: /NewModule" the program stops. I find the new module in the app but is not configured. Someone can help me?

having same problem....
esp module crashing as well.. tried almost everything.. any help?


I faced the same issue
+1 #29 Parminder Singh 2017-07-16 03:43
Quoting Andrea:
in debug mode, on the serial monitor, after the message "create module: /NewModule" the program stops. I find the new module in the app but is not configured. Someone can help me?

having same problem....
esp module crashing as well.. tried almost everything.. any help?
#28 Andrea 2017-06-07 00:38
in debug mode, on the serial monitor, after the message "create module: /NewModule" the program stops. I find the new module in the app but is not configured. Someone can help me?
#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 ?

You have no rights to post comments

Forum latest

  • No posts to display.