Electronics ru
Advanced Search +


Programmable digital timer switch using a PIC Microcontroller


Digital timer switches are used to control the operation of electrical devices based on a programmed schedule. This project describes a programmable digital timer based on a PIC16F628A microcontroller from Microchip that can be programmed to schedule the on and off operation of an electrical appliance. The appliance is controlled through a relay switch. This timer switch allows you to set both on and off time. That means, you can program when do you want to turn the device on and for how long you want it to be remained on. The maximum time interval that you can set for on and off operation is 99 hours and 59 minutes. The project uses a 16×2 character LCD with 4 push buttons to interact with the user.

Programmable digital timer switch using a PIC Microcontroller

Circuit Design

The circuit diagram of this project is shown below. A 5 V relay is driven by a PN2222 transistor that is controlled by RB3 pin of PIC16F628A. Digital inputs from the 4 push buttons are read through port pins RA2, RA3, RA4, and RB0. The functions of these push buttons are discussed in the operation section below. A standard 16×2 character LCD is used in the project to display the the device status, program menu and time. The LCD is operated in 4-bit mode, therefore, only 6 I/O pins of PIC16F628A are required to drive it. A piezoelectric buzzer provides audible tone when the timer is started and stopped. It also beeps when the device is turned on or off. The + 5V power supply for the circuit is derived from a LM7805 regulator IC. The input to the regulator is given from a 9V DC wall adapter.

Digital timer switch: Schematic Diagram
Click to enlarge

Схема питания для цифрового таймера на PIC16F628

In the circuit diagram, the pins 15 and 16 of the LCD are shown open. These pins are available only in those LCDs that have a back light illumination LED. The pins 15 and 16 are the anode and the cathode of the LED. If your LCD has the back light LED, you can connect these pins to the power supply terminals with a 39 Ω resistor in series. The backlight LED enhances the readability of the LCD display in low illumination condition.

The complete circuit soldered on a general purpose prototyping circuit board is shown below.

omplete circuit soldered on a general purpose prototyping circuit board

Operation of the timer

The timer gets inputs from the 4 push buttons. Their functions are described as follows:

  • ON/OFF TIME : This timer device allows you to set both on and off time. When the timer is initially powered on, the device is in off condition and both on and off times are 0. Pressing this button, you can switch between the on and off time on the display.
  • SELECT : This allows you to select between the on and off time settings as well as hour and minute digits. The selected digit is incremented by pressing the ON/OFF TIME button.
  • ENTER : When the appropriate hour and minutes are selected, pressing ENTER finalize the corresponding on or off time.
  • START/STOP is to start or stop the timer. If the timer is already on, you can stop it at anytime during its operation by pressing this button.

Now lets see how it works. Suppose, the device connected to the relay switch is needed to be turned on after 2 minutes. Further, once it is turned on, it is required to be on for next 20 minutes. In this case, the off time is 00:02 and the on time is 00:20, in hh:mm format. Once the timer is started, the device will be turned on after 2 minutes and remained on for 20 minutes. After that it will be turned off again. The following video shows how to do this.


The firmware is developed using the MikroC Pro for PIC compiler.

Source Code - download
HEX file - download

You may have to register before you can post comments and get full access to forum.
User Name
Fragments of discussion:Full version of discussion »
  • I'm kinda clueless when it comes to programming, but I know a little. Anyhow, is there a way to modify the source code to run in a on/off loop cycle till the interrupted or power is cut? If so, this is just what I need for my ranch tank fill system so I can fill it without running my well dry and overheating my well pump. thanks in advance.
  • its a great looks simple but the applications are unlimited.hats off to its creator....

News on theme:

Slices ↓
Radiolocman facebook Radiolocman twitter Radiolocman google plus