In this tutorial we will show how to build WiFi internet controlled switch connected to EasyIoT Cloud. We will use ESP8266, solid state relay and Arduino IDE.

This tutorial is obsolete. Use updated version ESP8266 internet connected switch (EasyIoT Cloud MQTT API V1) - improved.

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 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 ecourage you to play arround!

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

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, to set access point username and password and EasyIoT username and password:

#define AP_SSID     "xxx"

#define AP_PASSWORD "xxx"  

 

#define EIOTCLOUD_USERNAME "xxx"

#define EIOTCLOUD_PASSWORD "xxx"

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 Cloud interface

ESP8266 internet switch

 

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

This tutorial is obsolete. Use updated version ESP8266 internet connected switch (EasyIoT Cloud MQTT API V1) - improved.

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   

#57 Arumugam 2016-10-26 06:21
Hi,

Its working fine there is no troubles. But I need some modification.

How can I assign 2 GPIO's (GPIO0 and GPIO2) as OUTPUT, hence I don't want local switch
#56 Jarl Even Englund 2016-08-05 01:04
I found the answer. I need to define my own module like in the exaple in the link below:
http://iot-playground.com/blog/2-uncategorised/85-easyiot-cloud-module-configuration
#55 Jarl Even Englund 2016-08-02 22:38
Hi
I'm trying to add a second relay to the ESP8266 module.
My approach is to add a "Sensor.Parameter2" but in the EasyIOT cloud the module only have one on/off switch.
It looks like things are working but I don't understand how I can add the second switch in the EeayIOT cloud (module view)

Some screenshots are attached


#54 kobus 2016-05-18 11:37
Can anyone change the code to use a toggle switch instead?. It would be nice not to change all my light switches in my house
#53 Biser Georgiev 2016-05-17 08:48
Hello,
I have a problem with this sketch.
When I turn ESP8266, I do not add switch to EasyIoT Cloud
Appears my new WIFI network (ESP.XXXX) that blocks my router.
Where can I mistaken?
#52 kobus 2016-04-19 11:08
Would anyone be able to change the sketch to work with a standard light switch (toggle switch)? Would be nice not to replace all the light switches in my house
#51 Franz Maurer 2016-04-06 12:25
Where to buy the switch itself?
Cannot find a clue in the Materials list ...
Please help!
Franz
#50 Tomasz 2016-02-11 18:17
How to change the code to the button does not run the relay? Button in my project must only change the status of the site. It can be done?
#49 Super User 2016-02-11 15:47
Quoting Piotr:
Hi, Im having problems with the stability of the switch i want to use it to turn on/off the small led light. I have already put the PCB in the wall and found out the problem. Next to the IoT "switch" i have another standard wall switch for different light. The situation is that when i turn the different switch on / of the esp is changing the state and switches my led lamp on or of. I found out that the GPIO input used for manual switch is too sensitive. Even touching it with the finger or voltometer probe changes it state.
Any ideas how to modify the circuit to eliminate such disturbances?
What can cause it?
The GPIO is pulled up using 1k resistor.

Please help. If something is unclear i can answer any questions.

I can also share the wiring diagram and pcb layout i created for this project.


Hi, try to add 100nF capacitor parallel with push button to transistor B and ground. I guess this can lower noise. Report if it works.
And please share your PCB.
#48 Piotr 2016-02-11 11:19
Hi, Im having problems with the stability of the switch i want to use it to turn on/off the small led light. I have already put the PCB in the wall and found out the problem. Next to the IoT "switch" i have another standard wall switch for different light. The situation is that when i turn the different switch on / of the esp is changing the state and switches my led lamp on or of. I found out that the GPIO input used for manual switch is too sensitive. Even touching it with the finger or voltometer probe changes it state.
Any ideas how to modify the circuit to eliminate such disturbances?
What can cause it?
The GPIO is pulled up using 1k resistor.

Please help. If something is unclear i can answer any questions.

I can also share the wiring diagram and pcb layout i created for this project.

You have no rights to post comments

Forum latest

  • No posts to display.