Introduction: ESP8266-01 IoT Smart Timer for Home Automation

Picture of ESP8266-01 IoT Smart Timer for Home Automation

With the new buzzwords being Internet Of Things (IoT) and Home Automation, I decided to look at the current items in and around my home that is controlled via some sort of device. The items that stood out, are the following:

  • Swimming pool pump
  • Swimming pool water filler
  • Swimming pool and surrounding lights
  • TV/Entertainment system cabinet lights

The common item used to control these devices, are standard wall plug timers. Each device is fitted with it's own timer, and are all located in different locations. So why did I choose these items to begin with Internet of Things or Home Automation projects, you might ask?

Well, living in South Africa, means power failures are a regular occurrence. With statistics of my home, I had 35 power failures in the past year, totaling 40 hours. This is normally not an issue, as all the currently installed timers are fitted with a back-up battery for time keeping during power failures. But there are some issues:

  • These back-up batteries only last a year or two, then the timer has to be replaced. The timers are constructed such that the timer needs to be destroyed to gain access to the internal Ni-Cad battery.
  • Each time the power fails, the timers with faulty batteries needs to be reprogrammed, and the time set.
  • The physical location of the timer, when plugged into the wall socket, makes it almost impossible to read the lcd displays viewing the timer from the top. This means that the timer needs to be unplugged, or I have to lay down on the floor to set or adjust the timers after a power failure.

Due to the above reasons, I decided to test the possibility to replace the timers with an IoT Smart Timer, connected to my local home network.

The idea was to design a stand-alone timer, which can:

  • Automatically adjust the current time using the internet (IoT)
  • Operated without any user actions (Smart)
  • Turn an output On/Off according to set times (Timer)
  • Programmable and controllable via network (Home Automation)

Step 1: The ESP8266-01 Design

Picture of The ESP8266-01 Design

The design was done using an ESP8266-01 WiFi module, as this is what I had available. In it's simplest form, the ESP8266-01 has four I/O pins:

  • GPIO0
  • GPIO2
  • TX
  • RX

ESP8266-01 Power -up Modes

The logic state of the I/O pins are used to determine in which mode the ESP8266-01 will boot up. The first step was to determine which of the I/O pins can be used to drive an output relay.

  • For normal power up, GPIO0 and GPIO2 must be set to logic HIGH. Thus it is clear that these two pins can not be used as an digital output.
  • The Tx pin is set as an output on power up, and the output set high. This Tx pin also transmit some serial data during power up. Thus, this pin can also not be used as an output.

The only remaining pin is the Rx pin. This pin is set as an input at power up, and does not have to be pulled high during power up. This pin is thus the most suitable to be used as an output pin.


To ensure correct boot-up mode of the ESP8266-01 during power up, the following pins are pulled high using 10K resistors:

  • GPIO0
  • GPIO2
  • RST
  • CH_PD

This ensures that the unit boots up correctly each time.

Output Relay

The RX is the only pin suitable to be used as an output. This pin is thus used to drive the output relay via a NPN transistor. The standard flywheel diode and transistor base resistors were added.


The button is connected to GPIO2, and with the button released, a 10K resistor will pull GPIO2 high. Whith the button pressed, GPIO2 is pulled to 0V.

This button is used for two functions:

  • Initial set up to connect the unit to a local WiFi network
  • To manually control the output during normal operations

Indication LED

The LED is connected to GPIO0, and indicates the following:

  • On initial power up, flashes FAST to indicate WiFi Setup mode
  • Flashes slow when the time of the unit is not set
  • indicates the output relay On/Off status

Step 2: The Power Supply

Picture of The Power Supply

I will be using the IoT Smart Timer on different voltage levels, therefore there are two power supply options available:

12 - 24V DC

The DC-DC converter used is suitable for supplies up to 28V DC. The output of the converter is adjustable, and is set to 5V. This needs to be done before the ESP8266 module is connected.

A diode was added to to protect against reverse polarity on the supply input.

