Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | | About Us
 

Forward Logo (image)      

Retrofit Fan Timer
with override off and settable time

by Matthew Ford 26th August 2020 (originally posted 20th Sept 2016)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.


Final Testing Setup

Retrofitted Fan Timer using ESP8266-01

Update 26th Aug 2020 – Corrected power plug image
Update 2nd Nov 2016 – Added suppression to relay contacts, added addition supply capacitor, added timeout for config.

Introduction

This project shows you how retrofit a timer to your bathroom fan. With this retrofit the fan comes on with the light and then stays on for a period of time after the light is switched off. You can force the fan to turn off early by turning the light on and off quickly (on for less than 5 sec). A web page is provided for setting the period the fan will stay on for after the light is switched off. The complete user operating instructions in pdf format are here.

These instructions assume you already have a fan installed, operated by a separate switch. The installation of this fan timer involves removing the existing fan switch and adding some extra wiring from the light.

Update: Some times the initial design left the fan running. This only occurred in the bathroom with a compact fluorescent light. This latest update appears to have solved that problem. The update added relay contact suppression across the fan's Active and Neutral so there was no power used when the fan was off. An extra 100uF capacitor was also added to the regulator supplying the ESP8266 to help suppress supply spikes. Finally a time out was added to the config setting. The fan now turns off and reverts to normal operation after 5mins in config mode. Since it is easy to get into config mode, by flicking the light switch on and off a few (3) times, this may have been the root of the problem observed. Finally the debounce delay for AC inputs was reduced back to 10mS as users were finding the longer delay missed on/off switching. That is the users could flick the light switch faster then the debouce detected it which caused confusion.

Disclaimer – Mains Power can Kill You or Catch Fire

This project changes the use of the existing mains wiring in your house. You need to get an electrician to do these changes and you do these changes at your own risk. The hardware uses mains power and should only be attempted by experienced constructors. The hardware does not use an earth and is protected by double insulation, but it has not been certified by any standards authority and so may void your house insurance if it causes a fire. The hardware has been designed so it can be tested without using mains power. Carefully note the safety points detailed below.

Hardware and Software

The hardware is mounted in a small ABS box. The fan timer is powered by an ESP8266-01 board, programmed via Arduino IDE, which provides a captive hotspot for configuring the fan time. No internet connection is needed.

Hardware Construction

The parts list is. (Approximate prices as at Sept 2016, excluding shipping)


To program the ESP8266-01, you also need a USB to Serial cable. Here a SparkFun's USB to TTL Serial Cable (US$9.95) is used because it has nicely labelled ends and has driver support for wide range of OS's, but you can also use Adafruit's USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi which is the same price.

The circuit for the timer is shown below and also available as a pdf.

The ESP8266-01 has very limited I/O pins available and there are a few of interesting aspects to this circuit:-

The hardware is mounted on a vero board inside a sealed polycarbonate enclosure.



The above photos show the layout of the components, before adding the connecting wires and mains wiring. Note the cleared areas of the vero board. Around the 240V part of the circuit and under the ESP2866 aerial and under the power supply board which is secured with two part epoxy to the vero board. (
The slot under the opto-isolator is probably not strictly necessary as nothing will protect you against a really good lighting strike.)

On the top of the board there are 4 x 2pin headers, marked. These allow you to power the board from 5V and program, test and debug the software without using mains power.

There are no metal parts connecting the outside to the inside of the enclosure. Also note the strain relief, using a tie wrap, on the incoming and outgoing power cables which set in tight slots cut in top edge of the base of the enclosure.

After completing the wiring as per the above schematic, you can program and test the board. DO NOT apply AC power yet!!

Software Programming

SAFETY NOTE: DO NOT plug in the power cable. All programming and program testing/debugging can be done without applying mains power.

Programming the Timer Sketch

To program the shield follow the instructions given on https://github.com/esp8266/Arduino under Installing With Boards Manager. When opening the Boards Manager from the Tools → Board menu and select Type Contributed and install the esp8266 platform. This project was compiled using the ESP8266 version 2.2.0. Later versions well be better but may have their own bugs as the platform is evolving rapidly. (e.g. the Arduino ESP8266 board library V2.3.0 has problems connecting to access points so avoid that version.)

Close and re-open the Arduino IDE and you can now select “Generic ESP8266 Module” from Tools → Board menu.

