Introduction: DIY WiFi Outlet (HariFun#135)

Picture of DIY WiFi Outlet (HariFun#135)

In this instructable, I will take you along on my journey of building this WiFi Outlet.

Step 1: Parts

Picture of Parts

The final box will contain:

  • ESP8266 (any version will do)
  • 5V Relay Module
  • AMS1117 Low Drop Out Regulator
  • 1K Resistor
  • Duplex Outlet
  • Wall Box
  • Wall Plate
  • Cellphone Charger (5V output)
  • Power Cord

Only needed while programming the ESP8266:

  • FTDI Usb to Serial Converter (3.3V version)
  • Some jumper wires

Step 2: WARNING!!!

Picture of WARNING!!!

High voltage definitely would hurt you and potentially could kill you! So please be careful. If you don't know what precautions to take, please find someone who does. You've been warned.

Edit: fellow instructable brought up a good point. Thanks Spark Master!
"I would mention you will probably void any Home Owners Insurance you have if you do this in NYC. Ask the electrical inspectors listed in the phone book for your area."

Step 3: Charger Surgery

Picture of Charger Surgery

I considered just soldering wires to the mains input and use a USB cable for the output. However, in the end I decided to keep all the high voltage inside the charger. A gentle pry with a box cutter popped it open.

I replaced the input wire with a slightly longer wire.

I also removed the USB connector because plugging in a USB cable would have taken more room.

I then put everything back into its original container.

Step 4: High Voltage Wiring

Picture of High Voltage Wiring

I recycled a computer power cable for this project.
Obviously, we want the relay to switch the live wire instead of the neutral.

I opted to break one of the tabs that joins the two outlets. This allowed me to wire up one of the outlets to be always on, while the other outlet is switched by the relay.

Step 5: ESP8266 & Relay Wiring

Picture of ESP8266 & Relay Wiring

The wiring is fairly simple, so I opted to solder everything right around the ESP8266 instead of creating a custom PCB.

You could pretty much use any ESP model. I ended up using an ESP12.

The pushbutton switches and USB to Serial module are only necessary to program the ESP. That's the reason for the "header pins" on the ESP:

  • Ground
  • RX
  • TX
  • GPIO0 (bring to ground at power up to put ESP in program mode)
  • Reset (optional)

As you can see in the photos, instead of mounting the relay module on a PCB, I use the relay module as the center piece. I mounted the AMS1117 LDO (Low Drop Out voltage regulator) and the ESP8266 around the relay module. The wires are stiff enough to hold the ESP in place. I discovered that the 3.3V output of the LDO is available at the middle pin AND at the heatsink which is more convenient structurally to hold the ESP in place.

Step 6: Programming

Picture of Programming

When it comes to software, there are many options. The simplest one I found at the writing of this Instructable is Blynk. Download the free app onto your iPhone or Android. Register and get the AuthToken.

In the Arduino IDE, open Library Manager (Sketch > Include Libray > Manage LIbraries...) to install blynk library.

Under File > Examples > Blynk > BoardsAndShields > ESP8266_StandAlone

Modify the sketch to include your AuthToken, home WiFi SSID and password.

Hold GPIO0 to ground (using a switch of just temporarily wire it to ground) while powering it up or pressing reset.

Once the upload is done, you no longer need the USB to Serial module.

Setup the button in the Blynk app and you're done!

Have fun!


Jeebus678 (author)2017-11-10

You really don't need a voltage regulator to step down 5v to 3.3v, a simple voltage divider circuit will do the trick and is basically free in terms of cost (just two resistors). Read about it here:

conwyn (author)2017-03-31

Hi dont you need internet connection to run the BLYNK application

HariFun (author)conwyn2017-03-31

Yes you do, that's how the blynk app talks to the ESP8266 (via your wifi router and the blynk server). I think you could setup your own home blynk server on a Raspberry Pi if you don't want to rely on the cloud blynk server.

roneea made it! (author)2017-02-16

You are the best teacher on the net

Thank you

I did it in 10 minutes

Thank you so much

1-wemos D! mini

2-Relay Module 5V 2CH

HariFun (author)roneea2017-02-17

That's awesome! Thanks for sharing the photo!

Sleeman (author)2017-01-05

Hello ! Nice project ! I will probably do it in a few weeks (eBay shipping time).

I've just noticed something, in the step 5 you show the wiring sheet and I think only the upper outlet will be controled by the relay no ?

HariFun (author)Sleeman2017-01-05

Thanks. Yes, you are correct, I opted to only switch one of the outlets.

nitingautam (author)2016-10-04

Thanks for detailed information, is there a cheap 5V output supply which we can use?

HariFun (author)nitingautam2016-10-05

You're welcome.
The ESP WiFi module uses less than 200mA, so just about any 5V supply will do. You might even already have an old phone charger you no longer need. Or look in dollar stores, they usually have them for, er a dollar :-)

domlhereault made it! (author)2016-08-17

There it is... before and after putting everything together... with xtra insulation inside (i put electrical tape on every piece of metal I could see;)

I used a recycled fused power switch from a dead projector in which I connect a computer power cable... ur never too safe. ?

thx to HarryFun for all his guidance.
im gonna make more of those for sure...

HariFun (author)domlhereault2016-08-17

Looks great! Love the fused power switch! Thanks for sharing your build!

domlhereault (author)HariFun2016-08-17

Do you know if there is a way to have 2 widgets affected to the same digital pin in blynk?

i was thinking having the on/off button and also having a timer for the same outlet.

would I short the esp if I use another gpio pin in the same port of the relay?

would it be better to program a virtual pin?

HariFun (author)domlhereault2016-08-17

I would not connect two outputs. I think that would cause problems for the ESP.

Alternatively, since the ESP is a microcontroller like an Arduino, you COULD implement the timer on it. Might be more than what you want to chew though :-) .You will also need to read current time from timer server in the cloud if you want it to be accurate.

domlhereault (author)2016-08-15

This is the message I get:


error: failed reading byte

warning: espcomm_send_command: cant receive slip payload data

error: failed reading byte

warning: espcomm_send_command: cant receive slip payload data

error: failed reading byte

warning: espcomm_send_command: cant receive slip payload data

warning: espcomm_sync failed

error: espcomm_open failed

error: espcomm_upload_mem failed


I've checked and re-checked, and re-re-checked the connections and everything is like ur tutorial, same hardware, etc. Which raise a few questions.

1- In Arduino soft, what is the programmer used, mine is set at "AVRISP mkll" by default, is it the good one ? (library, board and all the shebang are up to date).

2- Should I be able to flash the esp8266 right out of the box, or I need to pre-flash with another firmware before?

3- Everything was connected together before I started attempting to flash, Should I flash, then connect all the component?

Thx for your guidance.

HariFun (author)domlhereault2016-08-15

I've never seen those errors, but one common cause of upload failure is that the ESP is not in program/flash mode.

Power off the ESP, connect GPIO 0 to ground, apply power to the ESP. Now the ESP is ready to receive new program.

Compile and upload the sketch in Arduino IDE.

1 - I don't think Programmer setting on the IDE matters, but mine is set to "ArduinoISP"

2 - You should be able to flash the ESP out of the box or any state since we're replacing everything that's on it.

3 - As long as GPIO 0 is LOW/grounded during programming and the other pins such as Chip Enable and reset are properly set, it does not matter what you have connected to the ESP.

Good luck!

domlhereault (author)HariFun2016-08-16


it was indeed the case, the 1k was getting in the way of the GPIO 0 and the GRD because I was using the resistor pin to put the jumper cable on. I had to solder another pin on the side of the resistor. Its not like there is a lot of place to solder, but I was able to pull it off, then the sketch was able to upload sucessfully and what do you know, I got a wifi outlet too !! The only variation I did was that I had a fused power box with on off switch recycled from an old projector... so if the S%"$/ hits the fan the fuse will hopefully blow before going to my breaker pannel.

Once again, thank you very much!!! ;)

PS: I upload pictures once everything in put together.

HariFun (author)domlhereault2016-08-16

How exciting! Glad you were able to solve it.
Yes, please post pictures, I'd love to see it!

domlhereault (author)HariFun2016-08-16

Thx again Mr Fun.

MTKapp27 (author)2016-06-09

Is there anyway you can provide more details or steps on how exactly you programmed the ESP8266 board? I think I can do it using an arduino, but I am not positive. I don't have the FTDI 232 UART chip, but I don't think it is needed if I have the arduino, correct?

HariFun (author)MTKapp272016-06-09

Though I've never done it myself, I believe it is possible to use an Arduino as an FTDI. Here's one I found:

I don't know how that would affect the programming procedure, but here is how I did it using an FTDI:
1. Choose Generic ESP8266 as my board
2. Choose the correct COM port where the FTDI is
3. Click Upload
4. Turn off power to the ESP
5. Connect GPIO0 to ground (I usually have a pushbutton to do this, but a simple jumper wire works too)
6. Turn on power to the ESP.
When the ESP boots up and it sees GPIO0 is LOW, it knows it's supposed to wait for new code from the computer.
7. Sketch will start running after upload is complete.
8. Remove GPIO0 from ground (it should have a 1K pullup resistor to bring it HIGH).
next time you reboot power on ESP it will run the sketch instead of waiting for new sketch.

You might want to get an FTDI module from ebay, I've seen them for less than $2 and they're quite useful to have. Make sure you get one that is switchable between 3.3V and 5V. If you can find one with both DTR and RTS that'll be even better. See diagram at bottom of this page:

Shadenf (author)2016-06-05

This is awesome! Thanks for writing this :)

Question: Is it possible to make the ESP8266 control more than one relay? So for your project have two relays so both outlets are independently controlled?


HariFun (author)Shadenf2016-06-05

You're welcome.
Yes, you can have as many relays as you have GPIO ports.
Depending on which ESP12 model you use, it could range from 2 to 8.
Make sure that the power supply for the relays can supply enough current for both relays being on simultaneously.

Shadenf (author)HariFun2016-06-06

Thank you for that info, I am definitely going to make this now.

Thanks for the inspiration :)

TonyF12 (author)2016-06-01

You are a STAR HARI!

Great video, great idea and I just love your projects and great videos - that must take A LOTS OF TIME to PRODUCE it!


HariFun (author)TonyF122016-06-01

Thanks Tony!

domlhereault (author)2016-05-29

hi, great instructable! im fairly new to all of this.. what is the wattage for the 1k resistor? i went to the electronic shop and they got 1/4w, 1/8w, 1w, 2w, etc. i did not know what to pick... thx

HariFun (author)domlhereault2016-05-29

Very little current will go through that resistor so 1/4 w is fine. 1/8 w if you want to be cautious. Anything higher would be overkill.

domlhereault (author)HariFun2016-05-29

thx for the quick answers ;)

oh.. and just to make sure, the ams1117 is a 3.3v or 5v?

HariFun (author)domlhereault2016-05-29

Ams1117 converts 5V to 3.3V.
It has three legs:
One leg is common ground.
One leg is 5V input from the phone charger.
One leg is 3.3V output that would power the ESP8266.

Carefully follow the diagram or datasheet. Incorrect wiring will likely cause permanent damage to the AMS1117 :-(
My diagram is drawn with the "top" side of the chip with the AMS1117 label facing you.

HSB2015 (author)2016-05-26

I am trying to understand the connection between the relay and the wifi module. Is this the correct schematic ?

thurtado (author)HSB20152016-05-26

The connection to the relay is dependent on which relay you use. A data sheet for the one that appears in the pictures here can be found at:

Note that the actuation current for this relay is ~72mA (70 ohm coil) which is too much to ask the ESP8266 to supply. A cheap bipolar xstr (2N3904 or 2N2222A) is needed to buffer the GPIO-to-relay actuation input is needed.

HSB2015 (author)thurtado2016-05-26

Goit it...but just for the sake off...based on the above prototype how did you connect the wifi module to replay...I can see one blue wire is connected between wifi module (port#4) and replay..second connection of red wire ...but not sure on the third black cable that you made the connection between wifi module and relay. Is it between wifi module ground port and replay?

HariFun (author)HSB20152016-05-26

You got it. Blank is ground for the ESP, relay, and that comes from the cell phone adaptor. Of course, make sure got the polarity of the cellphone adaptor correctly ;-) ground(-) and 5V(+)

HariFun (author)HSB20152016-05-26

You got it pretty close:

1. GPIO 0 should only be connected to ground during programming. After that the 1K pullup resistor should pull it high.

2. Though it doesn't matter, I would put the hot wire in the middle (common) relay pin, and the switched outlet on the Normally Open connection on the relay. I apologize that in the original drawing I was inconsistent on that part.

PS: I've updated the diagram, so hopefully it is clearer now.

Let me know if I still need to clarify further. Thanks for asking and motivating me to improve the diagram. :-)

Fezder (author)2016-05-25

Next step; dimmer? :)

thurtado (author)Fezder2016-05-26

Google MOC3010, opto-isolator plus diac that serves as a triac trigger device - there's a whole set of parts that will fill the bill. The MOC3010 plus the triac of your choice brings the dimmer capability to the ESP8266. I'm working on this design right now in my spare time. And, yes, PWM is the way to go, just make sure it's fast enough to avoid visible (or subliminal?) flicker.

HariFun (author)Fezder2016-05-25

Fellow user billgeo mentioned the use of a Triac instead of a relay
I wonder if the Arduino IDE for ESP supports PWM. Hmmm...

Thanks for the idea Fezder!

Fezder (author)HariFun2016-05-25

Well, PWM is all about rapid on/off so all that is needed is to vary time between these, if there is no native PWM available like in arduino. Glad to be of help!

billbillt (author)2016-05-25

Great project!!.. I tried to vote for you, but for some reason I am not allowed to vote any longer..

HariFun (author)billbillt2016-05-25

Bummer... that you could not vote for my project.
No worries. Thanks for the positive comment!

Gadget93 (author)2016-05-24

This is really cool. Your video looks a little too polished and professional though.

HariFun (author)Gadget932016-05-24

Thanks for saying that it looks polished and professional, my head is a few inches bigger now ;-)
In addition to making things, I also like making YouTube videos.
I'm quite pleased with the result as far as video editing. However, I felt that the content value is low. I hope this instructable is more useful as far as content. Thanks again for your kind comment.

Gadget93 (author)HariFun2016-05-25

You're welcome.
I don't know if this is possible but have you considered doing an instructable on video editing or doing whatever you do? I'd find it fascinating.

HariFun (author)Gadget932016-05-25

Hmm, I've never thought of doing an instructable on video editing. But that's a good idea because although I do not know very much about video editing, I know more than when I first started! :-)
BTW, I learned most of what I know about iMovie from Eric Timmer:

Gadget93 (author)HariFun2016-05-25

Neat! I will have to check that out too.

conwyn (author)2016-05-25

Hi so the ESP does not require any programming but how many relays module can the ESP controll

HariFun (author)conwyn2016-05-25

The ESP require programming. However, who provides the iPhone/Android app has a library with example code pretty much ready to go. All you need to do is fill in a few parameters so it could connect to the internet, compile it, and upload it to the ESP.

Depending on how which ESP8266 model you use, the number of GPIO that you could use to a relay varies from 2 to 8. If you REALLY want more, you could add an I/O expander to increase it to 64! lol

marcspeth (author)2016-05-24

There was so much information that was not given about how Blynk works that this is virtually worthless. What exactly gets programmed into the ESP8266? What IS the ESP8266? How do you get your phone to communicate with the module? (specifically: what app do you use on your phone?)

HariFun (author)marcspeth2016-05-24

The app on the phone is called Blynk. Their website is
You download their app to your phone, you upload their code to the ESP. They have fantastic intro and documentation on how to do both.
I covered what code and how to put the code onto the ESP in step 6.

ESP8266 started its life as a WiFi module, but thanks to some very smart people, the ESP is now basically a microcontroller like an Arduino that has built-in wifi.

About This Instructable




More by HariFun:HariFun #136 - How to Write a GameDIY WiFi Outlet (HariFun#135)DIY Motorized LEGO Camera Dolly
Add instructable to: