ESP8266-01 IoT Smart Timer for Home Automation





30/09/2018: Firmware Updated to Ver 1.09. Now with Sonoff Basic Support

01/10/2018: Firmware Version 1.10 trial available for testing on ESP8266-01 with issues

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.



3 People Made This Project!


  • Plastics Contest

    Plastics Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • Optics Contest

    Optics Contest

59 Discussions


Question 2 months ago

I've realized the project and it seems to be really nice.

It works flawlessy on a black esp01 (1M flash) least until I powercycle the module!

I explain better...
I programm the esp01 and then I can connect to the IoT wireless network. I can browse the page and select my WiFi network and my preferred ip.
At this stage if I turn off (removing power, before configuring home network and costum ip) or reset the module there is no problem: the firmware loads and I can access again IoT network.

If I configure my wifi network and ip I can then browse to my ip and configure other things...It works very smoothly. But if now I remove power the module never came back to life. I see it is connected to my wifi (but with another ip) and there is no reply to ping or browsing.

It seems a boot or a flash issue. But gpio are ok as the flash chip: with other sketch they run without problems also after powerloss and reboot.

Seems that the software cannot store settings correctly in eeprom: unless I configure my network it boot your firmware without problems.

Any idea?? Thanks a lot!

Schermata 2018-09-20 alle 16.59.13.png
8 more answers
Eric BrouwerMarcoN50

Answer 7 weeks ago

Hi, and thanks for your detailed question.

I am having the exact same problem with all my new ESP-01 modules.

Please refer to this:

Seems as if the ESP-01 projects will become less now.

Due to this, I have started using the D1 Mini modules, which cost about the same as the ESP-01.



MarcoN50Eric Brouwer

Reply 7 weeks ago

Tnx for your reply!

I tried some of the solution proposed in github issues but anyone worked.
Just to do one last experiment: which size of spiffs do you select? 128k?

D1 Mini modules like this?

Should run on this D1 module this sketch without problem? TNX again!!!

Eric BrouwerMarcoN50

Reply 7 weeks ago

Please see iv Version 1.10 now works. I have removed the SPIFFS save options, and now saves the network data to EEPROM. Looks asif this will solve the problem with the new versions of ESP-01.

Regards, Eric

MarcoN50Eric Brouwer

Reply 6 weeks ago

simply GREAT!
Unfortunately I can't try right now the 1.10 version because I definitely installed the esp01, it works with the water heater and I'll leave it there :D so I can't check if the problem is solved but surely, if you removed the SPIFFS save option, it works!!

I'll try it on the arriving new Sonoff basic, but I have no other ESP01 with puya chips on hands.

However I think I can do something nice sharing the python code to control the manual override of your fantastic SmarTimer via a telegram bot remotely via Internet: all info are in this repository

There is no mod on the original code to run the telegram bot, you only need a Raspberry or other little server to run the python code. The little server has only to be in the same LAN of the IoTSmarTimer.

It is possible to filter by username the access to the bot.
I wish I did a nice thing to thank you for your work Eric, thanks again.

Eric BrouwerMarcoN50

Answer 7 weeks ago

If you really want to implement this project, I can assist you in reprogramming the Sonoff Basic. Works 100% on my code as well.



MarcoN50Eric Brouwer

Reply 7 weeks ago

However having instruction also for Sonoff would be great!
Do YouTube modify gpio?
How do you change settings in Arduino ide ?

Eric BrouwerMarcoN50

Reply 7 weeks ago


Have a look at the latest code. It now supports the Sonoff Basic

MarcoN50Eric Brouwer

Reply 7 weeks ago

Great! I ordered a sonoff basic.. when the package will arrive I'll try the new code, thanks!

Ok... I'll post the code: without wifimanager your code con run smoothly also on new esp01 module "puya eeprom" version.

Eric Brouwer

7 weeks ago

Hi all

I have uploaded Version 1.10_trial for those who wants to test the code with the new generation ESP8266-01 modules that fails to work on older versions.

This is still a test version, so any feedback will be appreciated.

The trial code is available on the first page of the Instructable




7 weeks ago

Unfortunately this project, as we found in the comment above, doesn't work with latest esp01 module with "puya" eeprom chips. Actual arduino ide doesn't support correct writing of SPIFFS file system on puya eeprom.

In Eric's code the only thing using spiffs was wifi manager: I eliminated the function to set wifi password and hardcoded wifi settings in sketch. It's a little bit uncomfortable, I know, but at least in this way it works like a charm!
If Eric agrees I can post the modified sketch.

I also adapted the code for the use of this cheap pcb with integrated relay and power supply, see attached schematic:

I'll test the system in this day: for the moment it's all ok.

Great project Eric, thanks!

s-l1600.jpgSchermata 2018-09-29 alle 20.35.02.pngSchermata 2018-09-29 alle 20.57.12.png
1 reply
Eric BrouwerMarcoN50

Reply 7 weeks ago

Hi, and thanks for your comments.

Yes, please feel free to modify and share your code with others.
Also, thanks for sharing the small relay board drawing. I still wanted to make use of mine, but have no more "old" ESP-01 modules left.



Eric Brouwer

7 weeks ago

Hi all

I have uploaded the latest firmware (Version 1.08) today.

- Some minor bug fixes made

- Now supports the Sonoff Basic



Question 2 months ago on Step 9

Hey Eric That was really nice one. But what if I would like to use an RTC (DS3231) combined with Nodemcu and use it without connecting it to internet is it feasible if so what necessary changes in the code should I make in order to make it work

4 more answers
Eric BrouwerJonS219

Answer 7 weeks ago

Also, remember that the ESP-01 only have 4 IO pins available. You will have to use GPIO0 + 2 for I2C, leave GPIO3 for relay, and reconfigure GPIO1 for the button.

You will then loose the LED function, as there are no more available IO pins.



JonS219Eric Brouwer

Reply 7 weeks ago

I am planing to use NodeMCU I think it might be better. If you have any suggestions, feel free to do it.



Eric BrouwerJonS219

Reply 7 weeks ago

Code will work 100% with NodeMCU and Wemos D1 Mini

Eric BrouwerJonS219

Answer 2 months ago


Yes, it is feasible to use the DS3231 RTC instead of the internet time server.

You will have to add your own software for reading/writing the local time to and from the DS3231.

You also need to remove all the software used to get the time from the internet (all NTP Server related software).

Regards, Eric.


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

1 more answer
Eric Brouweribanzi

Answer 7 weeks ago

Hi. Sorry to hear about your problems.

I am using 14 similar devices, and not a single problem in the past year.

My code uses GPIO3 I thing to drive the relay. This is also the Serial port receive.

For testing, redefine the relay to say GPIO4.

Next, user Serial.begin() to enable serial port.

Then you can add Serial.print commands any place you want.