To compile the ESP8266_FanTimer.ino sketch you will need to install two libraries, pfodESP8266BufferedClient library V2.3 and the DebouncedSwitch library V3.0.

  1. Download this pfodESP8266BufferedClient.zip file to your computer, move it to your desktop or some other folder you can easily find

  2. Then use Arduino 1.6.5 IDE menu option Sketch Import Library Add Library to install it.
    (If Arduino does not let you install it because the library already exists then find and delete the older
    pfodESP8266BufferedClient folder and then import this one)

  3. Stop and restart the Arduino IDE and under File->Examples you should now see pfodESP8266BufferedClient.

Do the same for the DebouncedSwitch.zip V3.1 If you have previously installed the pfodESP2866WiFi library, delete that library directory completely.

To program the board, connect the USB to Serial cable as shown on the schematic. Add a shorting link to the Programming Link and apply power to start up the ESP8266 in flash programming mode.

Then click the Arduino download button to compile sketch and download it to the ESP8266-01. The relay will click a number of times as it connected to the Rx line. Once the download as started you should remove the programming link. When the download is completed, the board reboots in normal operating mode and you can open the Arduino IDE serial monitor (set to 115200 baud) to see the sketch's debug messages if you uncomment the
#define DEBUG
line near the top of the sketch

Once the board reboots, the relay should turn on for 10 secs and then turn off. You can test the software by shorting out the Testing Link to simulate AC power being applied to the opto-isolator. Follow the Fan Timer Operating Instructions to test out the various functions.

Final Testing

Once you have completed the software programming and testing using a 5V supply, you can seal up the enclosure and do a final test using AC power before installing the timer in the roof space.

WARNING – Mains Power can Kill You. Do not apply Mains power unless the enclosure is completely sealed and all the plugs and sockets are connected and closed.

To test the timer, plug it into a double power point, starting with both switches off, and plug a lamp into the controlled plug base (socket) as shown below.



Turn both switches off and then turn on the AC power switch, the one with the twin core power cable. The lamp should go on for 10 sec and then turn off. Next operate the other power switch to simulate turning the ceiling light on and off. This should operate the fan timer as per the operating instructions.

Installation

WARNING – Mains Power can Kill You or Catch Fire
This project changes the use of the existing mains wiring in your house. You need to get an electrician to do these house wiring changes.

After final testing, you can arrange for an electrician to install the timer in your ceiling. Here is a schematic of a typical existing two switch light / fan installation (pdf).



Installation consists of replacing the double wall switch with a single one and adding a power plug base (socket) connected in parallel with the light.

When the double wall switch is replaced with a single the power leads that used to control the fan are just connected together so that the existing Fan Plug Base is now always powered. This Plug Base is use to supply AC power to the timer. The extra plug base (socket) connected in parallel with the light provides the Active signal input to the timer to let it detect when the light is on and off.

Here is the circuit with the timer installed (pdf).

Preparing for Failure

Once the timer is installed and running correctly the most likely source of failure is one of the capacitors in the power supply. If the fan does not appear to be working correctly, the first thing to do is to reset the Fan Timer.

Resetting/Testing the Fan Timer

Turn off the light switch and then turn off the mains power for 20 seconds.
Then turn the mains power back on and the Fan should start running and turn itself off after 10 secs.
Resetting the Fan Timer does not change the set time or the hotspot name that has been configured.

If the fan does not start running or does not turn off after 10secs then the timer is faulty. Using the plugs and sockets installed, you can quickly take down the fan and un-plug the timer and plug the fan into the extra plug base connected in parallel with the light base. This will then turn the fan on and off with the light until you can repair and re-install the timer.

Conclusion

This Fan Time retrofit is simple to configure via a web page and includes a manual override to switch off the fan if needed. The installation is straight forward and if the timer fails it is easy to revert to a fan that just turns on and off with the light.



AndroidTM is a trademark of Google Inc. For use of the Arduino name see http://arduino.cc/en/Main/FAQ


The General Purpose Android/Arduino Control App.
pfodDevice™ and pfodApp™ are trade marks of Forward Computing and Control Pty. Ltd.


Forward home page link (image)

Contact Forward Computing and Control by
©Copyright 1996-2020 Forward Computing and Control Pty. Ltd. ACN 003 669 994