220V AC
For this option, I was able to obtain a small 220V/5V switch mode power supply on eBay.

Irrespective of the input voltage, the IoT Smart Timer needs two power supplies:

5V Rail

With both options, the 5V DC is obtained from a switched mode power supply, and not a linear regulator. This means that there is minimal heat generated by the power supply. The 5V is used to drive the output relay

3.3V Rail

The 3.3V for the ESP8266-01 is obtained from an ASM1117 3.3 regulator. The ASM1117 3.3 is a linear regulator, and can handle up to 500mA. However, the heat generated will be determined by the input voltage to the ASM1117. To reduce heat, the ASM1117 is powered from the 5V rail.

Noise Filtering

To reduce voltage ripple to the ESP8266-01, the 3.3V rail is fitted with a 100 - 1000uf capacitor. Both 5V and 3.3V rails are also protected from high frequency interference by 0.1uf capacitors.

Step 3: Assembling the PC Board

Picture of Assembling the PC Board

The PC Board was designed using the freeware version of Eagle. It is a single sided board, which can be easily made at home using the toner transfer method.

Once the PC Board is made, assemble the PC Board in the following order:

  • Solder the ASM1117 regulator and three 0.1uf SMD components to the solder side of the board
  • Add the single jumper to the component side of the board
  • Solder the resistors and diodes in place
  • Add the headers for the ESP8266-01 module
  • Add the header pins for the LED and button
  • Add the screw terminals
  • Using header pins, connect the DC/DC convertor to the board.
  • Solder the relay into place
  • Complete the board by soldering the transistor and 100uf capacitor.

Once all components are soldered to the board, verify all solder points, and ensure no short circuits between pads.

! ! ! IMPORTANT NOTE ! ! !
To ensure that the PC Board can handle large currents on the output contacts, apply a decent amount of solder to the tracks between the relay contacts and screw terminals.

Step 4: Testing of the PC Board

Picture of Testing of the PC Board

! ! ! Before applying power ! ! !

Remove the ESP8266-01 module from the unit. This is to prevent overheating of the ASM1117 regulator before the 5V supply is adjusted.

There is not a lot of tests that can be done after assembly. The most important step is to ensure the correct voltage levels.

  • Apply 12 - 24V DC to the unit.
  • Measure the output voltage of the DC/DC converter
  • Adjust the output of the converter to between 5.0 and 5.5V.
  • Next, measure the 3.3V supply.
  • If supplies are OK, remove power from the unit

You can now insert the ESP8266-01 module into the headers provided.

! ! ! Note ! ! !

Once you have tested the IoT Timer and it is working, use clear lacquer to cover the solder side of the PC Board. This will prevent oxidization of the tracks, and provide extra insulation between the relay contacts and the rest of the circuit.

Step 5: The Enclosure

Picture of The Enclosure

The enclosure is not that important, as long as the PC board and all wiring fits neatly and safe into it.

To make construction easier, I have made up a cable with the LED and MODE/SETUP button connected to it. This gave me more flexibility in mounting the LED and button to the enclosure. This cable is then plugged into the header on the PC Board.

The photos shows one of the 12V units used for LED lights.

Step 6: Programming the ESP8266-01/NodeMCU

Picture of Programming the ESP8266-01/NodeMCU

To program the ESP8266-01, you need to set up the Arduino IDE first. I am not going into this details, as there are plenty of great Instructables available on this topic. I have chosen the following links on Instructables for reference, without any specific order to the authors. Thanks for their individual Instructables.

Follow this ESP8266 and Arduino IDE to set up the Arduino IDE for the ESP8266 module..

Next, you will need a programmer to program the ESP8266. Here are two links:

Using Arduino Uno

DIY Programming Board


You will need to install additional libraries to be able to compile the code. Again, refer to this Instructable:

Install and Use Arduino Libraries

I can not remember which libraries I had to install, but I do know WiFiManager must be downloaded separately.. I I have included these in the file.

Step 7: First Time Setup

