ESP8266-01 IoT Smart Timer for Home Automation

28,355

151

77

UPDATES

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)

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

Boot-up

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.

MODE/SET Button

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

Libraries

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 Libraries.zip 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 - 192.168.4.1
  • 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:

Status

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.

Programs

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.

Configuration

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.

NOTE

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.

Regards

Eric

Invention Challenge 2017

Participated in the
Invention Challenge 2017

Home Improvement Contest 2017

Participated in the
Home Improvement Contest 2017

4 People Made This Project!

Recommendations

  • Indoor Lighting Contest

    Indoor Lighting Contest
  • Make It Fly Challenge

    Make It Fly Challenge
  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest

77 Discussions

0
None
HoàngT52

Question 12 days ago

Can someone port this firmware to 4 relays support in 1 NodeMCU

1 answer
0
None
Mohammad AminJHoàngT52

Answer 9 days ago

It is possible NodeMCU has More Port and by some Modification In Source Code
Of Course In Java Code for web Interface you can do it.

0
None
JarekW2

2 months ago

Problem with WiFi Manager. After pressing the button, the network (AP) does not appear.
After a few seconds the LED blinking faster.
edit: The button works well.
Please help!

1 reply
0
None
Mohammad AminJJarekW2

Reply 9 days ago

After pressing the button, the network (AP) does not appear:: Because AP >>> ST
After a few seconds the LED blinking faster.:: Can't Connect To NTP Server. Try Another NTP Server.

0
None
StudentP

3 months ago

Very nice and useful project i suggest to you have to add on off loop timer just like ewelink app i hope u will implement it on your next version . Thanks

0
None
kranshydro

4 months ago

Well done Eric Brouwer , just what I needed after Eskom blowing out 2 RPi's to control my greenhouse pumps. I had a NodeMCU on hand and little time to dev. I see a few questions around "What next" Maybe a better explanation of the i/o GPIO values in the code. i.e for MCU specific to match the diagram. Then it would be great to add channels. Relay 2 -4 eg. I dont have a spare to dev on , as this one is in production. Thank you.

0
None
am.steen

4 months ago

Dear Mr. Eric Brouwer

Many thanks to you for sharing this circuit, In fact I do your project on ESP8266-ESP12E samll board
and System work fine but after power failure or reset ESP8266-ESP12E could not connect the wifi network and the LED flash rapidly for about 5 seconds, then off for about 5 seconds

and you can not ping the ESP or browse it.

When I flash the firmware v1.10 again and start setup I found that it saved my wifi settings but not connect, please help.

ESP8266-ESP12E.jpg
0
None
Eric Brouwer

11 months ago

Hi all

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

- Some minor bug fixes made

- Now supports the Sonoff Basic

Enjoiy.

9 replies
0
None
SantoshT12Eric Brouwer

Reply 7 months ago

Pls share updated code, I m getting following error xtensa-1x106-elf-gcc error { archive_file_path } No such file or dictiory Error compling

0
None
Eric BrouwerSantoshT12

Reply 7 months ago

Hi
The latest software version is available under Step 6.

This code was tested on the following:
ESP8266-01
NodeMCU
Wemos D1 Mini

Did you install all the required libraries?

Regards, Eric

0
None
SantoshT12Eric Brouwer

Reply 7 months ago

Yes .... still it is giving error and also flash mode for generic esp8266 DIN option is not available...... pls share arduino version

0
None
Eric BrouwerSantoshT12

Reply 7 months ago

Hi, I am using the following:

Arduino Ver 1.8.5
ESP8266 library Ver 2.1.0

The additional libraries used is also available for download under Step 6.

Hope this will help.

Regards, Eric

0
None
SantoshT12SantoshT12

Reply 7 months ago

Trying my espmodule ip set in config file not nothing ..... so after config what is next

0
None
santoshtEric Brouwer

Reply 7 months ago

Thanks after upgrade ide able to complied code sucessfully. and i able to acess IOT timer page config the same if try to access nothing .......next is what ?...................

0
None
SantoshT12santosht

Reply 7 months ago

Trying my espmodule ip set in config file not nothing ..... so after config what is next

0
None
MarcoN50

Question 11 months ago

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

It works flawlessy on a black esp01 (1M flash)...at 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 192.168.4.1 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
1 answer
0
None
Eric BrouwerMarcoN50

Answer 8 months ago

Hi.
Did you try the latest software version? This is a known issue with the new ESP-01 modules.

It is still in test phase, but seems to solve the problem.

The settings are no longer saved in SPIFF, but on EEPROM.

Regards, Eric