ESP8266-01 IoT Smart Timer for Home Automation




Introduction: ESP8266-01 IoT Smart Timer for Home Automation

23/01/2018 Firmware Updated

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

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

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

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

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

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

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

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

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

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.



2 People Made This Project!


  • Fix It! Contest

    Fix It! Contest
  • Water Contest

    Water Contest
  • Tiny Home Contest

    Tiny Home Contest

40 Discussions


5 weeks ago

It Long Time Wifi Seek Iot Smart Timer.Smart Phone Not found It And I On Power Again Smart Phone Not Found.UpLoad To ESP-01 Pass No Error .


Question 2 months ago

Thanks for an awsome project with some really nice code, I have built a version of this for my geyser timer. However it crashes periodically and seems to have something to do with the wifi library. I am using an ESP8266F from electrodragon, similar to the NodeMCU and your NodeMCU code. It crashes on a variety of power supplies and I have tested with several (of the same type) ESP8266. Any thoughts on where I can place some serial print breakpoints to help diagnose. I have tried using a different branch of the wifi library and that improved it a bit but caused a herd of other unexpected behaviour.

3 more answers

Hi Paul

Glad to hear you got yours up and running.



Hi ibanzi

Throughout the development, I only used the ESP8266-01 modules. All my projects are also build using the ESP8266-01. I have a total of 5 unit running perfectly, some for almost a year. I have not experienced any crashes to date.

Although I assisted another reader with the NodeMCU code, I only tested the NodeMCU briefly. I can thus not confirm if the code works perfectly on the NodeMCU.

I have 2 units running from 24V supply, 2 from 12V from a switched-mode supply, one on a 12V battery system, and on from 5V. I do not think that your supply is the problem.

With my code optimised for the ESP8266-01, there are no more pins available for serial debugging.



Thanks Eric

Think I have found the source of the problem. Under tools there is an option for "LwIP Variant" which by default is set to "V2 Lower Memory". I now have it set to "V1.4 Compile from source" and it works perfectly.

So far its running perfectly, hopefully this solves a few other peoples problems too.



Screenshot from 2018-06-05 20-02-08.png

Hi, and thank you for the update. I noticed this this morning when I was looking into the questions asked the past couple of days. Server went down about 17:00 on 13 April, and came back on line 17 April at around 16:00.

I am happy to report that I could not notice a major loss/gain in time for the 4 days the units were keeping their own time without the NTP server.

Mine kept the time as well until yesterday when i had a power failure.

A good update would be the implementation of alternative servers like most routers have.... just an idea....


Initial tests during the design indicated that the ESP is able to keep accurate time for about a week. The maximum time loss was around 5 minutes.

With the NTP server down from 13/04/2018 to 17/04/2018, I ws happy with real-time results, as my devices still switched on/off without me noticing a minor time error.



Question 4 months ago

Thanks Eric, nice comprehensive project that does something really useful. Only real issue I have had is with the NTP time. It does not seem to update under any circumstances. I have been careful to build with the libraries you supplied with the project. I have tried a few other small projects that read and display NTP time and they all work. I have tried to use the ports they used with no improvement. I am probably missing something, as the rest of the software is great. Maybe one of the initialisation variables. Manually set time is fine. Any suggestions? Gerard (ZA).

2 more answers

Hi again GerryGit.

We noticed that the NTP server used as default was down from 13 April to 17 April. Please check if your device is working now.


Hi GerryGit

I am currently using 5 of the devices in my home, and do not have a problem with the NTP time synch.

I am using the NTP IP of on all my devices without any problems.

After complete power failure on all devices, time is normally restored within 15 - 265 minutes on devices.

Please note that NTP servers are not very reliable.... When first powered up, the device will try to connect to the NTP server every 5 minute (might be 10, I can't remember). Thereafter, the time is verified with the NTP server only once every hour. It might be that the time is not updated every hour, but only after a couple of hours.

In my installation, I can say with sertainty that the time is updated at least once every day.

I am not sure if this IP address is allowed/blocked via your internet service provider. During my development, I have tested the devices on the following networks:

- Telkom ASDL

- Vodacom cellular (normal cellular data with phone set up as access point)

- Vodacom APN (Vodacom 3G router via my company's APN network)

- TelkomSA cellular




System work fine but power on after power failure esp8266-01 could not connect the wifi network led flash rapidly but could not connect. solve my problem

1 reply


Does the LED flash rapidly for about 5 seconds, then off for about 5 seconds?

This indicates that the NTP server could not be reached. The unit will continue to try to connect to the NTP server. This can take several seconds, but sometimes quite a few minutes. The IoT Timer will continue to contact the NTP server every 10 seconds until time is obtained.

During this condition, are you able to set the time locally via the Web Interface?

Once time is set locally, the unit will check the time once every hour.

Please note that NTP servers does not always respond....

I am using 5 devices in my home, and part of the design of the software was to ensure the units are able to obtain the time after power failures. This function is tested once a month at my home when I do monthly generator tests runs.

If the NTP server tskes to long to reply, you might need to seach on Google for a different NTP server in you country/area.

Hope this answers your questions.



This is really impressive. I've been trying to modify the code so that the wifi ssid and password is hard coded into the code instead of having to configure the network. I'm having troubles getting this to work though. Any idea on how to get that to work?

1 more answer

Hi Zachary

I have actually spent several days programming and testing the unit using WiFiManager, to set the SSID and password via the network.

The main aim was to create a device that will be usable to all users, and does not require hard coding of the Access Point details.

I have build in the region of 160 units, imagine if I had to obtain the WiFi SSID and password of each user I have sold a unit to. Imagine if these users had more than one WiFi access point on their premises...

Security wise, the WiFiManager setup is relatively secured, as the IoT Timer is only accessible from within the user's home network. Yes, if the user enables port forwarding on their main router/DHCP server, the device can be accessed from the internet.

Another security feature on most home internet connections, is that the IP address of the home router changes periodically, and withuot a sort of DDNS service, access to the IoT Timers are further prevented.

Personally, I believe that the use of hard-coded SSID and passwords is not recommended.




6 months ago

Very good. Working great with everything necessary for my heating system.

Thank you very much for sharing.

Any chance of a login page so it can be used from outside the lan ?

2 replies

Glad to hear that the project is working for you.

Part of my network security is specifically to prevent access from outside my house LAN. Thus I did not look into the password option.

I will keep this in mind when I build another IoT project.


I thought of it also because you included ESP8266WebServer library. ´

I will try to do it myself. With my knowledge level it might take a (long) while....

Anyway thanks again for a very well done job.


8 months ago

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.