Picture of First Time Setup

When used for the first time, the IoT Smart Timer needs to be connected to a WiFi network. This task is done using the WiFiManager library, so no SSID or passwords needs to be typed into the code.

Follow these few steps:

  • Power up the unit
  • The LED will start to flash rapidly
  • Press the MODE/SETUP button
  • When the LED turns off, release the button
  • Wait a few seconds, then open your smartphone or device WiFi connections
  • A new WiFi netword called IoT Timer will be visible
  • Select this access point
  • Log onto the IoT Timer (no password is required)
  • Wait until your device is connected to the IoT Timer network
  • Open up any internet browser
  • In the address bar, type in the following IP address -
  • WiFiManager console will open
  • Select Configure WiFi
  • A list with available WiFi networks points will be displayed
  • Select the required WiFi network, and type in the password
  • Next, enter the IP address you want to use to connect to the IoT Timer
  • Enter the Default Gateway IP address, followed by the mask
  • Once all the settings are done, click on the Save button
  • A new window will open to confirm the new credentials were saved
  • Close your browser

Once saved, the IoT Timer network will shut down, and the unit will try to connect to your WiFi network.

  • Connect your Smartphone or device to the same WiFi network as used for the IoT Timer.
  • Open your browser
  • In the address bar, type in the IP address of your IoT Timer
  • The configuration page of the IoT Timer will open

Your IoT Timer is now ready for use

Step 8: Setup of IoT Timer

Picture of Setup of IoT Timer

The build-in web page of the IoT Timer consist of five sections:


This shows the device name, as well as the current time and output status of the timer

Additionally, the operating mode of the timer is set in this section. There are three modes:

  • Auto - Output will be controlled by the different timer programs
  • On - Output is forced ON, and will stay on until the mode is changed
  • Off - Output is forced OFF, and will stay off until the mode is changed.


This section contains the On and OFF times of the timer. There are seven programs available, and each program can be set individually.

Before changing the the next program, press the SAVE button to save any changes made to the current program.

Button Function

The MODE/SETUP button can be used to control the output relay during normal operation. Here, select what the button must do when pressed.

Tick the "Update Button Function" box before pressing the Save button to save the new settings.


Here, you can change the name of the IoT Timer. This makes it easy to identify between multiple timers.

Time on the unit is obtained from the internet via a NTP time server. To display the correct time, please update the Time Zone to your region.

Should you want to make use of a different NTP time server, enter the new IP address in the space provided.

Tick the "Update Configuration" box before pressing the Save button to save the new settings.


When changing the Time Zone, the new time will only be set correct during the next time query. The unit is set to update the time every 5 minutes.

Time Adjust

Sometimes, it happens that the NTP time server does not respond on every time query. Should it take too long for the time to be set via the NTP server, you can enter the time and date manually.

Tick the "Update Time" box before pressing the Save button to save the new time and date.

Time Synchronisation

The last part of the page indicates the time and date when last the time was synchronised via the NTP time server.

Step 9: Final Words

Picture of Final Words

With the help of several Instructables by different authors, the WiFiManager and it's included examples, and a lot of hours testing and debugging, the current design caters for different errors or faults that the IoT Timer might encounter. To name but a few:

After a power failure, the IoT Timers will boot up faster than the WiFi Router they are connected to. This is handled in code by a 120 second timer that will keep on trying to connecting to the WiFi network.

During normal operations, the WiFi router was turned off for 30 minutes, then restarted. The IoT Timers were all able to automatically reconnect to the WiFi network.

So far, I have three IoT Timers and one Instructable Hit Counter connected to my network, all using the ESP8266-01 WiFi modules. After several days in operation, no additional bugs were detected.

I have created an IoT folder on my smartphone, and added links to each device. This makes accessing the timers quick and simple.

I hope you enjoyed this Instructable, and find it's content useful.




ВладимирМ25 made it! (author)2017-12-03

I have repeated the device, works perfectly! Thanks!

Thanks for your feedback.



xrhxle (author)2017-11-29

Hy Eric i tray to made your project with nodemcu but it did not work even if i use nodeMCu code (The "Iot timer" network is not visible from my pc on android phone) . I have to asked you 2 qeastions

1.Can i remove 2 resistors and trasistor if i use this reley (photo)

2. This part of the code must define my router to connect nodemcu or not

"/define your default values here, if there are different values in config.json, they are overwritten.

//length should be max size + 1


char static_ip[16] = "";

char static_gw[16] = "";

char static_sn[16] = "";"

Sorry for my english.

And thanks from advanced.

Eric Brouwer (author)xrhxle2017-11-30


I have downloaded the code under STEP 6 ( and uploaded it to a NodeMCU. Connections was done as per NodeMCU drawing also under STEP 6. No problems experienced with the unit or code.

Please remember you need to set up the IoT Timer first to connect to your router.

Follow these steps (under STEP 7) for initial setup::

  • Power up the unit
  • The LED will start to flash rapidly
  • Press the MODE/SETUP button
  • When the LED turns off, release the button
  • Wait a few seconds, then open your smartphone or device WiFi connections
  • A new WiFi netword called IoT Timer will be visible
  • Select this access point
  • Log onto the IoT Timer (no password is required)
  • Wait until your device is connected to the IoT Timer network
  • Open up any internet browser
  • In the address bar, type in the following IP address -
  • WiFiManager console will open
  • Select Configure WiFi
  • A list with available WiFi networks points will be displayed
  • Select the required WiFi network, and type in the password
  • Next, enter the IP address you want to use to connect to the IoT Timer
  • Enter the Default Gateway IP address, followed by the mask
  • Once all the settings are done, click on the Save button
  • A new window will open to confirm the new credentials were saved
  • Close your browser

Question 1:

You can test to see if the relay board will work. Remember that the NodeMCU is a 3.3V device, so you will need an additional supply for your 5V relay.

Question 2:

Do not change these values. This is the default IP address of the IoT Timer for setup purposes. These values are NOT used to connect to your own WiFi router.

I hipe this information will help you to get your IoT Timer up and running.


AlessandroM20 (author)2017-10-07
Great project, congratulations. I tried to replace the ESP-01 with Nodemcu V3 Esp8266 Esp12 but it did not work, even if I connected an external 5V source to the VIN pin, I get the following message on the serial monitor:
"Jan 8 2013, rst cause: 2, boot mode: (3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
~ ld "

My NODMCU is working perfectly with other sketches.
Can anybody help me ?

Hi Alessandro

If I have some spare time, I will see how to port this to the NodeMCU.

I will keep you updated.



I thank you immensely. I really enjoyed your project. I will await your return. Thank you very much.

Glad you got it up and running.

I have added the NodeMCU sketch and connection diagram under Step 6 just in case you need some more assistance.


Hi, Eric.

I saw the drawing you added. Appreciate your help.

Now I'm going to set up the circuit for tests. Thank you very much.


Hi Eric.

To test the web interface I did some tests and it worked by changing the ESP-01 through NODEMCU: I changed the variables according to example:

#define Relay D3 // Output relay

#define Button D2 // Button

#define LED D0 // Satatus LED

#define Spare D1 // not used


meahdi (author)2017-07-27

Hi Eric

thanks for share last update

But I see same problem in time zone

When I want set time zone to +4:30 i should type 4.42

where is problem?

Eric Brouwer (author)meahdi2017-07-28

Hi. To enter your time zone (4 hours, 30 minutes) just enter 4.5 (4 and a half hour). I have verified that the Time Zone works correct.


meahdi (author)Eric Brouwer2017-07-29


thanks Eric

It work good

meahdi (author)2017-07-16

Hi Eric
I use your last updated version of this product
It is very nice
thanks for share this program

Eric Brouwer (author)meahdi2017-07-16

Thanks again for your feedback.

If you find any errors, please let me know.


meahdi (author)Eric Brouwer2017-07-19

Hi again

I see 2 little errors

1 ) In previous version, time zone hours and minutes are in separate box

