DIY WiFi Outlet (HariFun#135)





Introduction: DIY WiFi Outlet (HariFun#135)

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

Step 1: 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!!!

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

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

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

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

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!

2 People Made This Project!


  • Clocks Contest

    Clocks Contest
  • Creative Misuse Contest

    Creative Misuse Contest
  • Water Contest

    Water Contest

89 Discussions

Hi, great tutorial!

I have a question: in one of the first pictures you show an ESP01 (I think), while in the project you actually used an ESP12. Do you think that an ESP01 would work too? Which pin from the ESP01 can I connect to the relay?

2 replies

Hi Michele,
Yes, you can use any ESP, we're only using one GPIO pin to control the relay, so just make sure to specify that pin when setting up the Blynk (or whatever software you want to use to control the ESP). I would avoid GPIO zero since that one is also used to put the ESP into program mode.

OK, so I went to preferences - and typed into the additional boards manager URLs, then went to boards manager under tools and ESP8266 IS NOT there?? What am I doing wrong?

4 replies

Those are the correct steps. Try clicking the icon to the right of that textbox. It will popup a dialog box. Make sure there is only one URL per line. Good luck!

OK, I figured out the problem, but don't know the solution. When I hit OK, on the bottom of the screen it says, "Error downloading"

Does that url work from if you use a web browser?
Maybe your ISP blocks it?
If you can access that URL and yet the IDE cannot, make sure you're using latest Arduino IDE?
Very odd indeed...

I thought that might be the case as well, but it works fine when I open it in a browser. I downloaded the latest Arduino IDE right form the site. I'm using the app from the windows 10 store, the Arduino site redirected me to it. I am however using a work laptop, but I have admin rights to it.....IDK it's really frustrating, maybe I'll try another PC

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?

2 replies

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:

I can't find "Generic ESP8266" in the board dropdown, even when I search ESP8266 in the boards manager, it still doesn't find anything

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:


1 year ago

Hi dont you need internet connection to run the BLYNK application

1 reply

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.

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 ?

1 reply

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

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

1 reply

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 :-)

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.

1 reply

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!