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!

Participated in the
Internet of Things Contest 2016

Participated in the
Sensors Contest 2016
92 Comments
3 years ago
1) Where can i find the right size pins for the ESP8266?
2) What is the right resistor?
I have 1k ohm (1000 ohms) 1/4W 1% metal film resistor?
2a) Is this the right one?
Reply 1 year ago
Did u ever get the pins
Reply 1 year ago
No not yet. trying to figure out the pins that he used for the AMS1117 Low Drop Out Regulator. And the type of rod that he is using in the video @ 1:09 mins.
5 years ago
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?
Reply 5 years ago
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.
Reply 5 years ago
Thanks!!
5 years ago
OK, so I went to preferences - and typed http://arduino.esp8266.com/stable/package_esp8266com_index.json into the additional boards manager URLs, then went to boards manager under tools and ESP8266 IS NOT there?? What am I doing wrong?
Reply 5 years ago
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!
Reply 5 years ago
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 http://arduino.esp8266.com/stable/package_esp8266com_index.json"
Reply 5 years ago
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...
Reply 5 years ago
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
7 years ago
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?
Reply 7 years ago
Though I've never done it myself, I believe it is possible to use an Arduino as an FTDI. Here's one I found:
https://oscarliang.com/use-arduino-as-usb-serial-adapter-converter/
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:
http://www.arduinesp.com/getting-started
Reply 5 years ago
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
6 years ago
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:
https://learn.sparkfun.com/tutorials/voltage-dividers
6 years ago
Hi dont you need internet connection to run the BLYNK application
Reply 6 years ago
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.
6 years ago
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 ?
Reply 6 years ago
Thanks. Yes, you are correct, I opted to only switch one of the outlets.
7 years ago
Thanks for detailed information, is there a cheap 5V output supply which we can use?