Staircase Light Timer

We have a timer in our staircase that controls the light after dark: when someone presses a button (a button is located on each floor) the lights light up for a preset period. Lately, the timer in our staircase light has started to behave weirdly – no matter what settings we used, the ON time kept shrinking. By now, not even the fittest can make it after dark from one button to the next while the lights are on. Instead of buying a new timer (for about €5 🙂 ) I decided to make it a learning project for myself, as I have been learning PIC micros for a while now. This way, while learning, I also create something useful – for a price that is about 10-15 times higher… The difference is the price of education 🙂


Most of the hardware parts I purchased online, through eBay although I am sure all the parts are usually available in any local hardware/electronics/DIY shop. The problem form me is that there are no such shops in the vicinity of my home.

This is a non-exhausting list of the components used (apart of the electronic components in the circuit). I may have missed an item or two, but the whole list is fairly obviuos.

  • 1 * plastic box (12 * 15 * 6 cm approx) with metallic parts for wall mounting as the project box. Since dedicated project boxes are ridiculously expensive in my area and/or the shipment is very expensive from abroad, I had to settle for this box that is sold as housing for electrical installations. It’s not airtight and it has a big window on the front which I had to cover with a scrap piece of plexi glass I had lying around. It would certainly look better in a “proper” project box, but it does the job and in normal operation it will be out of sight anyway.
  • 3 * pushbuttons for testing purposes (up, down, test)
  • Assorted cables, connectors as necessary


At the heart of the circuit is Microchip’s 16F628A microcontroller. I chose this microcontroller because it is cheap and I had used this previously for other experiments and had some already.

The 16 (red) indicator LEDs are driven from 3 pins of the PIC using SIPO shift registers (74HC595).

There are also a green LED (power indicator) and a blue LED (state of the relay).

Since most components I used are SMT, I also included an ICSP header on the PCB so that I could program and reprogram the PIC after it has been soldered to the board.

Since I designed the circuit I have changed my mind about a number of things. This is due to my inexperience with the PIC microcontroller. If we need another timer controller in the future, I promise I will correct all the inefficiencies in the circuit, the software and the mechanical layout. For now it is working just fine.


As one of my first projects (learning PIC micros as we speak 🙂 ) the software is not very elegant, to say the least. There are no interrupts used, the microcontroller never sleeps, constantly polling the buttons, etc. I am fully aware of all the shortcomings of it and in any future versions it will be improved. As for now, I was happy that is was working for the first time I put it together.

The software was written in assembly, using Microchip’s MPLAB (it’s not the most user friendly IDE I have seen, but it’s free). The code for the 16F628A can be downloaded from GitHub.


When powering up the device first does self check – it lights up all the indicator LEDs one by one, then turns them off one by one. Then for a few seconds it switches on the staircase lights just to show that the relay works OK and all the connections are satisfactorily.

After the initial self test the device enters a waiting mode. In this mode the user may change the length of the ON time for the lights by pressing the UP and/or DOWN buttons. With each push one indicator LED gets switched on/off. There are 16 LEDs in total. At the moment it is programmed so that each LED means 15 seconds of ON time. This means the lights can be configured to be on for 15 seconds to 4 minutes in 15 second steps. For most scenaria this should be OK, but it can be changed in the firmware.

The user may also press any of the LIGHTS ON buttons in the staircase. This switches on the relay in the circuit (and all the lights in the staircase that it switches) and a control LED (blue). The top indicator LED will start blinking. After 15 seconds the blinking LED stays off and the one next to it (in the direction of 0) starts blinking. This procedure keeps repeating until all the indicator LEDs are exhausted. At this point all the indicator LEDs (until the preset interval) light up, and the relay switches off – switching off the lights in the staircase.

During the countdown process the user can press any of the LIGHTS ON buttons in the staircase resetting the countdown timer to expand the time the lights are on.

Extra stuff

The same circuit with only a slight modification in firmware can be used in various other applications that require similar timing, such as delayed switch off of car/boat/etc. cabin light, car wiper intervalled operation, camera interval shooting, etc.

Possible improvements, future plans…

… or what I would do differently if I had to do it again – in no particular order:

  • I would incorporate the relay on the PCB – this would make the whole device look less cluttered.
  • When the microcontroller is in waiting mode, it should sleep and it could be waken up by an interrupt when a button is pressed.
  • I would use a cooler project box 😉


With the original 12VDC power supply the regulator 7805 IC needed a very large heatsink which I really didn’t like. So I was looking around what else I can do. A few days later I found on eBay a 5VDC and 12VDC power supply in one and a compact size. It’s the one that are used for external hard disks or DVD drives. I just removed all cables and the enclosure that I don’t need, and bypassed the power supply part of my circuit. Now the device works with its own switching mode power supply.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.