Almost a decade ago I made a PIC micro controlled staircase light timer. It has been working really well ever since and now time has come to upgrade it. This time I designed it around the ESP8266 WiFi module as most of my other projects these days. Having WiFi in the staircase timer allows it to be managed remotely and it also ties in nicely into my home automation system. Watch this space.
While getting a face lift, the device also got some cool new functions added which I will show below.
These are the requirements/goals for the new unit that I set up before starting the project:
- Just like its predecessor, it should be an install and forget type device. The previous unit worked almost 10 years without a hitch. I am hoping this new one will rise to the challenge!
- It should require no new cables installed in the staircase or anywhere else, i.e. it should be drop-in compatible with the previous unit.
- It should take, as an input, one of the many push buttons installed on every floor to start the staircase lights for a specified time interval after which it should switch them off.
- At or around sunset it should switch on the light right above the entrance so that people arriving home at night can find the keyhole easily. Also, at or around sunrise this entrance light should switch off. Until now the entrance light was switched on and off manually resulting in not having it on many times at night and forgotten on during the day. An automation should fix this.
- All the settings should be done remotely either through built-in web pages (like routers) and/or through MQTT so that it could become an integral part of my home automation system.
- It should work with no internet connection, it should depend on no third party service. As long as there is electricity it should work.
- The unit should be expandable in the future without having to start from scratch.
For this project I didn’t have to design a separate circuit. Instead, I borrowed two PCBs from other projects of mine: A control circuit with the core components and an I2C expansion board with 4 high voltage (mains) input and 4 relays capable of switching high voltage, low current (up to 10A). Repurposing existing designs meant a much faster development cycle as I didn’t have to order and wait for new PCBs.
The circuit can be powered by any decent smart phone charger through a USB-B mini socket. The ESP12-F module handles all the WiFi communication, has a built-in web server for remote administration and handles all the inputs and outputs via I2C on the daughter board using only 2 GPIOs.
The I2C expansion board uses a PCF8574 I2C expander chip so that the ESP12-F module can handle all the digital inputs and outputs needed using only 2 GPIO pins. I designed these boards sot that in the future they can be expanded with further similar boards if needed without having to redesign everything from scratch. Up to 8 of such boards can be connected to the controller board. These expansion boards can be simply daisy chained and only the firmware needs to be updated.
The high voltage inputs are electrically isolated by opto-couplers. I used a PC847 chip to save place as it contains 4 PC417 opto couplers in one package. The resistors limiting the current for the LEDs in the opto couplers are high wattage ones so that in the event of one of the push buttons breaks down in the staircase and remains a permanent short, they can dissipate the excess heat.
Parallel to the opto couplers I also fit a momentary push button for testing purposes.
I roll my own firmware on this device, which is available to anyone willing to try it out. The firmware is based on my ActoSenso platform, modified to suit the hardware setup of this device.
Some of its features are:
- Serial debugging
- Built-in web server for setting light parameters (like how long the staircase lights should be on after a button was pressed, how much before/after sunset/sunrise the external light should come turn on/off, etc)
- Uses MQTT which makes it compatible with any home automation system that uses MQTT.
- Can be controlled (its settings changed) via its web interface as well as via MQTT.
- Error and event logging through MQTT.
- OTA updates through wifi.
- Does not rely on Internet nor any third party services.
Sample pages from the web interface:
Using repurposed hardware modules from previous projects I managed to accomplish all design goals set out at the start. If new peripherals need to be sensed/controlled in the future, I only have to update the firmware and connect a few new cables to the unit.
Finally, a screenshot showing how it looks in my home automation system: