ESP8266 - $5 Internet Connected Switch





Introduction: ESP8266 - $5 Internet Connected Switch

In this tutorial we will show how to build WiFi internet connected switch connected to EasyIoT Cloud. We will use ESP8266, solid state relay and Arduino IDE. Switch can be controlled by WEB application, native Android application or button.

Improved version of this switch can be found here:

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

Material for switch cost about 5$.

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.

Step 1: Material


  • ESP8266 WiFi module
  • Solid State Relay 2A 240V
  • 3.3V 600mA AC-DC step down module
  • Push Button switch
  • NPN Transistor TO-92 2N2222
  • 1000uF electrolytic capacitor
  • resistor, 1K, 47K

Click to buying guide for ESP8266 internet connected swith.

Step 2: EasyIoT Cloud Registration

Register to EasyIoT Cloud. You will need username and password later in program. Also use username and password to access EasyIoT Cloud and control your device from computer or mobile phone. Also EasyIoT Cloud Android application is available.

Step 3: 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 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 your EasyIoT Cloud username and password:

#define AP_SSID "xxx"
#define AP_PASSWORD "xxx"



Step 4: 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.

After power on, switch will be automatically added to EasyIoT Cloud and it will be visible in WEB interface or Android application where you can control your device from remote locations.



    • Science of Cooking

      Science of Cooking
    • Trash to Treasure

      Trash to Treasure
    • Paper Contest 2018

      Paper Contest 2018

    We have a be nice policy.
    Please be positive and constructive.




    Where can I get the enclosure? It's not listed in your buying guide.

    How can 3.3V output from ESP8266 trigger 5V relay?

    In my mock up the 3.3 triggers an opto switch that is part of a chinese relay module which allows the 5V to actually operate the relay.

    In this instance it is triggering a transistor as a switch to allow a larger load to operate the relay.

    Sort of like a relay to operate a bigger relay / larger load

    See the link for a little more explanation.

    Great, that makes sense! Thank you for explanation.

    It doesn't make sense, I'm afraid - there are traces of a couple of misunderstandings there. The ESP cannot supply enough current to drive a relay, and that's what you need a driver (e.g. the transistor) for, but in this circuit that does NOT increase the voltage - in fact (again, in THIS circuit) it decreases it. In the circuit as drawn, the relay is going to see a voltage of about 2.7v: it's being powered by a 3.3v supply, and you're going to lose about 0.6v of that across the transistor. Now, perhaps the relay will still work at 2.7v - I haven't tried - though it's not guaranteed. Really you either need a lower voltage relay, or a higher voltage supply for the relay. A supply giving 5v for the relay and 3.3v for the ESP would do nicely.

    Is it possible not to use the automatic registration of parameters?

    and, register manually the parameters!

    // Create Sensor.Parameter1

    #ifdef DEBUG

    Serial.println ( "/" + String (storage.moduleId) + "/Sensor.Parameter1/NewParameter");


    myMqtt.subscribe ( "/" + String (storage.moduleId) + "/Sensor.Parameter1/NewParameter");

    waitOk ();

    Thanks for nice tutorial. How can I use it behind the proxy server ( my institute have proxy server with id and user name)

    Did you solve the proxy problem ? The same condition is in my institute also , I have also contacted various forums but they couldn't solve the problem.

    follow instructions and you will solve your error

    I receive this error .... seems im not the only one?

    ESP MQTT\mqtt\mqtt.c.o:(.bss.default_private_key_len+0x0): multiple definition of `default_private_key_len'

    ESP8266WiFi\WiFiClientSecure.cpp.o:(.bss.default_private_key_len+0x0): first defined here

    ESP MQTT\mqtt\mqtt.c.o:(.bss.default_certificate_len+0x0): multiple definition of `default_certificate_len'

    ESP8266WiFi\WiFiClientSecure.cpp.o:(.bss.default_certificate_len+0x0): first defined here

    collect2.exe: error: ld returned 1 exit status

    Error compiling