Wifi Relay With ESP8266




Introduction: Wifi Relay With ESP8266

This wifi relay can controls any device like lamps or your soldering station with your smartphone or your computer.

Step 1: Materials and Tools

To make this wifi relay you will need:
An Esp8266, which can be program like an arduino and have wifi built in
An USB to TTL converter for programming the esp8266
2 relays 220vac control by 12v
2 transistors TIP122
6 diodes IN4007
A few resistances (2x1k, 2x10k, 330, 220)
Some screw terminal and pin headers
A plug in
2 plugs out
A transformer 12v
A power switch
2 meter of 3 wires cable
A lm317
Capacitors 50v of 1000uf and 10uf
Prototypes pcb
Some screws

For the tools you will need a solder iron, a drill, a 3d printer (optional) and sandpaper.

Step 2: The Relay Board

I divided the electronic in two boards:
- the relay board with the 2 relays and 2 transistors
- the esp8266 board with the module and all the power part (transformer, bridge rectifier and the lm317 for the 3v3 regulate)

This board is very simple, it consists of 2 mosfets how control 2 relays.
I made this board by placing all the components on the Prototype pcb and then I cut the it in the right size with a saw. I solder all the components and after I link them with wire. Pay attention of the diameter of the wire when connecting relay, you should use bigger one for the high voltage.

Step 3: The Main Board

The main board has 3 parts:
-the 12v power which is a bridge rectifier (four diodes) and a capacitor.
-the 3v3 power regulated with the lm317 and the 2 resistors. It creat a constant voltage for the esp8266.
-the module esp8266 with resistors
To make the second board, repeat the same process of the first one. When it's done, check the voltage at the power pin of the module.
Once the 2 boards are done, connect them together wire wire.

Step 4: Make the Box

I made a box with sketchup and 3d print it. If you have access to a 3d printer, download the stl file and print it (20% infill and 0,3mn layers). Sand the box and clean holes. If you don't, you can made a box out of a Tupperware or any plastic box.

Step 5: Finish Everything

You can now finish everything. Place first the electronics and the transformer into the box and glue them. Take the 3 plugs (one in and 2 out), strip the end and connect each wire with the terminals screw by following the schematic. Don't forget to connect the transformer.

Step 6: Program the Esp8266

The last step is to program the esp8266 like an arduino. Follow this tutorial if you don't now how to do it: https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide Download my program and upload it into the module. Don't forget to change the wifi name and the password. Enter the IP of the module into any web browser and you will see 2 on/off virtuals switches. This switches control the 2 gpio pins connected to the transistors.
After plug in the module, close the box witch 4 screws. And that's it you can now control any device with your smartphone or PC.

3D Printing Contest 2016

Runner Up in the
3D Printing Contest 2016



    • Creative Misuse Contest

      Creative Misuse Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Water Contest

      Water Contest

    67 Discussions

    please help me about android app

    i cannot find any android app.


    Thank you for this project. It-s alive :)

    I'm doing something incorrectly, but have spent enough time on it that I'm throwing in the towel.

    I upload the sketch, and go to the web, everything works great. If I unplug the board from power and plug it back in, I got nothing. The web comes up as "network not responding".

    Is there any idea what I've done wrong?

    I'd also like to set a static IP if that's possible. can this be done?

    2 replies

    You have to reserve a range for static IPs in your router. Edit DHCP range to start with 100 (for example to, so you can use 99 and below to static IPs.

    In your sketch you can use WiFi.config(ip, gateway, subnet, DNS) to set the static IP for ESP.

    Please, follow this thread https://github.com/esp8266/Arduino/issues/1959 to the end.

    If you set to ESP, it will always be found at this IP and router will never assign this IP to other element in your network.

    Is it because the ip of the esp change every time it's connecting to the wifi?
    If yes, the problem comes maybe from your router and not the module. But I have no idea how to solve this problem.
    Try others sketches from the web to see if you have the same problem.

    Ok I have made this and it worked like a charm first go. However I have had some experience with the ESP8266. But unfortunately its still unstable. The device becomes unresponsive to the webpage after a day or two. I am trying to use this in a real world situation where I need it to ALWAYS work as its installed remotely (outside controlling a pet door) The power supply is rock solid and I used an older version of this software programed by a different method (before it was intergrated into arduino IDE) and IM getting the same result.

    Yours works exactly the same. Works great but you come back after a day of it running and it wont load another webpage. The original webpage open on the laptop or phone simply doesnt respond either. I have changed devices several times, programmed with different programers, used different webpage clients , everything. The things I have not changed are the brand of ESP (version 1) and my wifi router, which is a Netgear dual band wireless router, only 2 years old. It works flawlessly with my other devices.

    Does anyone have any idea what is going on?

    Hi there,
    I just wanna know I've 3 ESP8266 boards connected to my router.
    Each board can be accessed by putting their individual IP and thus the corresponding devices can be controlled.
    But if I wanna access all the boards simultaneously, what Have I to do for that??
    I'm asking this question because the 3 ESPs are controlling each of my room. If I've to control the appliances of my room-1, I need to connect to corresponding ESP8266. For room-2, need to connect to corresponding ESP8266 and so on. But what if I wanna control all rooms simultaneously.

    Any suggestion would be appreciable..

    1 reply

    My only suggestion, would be only one device should handle the UI, but know the URL for each device, I.E. sending page as one solid, but each button pressed would send back the device's URL, and which port to control. You would then need each device to report back it's status to the main device. could get complicated, but not impossible..

    i made this project with esp8266 12E...but i am facing a problem...when i connect the relay to the esp when it is already ON it works fine but when i connect the relays first and then turn the circuit ON it turns the relays automatically ON and i can't turn the relays on or off...

    2 replies

    solved it...i connected the relay to the output pin of the esp and then burned the program to the esp....and this worked :)

    Yes of course but check the maximum voltage and current depending of the relay you use

    Yes my esp8266 restarts when I use any AC product ( After first switching ) with relay whereas for DC it works fine .

    I am using BC547 .


    Such a nice work. It pushed me to make such a project for my Home devices.

    But during executing the same, I am facing some problem that the 5V Relay, I am using in my project, works when I connect IN1 or IN2 of Relay to Low (ground) but the digital output of the GPIO0 and GPIO2 is high (positive). And it causes the relay ON when I click to OFF button on Web and OFF when I click ON.

    In case of LED it works fine bcoz no matter what the output GPIO pin is providing, the second LED pin will be connected accordingly (either to high or low).

    Kindly provide any suggestion.


    1 reply

    Yes depending on the relay you use, it will inverse the position, you could try to inverse the position directly in the code or by using an inverter

    Hi, great project !

    Can you upload the library you use at this project ?

    (as I have issues with the new one)

    Hi! can i manually turn the load on or off???if no how can i do it..

    1 reply

    yes of course if you add a manual switch in parallel with the transistor or directly in parallel with the relay (you will be able to turn on/off without powering on the esp )