Timer Relay using ESP8266 (ESP-01) webserver
Why I made this?
Recently I had an issue with my smartphone. Let me explain, the battery bulged and opened the back cover. I went to mobile repair guy, he said, “It’s because you charge your phone to 100%”. Honestly, everyday I just plug the phone to charging and go to sleep. I thought the makers of my smartphone are smart enough to integrate an overcharge protection circuit. Never mind, what can I do as an electronic engineer to solve this issue. I cannot tweak into charger or mobile but the thing I can do is, cut-off the mains supply using a relay after fixed time duration. which can be preset for time duration it takes for mobile to charge near to 95%. That’s why, I decided to make this “IoT timer relay”.It will also solve my other problem, like sometimes forgetting to turn off electrical appliances. It takes me maximum 10 min to iron the clothes, so I will set the timer relay for 10 min.
What it does?
![]() |
Fig 1 - Block diagram |
How the time is set?
The time duration is set from a webpage served by ESP-01, this doesn’t requires internet. We are using ESP8266 in AP (Access point) mode. In this mode it generates it’s own hotspot. All you need is a smartphone/PC/Laptop, which can connect to hotspot and display webpages with the help of browser.
Components needed
Sr no |
Component name |
Quantity |
1. |
ESP-01 |
1 |
2. |
Relay 5V DC |
1 |
3. |
AMS1117-3.3V module |
1 |
4. |
5V SMPS/Adapter |
1 |
5. |
Switch (push button) |
1 |
6. |
Resistor 1K |
4 |
7. |
Resistor 4.7K |
1 |
8. |
Resistor 56K |
1 |
9. |
Capacitor 47uf |
1 |
10. |
Capacitor 0.1uf |
1 |
11. |
Transistor BC547 |
1 |
12. |
Diode 1N4007 |
1 |
13. |
Led red |
1 |
14. |
FT232RL (USB TO UART TTL 5V 3.3V) |
1 |
These all components you need to make the circuit. You can make circuit on breadboard, perf board or directly make PCB. Depends on your fabrication process. I have made it on breadboard. Below given is the circuit diagram.
Circuit diagram
![]() |
Fig-2 Circuit diagram |
Project program files
1. Download the code from the link given below:-
https://github.com/prachetechnosavi/Iot_timer_relay
3. You have to make ESP board compatible with Arduino IDE. If you haven’t then go through this blog - https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/
a. Switch “GPIO 0” to GND.
b. Switch “GPIO 3 / RX” to TX of USB to UART converter.
c. Reset the board with reset switch. The board is now in programming mode.
d. Upload the code from Arduino IDE. Once uploaded put board in operating mode.
5. Steps to put board in operating mode
a. Switch “GPIO 0” to VCC using pull-up resistor of 1K ohm.
b. Switch “GPIO 3 / RX” to relay driver circuit.
c. Open serial monitor to see the status.
d. Reset the board with reset switch. The board is now in operating mode.
e. The code starts running, so keep an eye on serial monitor.
How does it work?
Flow diagram of the project
![]() |
Fig 3 - Flow chart |
1.Initially it generates it’s own hotspot /Access Point (AP). With name “IOT_RELAY(mac id)” with password “tryit”. You can change password from the code.
2. Connect to the AP and open browser. For eg – Chrome, Opera, firefox , etc.
3. Type IP address 192.168.1.2 in the address bar and hit enter, the webpage will appear. You can bookmark this page, for ease of access. The webpage will look like this
Webpage
![]() |
Fig4 - HTML webpage layout |
5. Close the Webpage and disconnect the device from AP.
6. Reset the ESP board and the relay will stay activated for the submitted time duration.
Now every time we turn on the mains switch which powers the ESP device. The board resets turning on the relay for a set time duration. The time is saved in EEPROM of ESP8266. The load (Electrical appliance) will receive supply as long as relay remains activated.
Conclusion
This project achieves the function of timed switching using relay and ESP webserver. For now, It works for me and will work for anyone willing to make it and use it. If you are someone who has any new ideas for making it better , want to make this or facing some bug in process of making then feel free to contact me.
My email id - prachethire@gmail.com
My contact no – 9137440186
If you found this blog useful and want to support me, then you can donate me. The money you give will be used to make more advance electronics projects and setting up better lab.
Comments
Post a Comment