Home / Projects / PIC Projects / Adjustable Timer with Relay

Adjustable Timer with Relay

Project Overview

This adjustable timer displays seconds, minutes and hours and is powered by a PIC16F877A microcontroller. There are five buttons included: start/stop, up for incrementing digits, down for decrementing digits, left and right for moving between digits during adjustment. I’ve included a relay circuit which will trigger when the timer is finished.


[the_ad id=”3059″]

A timer is a common project but not really a simple one. Here, I designed a six-digit countdown timer which, when finished, will trigger a relay. The timer can be set to a maximum of 99 hours, 59 minutes and 59 seconds and to a minimum of 1 second. This is useful as a timed switch for appliances or other electrical devices that draw power from mains.

Schematic Diagram

Adjustable Timer with Relay schematic

I wanted to use the least amount of components possible but I also don’t want to make the code too long. Thus, I settled to use one decoder even if it’s possible not to use one. The POV refresh rate is based on timer0 overflow with x32 prescale. This is using a 4 MHz crystal oscillator. Adjust the prescale through the OPTION register if you are using other oscillator frequencies.


[the_ad id=”3059″] The project was coded using Microchip XC8. There are some peculiarities with my code, especially the use of structs. You can actually remove the structs and just use simple variables. I just find the structs more readable given the number of variables I had to use.

I used two interrupts in this code: timer overflow and RB change interrupt. The timer overflow interrupt is used for POV while the RB change interrupt is responsible for starting or stopping the timer. The adjustments are not done with interrupts but by simple button testing. The debounce problem is handled by a delay after every button pressed.

Project Files

Of course, the schematic, code and simulation files are free to download. Just click the link below.

[wpdm_package id=’1981′] [the_ad id=”3059″]

I hope you find this project useful!

Check Also

Digital Thermometer Nokia LCD

Digital Thermometer with Nokia 3310 LCD

The Nokia 3310 LCD is a cheap option for those who want to add a …

Leave a Reply

Your email address will not be published.