2 ) Time zone adjustment doesn't work true

Eric Brouwer (author)meahdi2017-07-22

Thanks for your feedback.

Yes, the Time Zone is now entered into a single field. For instance, if your time zone is -4 hours 30 minutes, you enter -4.5.

I have looked at the time zone adjustments, and found a syntax error. However, this error did not cause faulty times. It resulted in the time server updates not running fast enough.

It does happen quite often that the NTP Time Server does not respond on every request. I have changed the software to do time requests every 10 seconds until it gets the network time, thereafter, the time is requested only once a hour.

If the NPT Server IP or Time Zone are changed, the network time should update within a few minutes.

Alternatively, you can set the local time , and the time will again be synchronised once every hour with the NTP Time Server.


meahdi (author)2017-07-07

I try to inter time zone +4:30
but cant do it
how can i do?

Eric Brouwer (author)meahdi2017-07-08

Hi meahdi

I have corrected the Time Zone problem for you. Please download the latest revision under step 6.

Please let me know if the problem is now solved.



meahdi (author)Eric Brouwer2017-07-09

Thank`s for this change
it work very good.
if change some menu to folding mode it's better
Like the manual settings of the clock and timezone and "Update Button Function"

Showed time clock on web is not active

if change it to active mode it is better


Eric Brouwer (author)meahdi2017-07-15


I have updated the code, and the web interface is now more streamlined.

Eric Brouwer made it! (author)meahdi2017-07-10

Thanks for your feedback.

This was one of my first projects for the ESP modules, so I am still very unfamiliar with the HTML coding. But I am busy changing the web page as you suggested. Once completed, I will upload the new code, and inform you.

Here are some images of the new interface.



Eric Brouwer (author)meahdi2017-07-07

Hi meahdi

I see that I did not allow for 30 minute offset in the software. I will make the required changes and notify you when I'm done. I will then upload the new code.

Thank you for pointing out this mistake.



meahdi (author)Eric Brouwer2017-07-14


I wait for new edition of this program

Can you add I2C oled display on it for displaying time?

This option make it to more professional than circuit

Eric Brouwer (author)meahdi2017-07-14

The unit already uses 3 of the 4 I/O pins available on the ESP8266-01,, so there are no more I/O pins available to add an OLED display.

My design was made as simple and small as possible, thus the web interface to set/change the settings. This made it more suitable for my application, and reduced the overall size and cost of the unit.

As per my Instructable, you will notice that I opted for a design without a display and programmng buttons, as the location of the timers makes it difficult for me to read the displays.

Hope this answers your questions.

Thanks for your continued feedback, I appreciate it.



meahdi (author)2017-07-07

i made it
it`s very interesting
work very good
thanks for share this project

Eric Brouwer (author)meahdi2017-07-07

Thanks for your feedback. I am glad you found this Instructable useful.



nqtronix (author)2017-07-05

☑ Solves a real problem
☑ ESP8266 fits purpose well (not just slapped on because it's trendy)
☑ Straight forward schematic
☑ Well designed custom PCB (compact, but with good mains-to-circuit spacing)
☑ Simple, yet functional software
☑ Interesting and detailed write up

Honestly I can not think of anything I could do better, this is a very well executed and documented project! I don't have a need for such a timer (yet), but I'll remember when I do!

Best luck in both of the contests :D

Eric Brouwer (author)nqtronix2017-07-05

Thank you very much for your detailed comments. I really appreciate it.



Saeed Nazarian (author)2017-07-03

Great work. I enjoy every part of it. you have my vote!

Thank you for your feedback.

About This Instructable



More by Eric Brouwer:ESP8266-01 IoT Smart Timer for Home AutomationInstructables Hit Counter (ESP8266-01)Converting Camping Deep Freezer Into Fridge/Freezer Using AtTiny85
Add instructable to: