loading

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!

<p>Hi dont you need internet connection to run the BLYNK application</p>
<p>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.</p>
<p>You are the best teacher on the net</p><p>Thank you</p><p>I did it in 10 minutes</p><p>Thank you so much</p><p>1-wemos D! mini</p><p>2-Relay Module 5V 2CH</p>
<p>That's awesome! Thanks for sharing the photo!</p>
<p>Hello ! Nice project ! I will probably do it in a few weeks (eBay shipping time).</p><p>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 ?</p>
Thanks. Yes, you are correct, I opted to only switch one of the outlets.<br>
<p>Thanks for detailed information, is there a cheap 5V output supply which we can use? </p>
<p>You're welcome.<br>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 :-)</p>
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;)<br><br>I used a recycled fused power switch from a dead projector in which I connect a computer power cable... ur never too safe. ?<br><br>thx to HarryFun for all his guidance.<br>im gonna make more of those for sure...
<p>Looks great! Love the fused power switch! Thanks for sharing your build!</p>
Thx. <br>Do you know if there is a way to have 2 widgets affected to the same digital pin in blynk?<br><br>i was thinking having the on/off button and also having a timer for the same outlet.<br><br>would I short the esp if I use another gpio pin in the same port of the relay?<br><br>would it be better to program a virtual pin?
<p>I would not connect two outputs. I think that would cause problems for the ESP.</p><p>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.</p>
<p>This is the message I get:</p><p>----------------</p><p>error: failed reading byte</p><p>warning: espcomm_send_command: cant receive slip payload data</p><p>error: failed reading byte</p><p>warning: espcomm_send_command: cant receive slip payload data</p><p>error: failed reading byte</p><p>warning: espcomm_send_command: cant receive slip payload data</p><p>warning: espcomm_sync failed</p><p>error: espcomm_open failed</p><p>error: espcomm_upload_mem failed</p><p>-----------------</p><p>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.</p><p>1- In Arduino soft, what is the programmer used, mine is set at &quot;AVRISP mkll&quot; by default, is it the good one ? (library, board and all the shebang are up to date).</p><p>2- Should I be able to flash the esp8266 right out of the box, or I need to pre-flash with another firmware before?</p><p>3- Everything was connected together before I started attempting to flash, Should I flash, then connect all the component?</p><p>Thx for your guidance.</p>
I've never seen those errors, but one common cause of upload failure is that the ESP is not in program/flash mode.<br><br>Power off the ESP, connect GPIO 0 to ground, apply power to the ESP. Now the ESP is ready to receive new program.<br><br>Compile and upload the sketch in Arduino IDE.<br><br>1 - I don't think Programmer setting on the IDE matters, but mine is set to &quot;ArduinoISP&quot;<br><br>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.<br><br>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.<br><br>Good luck!
<p>Thx, </p><p>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%&quot;$/ hits the fan the fuse will hopefully blow before going to my breaker pannel.</p><p>Once again, thank you very much!!! ;)</p><p>PS: I upload pictures once everything in put together. </p>
<p>How exciting! Glad you were able to solve it.<br>Yes, please post pictures, I'd love to see it!</p>
<p>Thx again Mr Fun.</p>
<p>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?</p>
Though I've never done it myself, I believe it is possible to use an Arduino as an FTDI. Here's one I found:<br>https://oscarliang.com/use-arduino-as-usb-serial-adapter-converter/<br><br>I don't know how that would affect the programming procedure, but here is how I did it using an FTDI:<br>1. Choose Generic ESP8266 as my board<br>2. Choose the correct COM port where the FTDI is<br>3. Click Upload<br>4. Turn off power to the ESP<br>5. Connect GPIO0 to ground (I usually have a pushbutton to do this, but a simple jumper wire works too)<br>6. Turn on power to the ESP.<br>When the ESP boots up and it sees GPIO0 is LOW, it knows it's supposed to wait for new code from the computer.<br>7. Sketch will start running after upload is complete.<br>8. Remove GPIO0 from ground (it should have a 1K pullup resistor to bring it HIGH).<br>next time you reboot power on ESP it will run the sketch instead of waiting for new sketch.<br><br>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:<br>http://www.arduinesp.com/getting-started
<p>This is awesome! Thanks for writing this :)</p><p>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? </p><p>Thanks!</p>
You're welcome.<br>Yes, you can have as many relays as you have GPIO ports.<br>Depending on which ESP12 model you use, it could range from 2 to 8.<br>Make sure that the power supply for the relays can supply enough current for both relays being on simultaneously.
<p>Thank you for that info, I am definitely going to make this now. </p><p>Thanks for the inspiration :)</p>
<p>You are a STAR HARI!</p><p>Great video, great idea and I just love your projects and great videos - that must take A LOTS OF TIME to PRODUCE it!</p><p>THANKS HARI!</p>
Thanks Tony!
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
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.
thx for the quick answers ;)
oh.. and just to make sure, the ams1117 is a 3.3v or 5v?<br>
Ams1117 converts 5V to 3.3V.<br>It has three legs:<br>One leg is common ground.<br>One leg is 5V input from the phone charger.<br>One leg is 3.3V output that would power the ESP8266.<br><br>Carefully follow the diagram or datasheet. Incorrect wiring will likely cause permanent damage to the AMS1117 :-(<br>My diagram is drawn with the &quot;top&quot; side of the chip with the AMS1117 label facing you.
<p>I am trying to understand the connection between the relay and the wifi module. Is this the correct schematic ?</p>
<p>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: <a href="http://www.songle.com/en/pdf/20084141716341001.pdf" rel="nofollow"> http://www.songle.com/en/pdf/20084141716341001.pd...</a></p><p>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.</p>
<p>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?</p>
<p>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(+)</p>
<p>You got it pretty close:</p><p>1. GPIO 0 should only be connected to ground during programming. After that the 1K pullup resistor should pull it high.</p><p>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.</p><p>PS: I've updated the diagram, so hopefully it is clearer now.</p><p>Let me know if I still need to clarify further. Thanks for asking and motivating me to improve the diagram. :-)</p>
<p>Next step; dimmer? :)</p>
<p>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. </p>
<p>Fellow user billgeo mentioned the use of a Triac instead of a relay<br>I wonder if the Arduino IDE for ESP supports PWM. Hmmm... </p><p>Thanks for the idea Fezder!</p>
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!
<p>Great project!!.. I tried to vote for you, but for some reason I am not allowed to vote any longer..</p>
Bummer... that you could not vote for my project.<br>No worries. Thanks for the positive comment!
This is really cool. Your video looks a little too polished and professional though.
Thanks for saying that it looks polished and professional, my head is a few inches bigger now ;-)<br>In addition to making things, I also like making YouTube videos.<br>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.<br>
You're welcome.<br>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. <br>
<p>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! :-)<br>BTW, I learned most of what I know about iMovie from Eric Timmer:</p><p>https://www.youtube.com/user/ierict</p>
Neat! I will have to check that out too.
<p>Hi so the ESP does not require any programming but how many relays module can the ESP controll</p>
The ESP require programming. However, www.blynk.cc 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.<br><br>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<br>https://www.youtube.com/watch?v=gIqyMAo-C9Q
<p>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?)</p>
<p>The app on the phone is called Blynk. Their website is <a href="http://www.blynk.cc">www.blynk.cc<br></a>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.<br>I covered what code and how to put the code onto the ESP in step 6.<br><br>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.</p>
<p>Thanks, I already see a few fun ways to use this. How did you connect the relay to the junction box? </p>

About This Instructable

37,722views

565favorites

License:

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