Introduction: Wifi Relay With ESP8266

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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.

Comments

kevinmaker2018 (author)2017-08-25

This NEW version ESP -01M module will perfect in this project.

smocksam (author)2016-07-23

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?

lrd (author)smocksam2017-04-06

You have to reserve a range for static IPs in your router. Edit DHCP range to start with 100 (for example 192.168.1.100 to 192.168.1.200), 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 192.168.1.55 to ESP, it will always be found at this IP and router will never assign this IP to other element in your network.

Romain7333 (author)smocksam2016-07-24

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.

JohnW166 (author)2017-02-09

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?

iTECHKING (author)2017-01-29

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..

Gelfling6 (author)iTECHKING2017-02-09

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..

Harisiqbalengr (author)2017-01-15

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...

why is relay already on, the ESP should turn it on.

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

kmanchanda (author)2017-01-09

Can I use any other Transistor in place of TIP122 ?

Romain7333 (author)kmanchanda2017-01-10

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

kmanchanda (author)Romain73332017-01-11

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 .

iTECHKING (author)2017-01-09

Hi,

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.

Thanks

Romain7333 (author)iTECHKING2017-01-10

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

Michail2017 (author)2017-01-10

Hi, great project !

Can you upload the library you use at this project ?

(as I have issues with the new one)

Harisiqbalengr (author)2016-12-19

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

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 )

you are right i know that...but i want to know that if i turn the relay on from my mobile and then i want to turn it off using that button and vice versa..can i do that?

Yes I think it's possible by adding a button on an input of the ESP and modify the code

Harisiqbalengr (author)2016-12-30

can i use version 12 of esp8266???

Yes of course but the number of the pin may not be the same as the version 1

iTECHKING (author)2016-10-08

I want to know something.

Suppose I have -

(i) a WiFi Router at my home (name Home WiFi) and

(ii) a project (say switching light on/off) with ESP8266 ( name Test WIFi)

Normally my mobile is connected to my "Home WiFi" to access Internet But when I need to switch the light, I'll have to connect my phone to ESP8266 "Test WiFi" and my task will be executed. After executing the task I'll have to connect back to my "Home WiFi".

So each time when I need to execute the task, It requires switching in WiFI connectivity from "Home WiFi" to "Test WiFi" (As per my understanding).

Is there any way that only by connecting with any WiFi (Either Home or Test WiFi) I can access the internet as well as Execute the task ?

Romain7333 (author)iTECHKING2016-10-08

The esp8266 is connected to your wifi and you can have access to it by entering it ip on a web browser. You don't have to connect your phone to the esp just connect the esp to your router, connect your phone to your router and enter the IP address of the esp on your phone and you will see a web page with the buttons.

luckyvictor (author)Romain73332016-12-01

so where is the buttons on the webpage defined please?

DILONTRONICS (author)2016-11-17

Where is the library of the following header files???

aREST.h

aREST_UI.h

Also, what is the device IP address?? Is it "1" set in code?

In board manager I have selected "Generic ESP8266 Module". Is it OK?

I tried to follow the steps you mentioned in this WIFi Relay tutorial, but STUCK UP in code errors. Plz help dear Author.

Romain7333 (author)DILONTRONICS2016-11-18

Hello
Have you tried this tutorial to configure the esp? https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide
By following it you will be able to see the ip of your esp given by your internet box.

Jasmeeet Singh (author)2016-07-09

Can we connect the esp8266 to a microphone for sending the audio to a mobile phone just when it is heard??

No the i/o pin of the esp8266 can't read and send sound from a microphone. But you can use a microphone to detect sound and send an alert to your phone.

WindowsNT (author)2016-05-13

Ah! Your title had me thinking you were building a wireless bridge. You literally meant an electro-mechanical relay controlled via wifi! Voted. This is cool.

WindowsNT (author)WindowsNT2016-05-13

The only thing I have to critique is the orientation you printed the curved case piece. I would turn it on its side so that the curves are on the same plane as the layers.

Romain7333 (author)WindowsNT2016-05-13

Thank you, yes you're right I didn't print it on the right side. I just began into 3D printing.

cburg (author)2016-05-12

This is a nice project as it is. I would like to see an ESP8266 project using the ESP as a switch to send the commands to the relay.

Ruben Marc Speybrouck (author)2016-05-09

We made exactly the same instructable. Lol. I made fancy handdrawn schematics too. respect for those!

ghaneipour (author)2016-05-08

hello

i am c# programmer

how can send PIO command?

Romain7333 (author)ghaneipour2016-05-08

im sorry I'm not an expert into this module, but you can use the gpio like a digital out/input of an arduino with digitalWrite, digralRead...

ghaneipour (author)2016-05-08

my email is ghaneipour@gmail.com

jakebozz (author)2016-05-04

Hi. Any chance of adding some information on the cell phone software you used to connect to this project? Thanks

MagnusR2 (author)jakebozz2016-05-04

He uses a browser like Chrome, Firefox, Opera,... If your phone has Wifi, it has a browser. Then you put the ip in the addess line. Probably something like 192.168.0.9... Your Router should be able to tell you.

cts_casemod (author)MagnusR22016-05-04

How do you use it from outside your network then?

jlms (author)cts_casemod2016-05-06

You would need to tell your router to allow traffic and to direct it to the device doing the whole thing.

cts_casemod (author)2016-05-03

Interesting.

I designed a similar concept, but rather than wi-fi I use an internal network with a master and several slaves.

The slaves have a 30A capable relay and built in power supply

Nman120 (author)cts_casemod2016-05-03

If you don't mind me asking, what circuitry did you use for your integrated power supply?

cts_casemod (author)Nman1202016-05-04

Its based on this design:

http://www.onsemi.com/pub_link/Collateral/EVBUM214...

You can also replace the NCP1014 with a TNY254PN, which can operate as a constant current source (The NCP1014 goes into hiccup mode instead)

MagnusR2 (author)cts_casemod2016-05-04

Then why not buy a power supply pcb. Got me one for LED drive with 12V and 450mA for just about £1on ebay including shipping. I guess that should be enough power?

cts_casemod (author)MagnusR22016-05-04

Thats plenty yes. The reason I built my PS's is because I cant get a product from ebay that has a long life cycle. They keep changing the format even if it is electrically the same, rendering a pcb design defunct

cts_casemod (author)MagnusR22016-05-04

Thats plenty, yes

sayedfar (author)cts_casemod2016-05-03

can you provide the link of the circuit.

dduley (author)2016-05-03

The transistors that you specified are not MOSFETs. They are NPN Darlington transistors. They have two NPN transistors connected in a Darlington pair configuration in a single TO220 package. A MOSFET transistor is something different.

Cool project!

Romain7333 (author)dduley2016-05-03

Thank you, I was using mosfet during prototyping but one died. I changed them by TIP122 but didn't change the name. My mistake.

About This Instructable

51,159views

596favorites

License:

Add instructable to: