Menu

Timer on a microcontroller with one button. Household timer on a PIC microcontroller

All about roses

This is a circuit of a simple timer built on a PIC16F628A microcontroller and an LCD 1602 indicator. The idea for the timer was borrowed from a Portuguese site on radio electronics.

The PIC16F628A microcontroller in this circuit is clocked from an internal oscillator, which is quite accurate for this case, but since pins 15 and 16 remain unoccupied, an external quartz resonator could be used for greater accuracy.

Timer on PIC16F628A. Description of work

As mentioned earlier, this project is based on an existing project, but in fact both designs are different from each other, and therefore the code was almost completely rewritten. The timer has three control buttons: “START/STOP”, “MIN” and “SEC”

  1. “START/STOP” - to start and pause the timer.
  2. “MIN” - to set the minutes. The number of minutes is set from 0 to 99, and then everything starts again from 0.
  3. "SEC" - to set seconds. The second is also set from 0 to 59 and then again from 0.

Pressing "MIN" and "SEC" simultaneously will reset the timer during operation.

When the timer reaches 00:00, a beep sounds (3 short beeps and 1 long beep) and the HL1 LED lights up. An electromagnetic type buzzer is used as a sound emitter. After this, when you press one of the buttons, the timer is reset and the HL1 LED turns off.

When the timer is counting down, pin 13 (RB7) is high, and when the timer stops, a logic low level appears. This pin can be used to control external actuators. The timer is powered from a stabilized source.

Jumper J1 is designed to calibrate the timer. When it closes, the timer enters setting mode. Using the "MIN" and "SEC" buttons you can increase/decrease the value of the internal parameter, which allows you to slow down or speed up the timer. This value is stored in the EEPROM. If you press the START/STOP button while in this mode, this parameter will be reset to the default value.

The code is written and compiled with mikroC PRO for PIC.

Project parameters:

  • Generator: INTOSC
  • Oscillator frequency: 4 MHz
  • Watchdog: disabled
  • Power-up timer: enabled
  • RA5/MCLR/VPP: disabled
  • Brown-out: enabled

Photo of the finished timer.

Sometimes you just need to set a time interval, without much microscopic precision. For example, for cooking, where the error is a few seconds per half hour, the hour does not play an important role. Based on these considerations, an internal RC oscillator was selected as a clock generator. The stability of which depends on temperature and changes in supply voltage, since the microcontroller remains operational at a voltage of 1.8-5.5 V. I used a 3-volt battery (or 2 cells of 1.5 V each) as a power source.

The goal was to simplify the design as much as possible with a minimum of external parts and control and display elements (as simple as possible). The program is written in assembler in AVR Studio.

There are a pair of buttons to control timer modes. The first “SET” is for setting the time interval, the second “RESET” is for resetting at any time if you need to “replay” the situation and set a different time interval. And also an audible buzzer, as an audible indication of the state of the timer at different periods of operation.

The timer is made with a minimum 5-minute discrete interval; you can dial as many such intervals as you like (up to 255) if you hold the button pressed.

Schematic diagram of a kitchen timer:

After releasing the button, the timer starts and counts down. The timer has a sound indication (eyes and hands do not participate in control, only hearing), when installed, it “beeps” as many times as you need to dial 5-minute intervals. For example: you need an interval of 30 minutes, which means you need to press the “SET” button and hold it down, dial “beeps” 6 times and release the button. From the moment the "SET" button is released, the LED indicator lights up, indicating that the timer has started, and goes out only at the end of the entire cycle, also from the moment it starts, the countdown begins, the buzzer "beeps" after the next discrete 5-minute interval so many times how many of them are left before the full timer cycle ends. And when the entire cycle is completed, at the end of the cycle a long “beeping” signal sounds for about 10 seconds, signaling the end.

After this, the timer goes into standby mode by switching to the sleep command into the energy-saving Power down mode where the current consumption is less than a microampere. The program uses an internal RC generator whose clock frequency is selected at 128 / 8 kHz.


A simple kitchen timer that can protect your kitchen from excessive smoke. An ideal gift for March 8th.
The timer allows you to set the time from 1 to 99 minutes, the countdown starts automatically, 3 seconds after setting.

Device diagram:

The basis of the device is an ATMega8 microcontroller with an external 16 MHz quartz. The Zas connector is used to power the device; it is supplied with a constant voltage of 7-15V. The 5V supply voltage is provided by the L7805 linear stabilizer; if you use a stabilized source of 4.5 - 5V, such as a mobile charger, then the stabilizer, C3 and C4 can be excluded.
Buzzer B1 and display anodes W1 are controlled by transistors T1 - T5. Resistors R9 - R16 are needed to limit the current flowing through the display segments. A programmer is connected to the Prog and R(reset) connectors, and a keyboard or buttons are connected to the Sw connector. There are only 5 buttons, four of them are responsible for setting the time (+1, +5, +10 and +20 minutes, respectively) and one for resetting the timer.

Printed circuit board:


List of components:

U1 ATmega8A-AU 1pc
U2 Linear stabilizer LM7805CT 1pc
T1-T5 Bipolar transistor BC556 5pcs
C1, C2 Ceramic capacitor 22 pF 2 pcs
C3 Electrolytic capacitor 100 uF 1 pc.
C4 Electrolytic capacitor 47 uF 1 piece
R1-R8, R17, R18 Resistor 3.3 kOhm 10 pcs
R9-R16 Resistor 330 Ohm 8pcs
W1 seven-segment indicator AF-05643FG-B (or with similar pinout) 1 pc.
B1 Buzzer with generator 1pc
X1 Quartz crystal 16 MHz 1pc

Photo of the finished device:


I propose to repeat a simple scheme of a household (kitchen) timer for 99 minutes of my own design. The idea was to make it easy to use, so that literally any (stupid) housewife could use it without any problems. Simply dial 2 digits for the minutes and press the "Start" button. If necessary, you can set the seconds. There is also a hidden “service menu”, where several features are “hidden” - display of forward/downward time countdown when the timer is running and several different options for light and sound effects at the end of the time countdown. Another feature of the timer (though only at the controller programming level) is the ability to select an option for controlling the RC5 leg - the appearance of “1” on it either during the counting of time, or after the end of the counting. This leg can be used, for example, to control the load or in any way you wish. In my version, I turned on an additional sound amplifier at the end of the count.

At the beginning I developed the "design" of the scoreboard. The timer uses a 2-digit indicator with a colon on the left, and 6 LEDs are located around it. When counting down time, they show tens of seconds, and when the counting ends, they depict a running fire. The colon also serves as a visual mode control. When setting the time in minutes mode, it is off, and in seconds mode it is on. When the timer is started, the countdown begins. If the time is less than one minute, the indicator shows seconds and the colon is constantly lit. When more than a minute has passed, the minutes are displayed on the indicator, and the colon begins to blink. Tens of seconds, as I wrote above, are shown by the LEDs. Now, when reading this text, it seems that everything is too complicated, but in reality everything is very simple and logical.

Since I intended to build this timer directly into the wall, I supplied it with power from the network with a real switch. No sleep or standby modes! I don't like them. Only complete shutdown! The power supply is the simplest switching one, similar to a Chinese charger. I didn’t strive for particular accuracy, since for preparing all kinds of culinary products, accuracy even plus/minus a couple of minutes is not so critical. And I didn’t have a standard stopwatch either. By eye, when setting the maximum interval to 99 minutes, there was practically no difference compared to the “reference” clock. Well, maybe there was about half a second there, but it’s difficult to track it by eye. So if you are satisfied with everything, you can start replicating the device. Here is his diagram:

During the MK firmware update, jumpers JP1 and JP2 are removed. To save space, keys VT5, VT6, VT9 and VT10 are not shown in the diagram. The indicator was taken from an old computer case. It uses the left 1 as a colon. Only during final assembly these segments need to be painted over a little to make 2 dots (I simply covered the unnecessary areas with black electrical tape). Another feature of this indicator is that the segments of this left unit are connected in series within the indicator and are displayed as an H segment (comma) from the second digit. Therefore, note that the value of R22 is less than that of the resistors for other segments. In general, you can simply use a regular 2-digit indicator and 2 series-connected LEDs for the colon. I took this indicator simply because I already had it. Just in case, I'll give you the pinout.

Setting the time is as follows. By default (when turned on), the timer is in minutes input mode, and the colon is disabled. Use the number buttons to dial in the required minutes and press the “Start” button (S12 according to the diagram). The entered numbers shift to the left as you press, which numbers on the indicator are lit - the number of minutes currently set. For example, if the indicator lights up 23 (23 minutes are set), but you need to set 6 minutes, then simply press “0” and “6”. If you need to set the seconds, press the “Sec” button (S10 according to the diagram), and the colon lights up. We set how many seconds we need in the same way as minutes. If the dialed number is longer than 59 seconds, the highest digit begins to blink, symbolizing an error, and is reset to 0. The timer can be started from either the minutes or seconds mode. After starting the timer, you can stop it ahead of schedule by pressing the "Start" button again.

In the circuit diagram on the left you can see connector X3 with the inscription "Out". This is the same output for controlling something that I wrote about at the beginning. In the initial state there is "0". At the programming stage of the MK, you can set when level “1” will appear there - during the time countdown or at the end of the countdown and before the timer returns to its original position. This is set in the EEPROM data memory, in cell at address 0x2105 (square 1 in the figure). By writing the value 0x01 there, the output will be logical "1" while the timer is running. By writing 0x00 - after the end of the countdown. Here is a screenshot of the program when programming the MK.

At address 0x2107 (square 2) is the value of the correction number when counting time (lag - decrease, hurry - increase). It is advisable to change the number within small limits and it is better not to touch it unless absolutely necessary. Do not put numbers equal to 0 and 0FFh. At address 0x2109 (square 3) there is a number that determines how many minutes the sound signal will sound at the end of the countdown, if the timer is not reset to its original state by pressing the button.

As I wrote above, you can, for example, connect a load control unit to the “Out” output according to this scheme.

If the load is not very powerful (several tens of watts), the thyristor does not even need to be placed on the radiator. During the experiments, I connected a 25W incandescent lamp and all the parts were as cold as a corpse.

Since I didn’t need to control anything, and the timer was intended to count time when cooking, I connected an additional “amplifier” with a piezo speaker from the phone to this output to increase the volume of the signal when the timer was triggered. It turned out quite loud, and the signal can be heard in any corner of the apartment.

Those. the "Out" output turned on the power to the "amplifier", and the sound signal itself was taken from the output of the PIC for the small speaker. It turned out that when you press the buttons to set the time, only the small speaker beeps, and when the timer goes off, both speakers beep at once. This additional amplifier is assembled on a separate board.

The timer itself is assembled on a double-sided printed circuit board drawn in . The archive is attached at the end of the article. The board is wired for PIC in a TSSOP package with a pitch of 0.65mm.

Photo of the board in the process of assembly/debugging.

To power the timer, I used a simple switching power supply, assembled according to this circuit (I took the circuit itself ready-made somewhere on the Internet). There is no point in writing about it in detail here, because this is a topic for a separate article about switching power supplies. I will only provide data on the winding of the transformer. The frame itself of a suitable size is taken from an energy-saving lamp or from a burnt-out Chinese power supply unit. It can also be torn out from the duty circuit of a computer power supply or from a monitor, but they will be slightly larger in size. To easily disassemble the frame and core of transformers, I dip them in boiling water for 3-4 minutes and then carefully, without much effort, disassemble them. Next, we remove all the old windings and wind new ones. Windings: 1-2 - 600 turns with a diameter of 0.08 - 0.1 mm; 3-4 - 23 turns with a diameter of 0.3 - 0.55 mm; 5-6 - 10 turns with a diameter of 0.08 - 0.1 mm. Winding 1-2 wound in bulk, the rest turn to turn. All windings must be well insulated from each other. When winding, observe the direction and beginning of the winding at points. The two halves of the W-shaped cores are joined through an insulating gasket (air gap ~ 0.1 mm).

But you can do it easier by taking any ready-made Chinese power supply with an output voltage of 8-9 volts.

A few photos of the case being made (small workshop). Particular attention was paid to the design of the display.

Well, the finished device is assembled.

And finally, about the “service menu”, which was mentioned at the beginning of the text. If you enter “1”, “1”, “1”, “1”, “1” and “Start” from the seconds setting mode, then using the “1” and “2” buttons you can select a forward or backward countdown. The indicator will show " Cu" (Count Up) or " Cd" (Count down). Exit the menu and save the settings in EEPROM with the "Start" button.

If you type the sequence “2”, “2”, “2”, “2”, “2” (also from the seconds setting mode) and “Start” - using the buttons “1” - “4” you can select one of four sound signal options when the timer fires. The indicator will show " A1" -"A4" (Alarm). Exit with saving settings in EEPROM using the "Start" button.

By typing “3”, “3”, “3”, “3”, “3” and “Start” using the “1” - “4” buttons, you can select one of four options for the “running light” of circular LEDs when the timer is triggered. The indicator will show " E1" -"E4".

By typing “4”, “4”, “4”, “4”, “4” and “Start” using the “1” - “4” buttons, you can select one of four options for blinking seven-segment indicators when the timer is triggered. The indicator will show " L1" -"L4".

The archive contains timer and power supply boards (if anyone needs them) and controller firmware. The fuses are already specified in the firmware, nothing needs to be changed. On the timer board there are several 0.1 µF ceramic capacitors for power supply, not shown in the circuit diagram. There are also a couple of parts designated FB (ferrite bead) - these are simply so-called ferrite beads used as jumpers.

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
IC1 MK PIC 8-bit

PIC16F636

1 To notepad
IC2 Encoder, decoder

SN74LS155A

1 To notepad
IC3 Shift registerK561IR21 To notepad
IC4 Linear regulator

L78L05

1 To notepad
VT1-VT3, VT13 Bipolar transistor

KT3107BM

4 To notepad
VT4-VT12 Bipolar transistor

KT3102BM

29 To notepad
D1-D4 Rectifier diode

1N4148

4 To notepad
Q1 Quartz resonator20 MHz1 To notepad
C1, C2, C4 220 µF3 To notepad
C3, C5, C8 Electrolytic capacitor100 µF3 To notepad
C6, C7 Capacitor22 pF2 To notepad
C9 Capacitor0.1 µF1 To notepad
R1-R3 Resistor

1 kOhm

3 To notepad
R4-R6 Resistor

680 Ohm

3

This microcontroller timer circuit PIC16F684 allows independent selection of the moment to turn off and turn on the load. A distinctive quality of this timer is the use of a SoG LCD indicator with a built-in serial interface.

Description of the operation of the timer on the microcontroller

The indicator has 8 seven-segment digits. The time display starts with four digits in the middle. Hours and minutes are separated by a decimal point. Indication of whether the timer load is on or off is displayed on the right side of the indicator (0 – off, 1 – on)

All timer control is carried out using 4 buttons. If you press and hold the “Install” button for 2 seconds, the installation mode is activated. First, the real time (hours and minutes) is set. After setting the time, you must click on “set” once

To set the on and off time of the microcontroller timer, you must press the corresponding button. Also, after selecting the required value, you must click “install” once.

The microcontroller operates from a built-in RC oscillator with a frequency of 8 MHz. The internal clock circuit operates from a 32768 Hz quartz oscillator. The microcontroller is in sleep mode most of the time, so the average current consumption is approximately 5...7 µA.

IRLML2502 (BSS138) is used as a key. Tactile buttons are arbitrary. Other SMD radioelements. Plug for programming the PLS5 microcontroller with pin numbering as in PICKit2.