Arduino project

Raspberry project

Post Page Advertisement [Top]

Inherit "DIY wifi light switch" project, I continue making wifi outlet 220V, using arduino ESP12E to control it. "Wifi outlet" is also called as smart power outlet, which is sold a lot on internet.

Let's see result first:

What all we need:
1. ESP12E
2. A normal outlet
3. Power adapter 220V to 6VDC
4. Power module 6VDC to 3.3VDC
1. ESP12E
2. A normal socket
4. Power module 6VDC o 3.3VDC

1. Making wifi communication board

This project uses ESP12E to make wifi communication with house's wifi network. Then, a mobile phone in network can take control ESP12E via local web browser.
Make PCB circuit for ESP12E:

This is my example PCB circuit, very small:

Note that, please prepare good power supply for ESP12E because it will use too much current (around 200mA)

2. Code works:

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
//------------------------------for local web
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

MDNSResponder mdns;
ESP8266WebServer server(80);
String webPage;
//----------------------------for local web

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_PASS_WORD";
int pinout=14;  //for relay
boolean socket_change;

void setup() {
  pinMode(pinout, OUTPUT);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");

  //Authentication password for programming OTA
  ArduinoOTA.setPassword((const char *)"123");

  ArduinoOTA.onStart([]() {
  ArduinoOTA.onEnd([]() {
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  Serial.print("IP address: ");

  //-----------------------------------------add your code here
  webPage += "<center><font size='27'>ESP8266 Web Server<p>Socket #1 ";
  webPage += "<a href=\"socket\"><mark>TOGGLE it</mark></a></p></font></center>";

  if (mdns.begin("esp8266", WiFi.localIP())) 
    Serial.println("MDNS responder started");

  server.on ("/socket", [](){
    server.send(200, "text/html", webPage);
    // Change status
    socket_change = true;
  //-------------------------------------------add your code here

void loop() {
  //-------------------------------------------add your code here
    socket_change = false;
    if(digitalRead(pinout)) digitalWrite(pinout,LOW);
    else digitalWrite(pinout,HIGH);
Compile the code and download into ESP12E.
Please study how to download ESP12E via wifi, it is very useful for next modify and download. Once ESP12E is installed into socket, it is difficult to take it out.

3. Install to normal socket

This socket contains 3 slot. However, 2 slot have to take out to save space for power module and ESP12E PCB
The power module is taken from mobile phone charger adapter. It's good enough for this project.

Place all things into socket.

4. Testing....

Plug socket into power 220V. Plug into it a lamp for test.

Go to web browser, type address, this case is:

Now, click to "TOGGLE it" the light will ON/OFF
By this way, the socket also can be controlled via mobile phone.


  1. Hi, I think you have not listed all components in your "What all we need:" list. I can see relay and some other components also. can you update list of all needed components.

    1. sorry, i just mean about main things. Other small things, they're easy to find with cheap price, and play not so vital role in project.

  2. I very much like your pattern it's beautiful,thank for sharing good i dea !


  3. Informative post. Thanks for sharing.

  4. After reading this blog, I would like to demand more articles again and again. I am feeling myself as satisfy by got to know these all such information which never came to my knowledge. Please writer more.Home theatre power filter

  5. WiFi is the other name for remote web or remote system, this name is generally utilized by none specialized clients who just realizes how to get to web remotely, they know basically nothing past that. router settings


Bottom Ad [Post Page]