Programmable daily timer




I needed to use a timer, to operate a small mist pump for a small greenhouse, programmable in the following way:

1): active from hours, at hours throughout the day.

2): activation at programmable intervals.

3): Pump active for a specific time.

I threw what I needed on paper:

Summary of timer operation used at the beginning of the project

There are timers with a programmer disc on the market that allow similar programming, but they are not as accurate as I would like, for example I have one that has steps of 15 minutes or 4 selectors every hour. Not what I need.

Then, as mentioned, paper and pen, and I begin to define the main parts that will make up the timer.

PIC: it is exaggerated, it has a lot of flash memory, but adequate number of pins: the proven 16F876 goes well.

LCD: in primis, I thought about the classic 16×2 but then I opted for a 16×4 for a complete display of the set parameters.

There must clearly be a clock that keeps the time even in the event of a power failure.

This is the first problem: I could use the internal EEprom and write hours and minutes to it but when the power returned, the time would be wrong: discarded idea.

Second solution, always keep the PIC powered and reinitialize the LCD at each restart…. You would need a large enough rechargeable battery with the associated problems: discarded idea

In a project from a few years ago, I had used a battery that kept me powered throughout the circuit, but it doesn't seem to me the case: battery consisting of 6 stilo 1,5V, they do not have a great duration. This solution too, rejected.

I have some RTCs in the drawer (Real Time Clock) type DS1307 never used, the time has come to use them.

For simplicity I start looking on the net for examples of use of this RTC and there are many: all, however, have the characteristic that the time and calendar programming, it has to be done in the program then, once completed, it fits into the PIC and from there. I don't like it so I start working on the software so that it can be set during use.

Established everything you need, the project begins to take shape.


After much study SW and HW, as you can see from this first photo, here is the experimental project from which the definitive and working version will be born. I state that for many years I have not made printed circuits anymore but I use the very comfortable base 1000 holes.


This is the main scheme of the project.

Very simple, PIC 16F876 with 4MHz quartz, RTC DS1307 with 32768Hz crystal, CR2032 lithium battery that powers the RTC in the event of a power failure, seven buttons for the various functions and a 12V relay with 10 / 15A changeover to operate the pump.

The PIC stores all the programming made in the internal EEprom precisely the hour and minutes of the start, hour and minutes of the stop or interval within which the timer is active. Then subsequently it stores the cyclical nature of the nebulization in minutes and lastly its duration in minutes. All this happens by entering the MENU2 with the relevant button. I point out, that after programming the Flash of the pic with the .hex file, therefore on first use, TIMER programming MUST be carried out.

Nella EEprom, other parameters are also stored. For simplicity, I calculate everything in minutes (hours x 60 + minutes) to start and stop the timer. Starting from the start, memorized in the EEprom starting from the address 16 (in decimal) this value. Being a WORD variable (2 Bytes) the following storage will take place from the location 18 and so on. The second memorization, will contain the previous value, added to the cyclical time and so on until the stop timer time is reached. Example follows:


Starting from these settings with timer ON from 08:00 all 22:30: nebulization every 30 minutes with time 10 minutes.




As can be seen from the lease 16 (10 in Hexadecimele) we will have the first activation a 480 minutes or hours 08:00 and of course later 10 minutes turns off. The following activation (lease 18) will happen to 510 minutes or at 08:30 per 10 minutes. So on up to the last value 1320 or the 22:00. after which the timer is deactivated.

This information can be clearly seen by looking at the program listing.


Passing all'HW, Q1 is the transistor that will allow the activation of the relay, Q2, on the other hand, allows the display backlight to be turned on. J1 is the ICSP connector used for programming the PIC FLASH without having to extract it from the circuit. Note that at this stage, the power supply of the PIC must be provided by the timer circuit because I do not take it from the PICKIT.

In the diagram I have not shown the power supplies for the LCD: They are the following:



PIN3 : it must be connected to the cursor of a 10Kohm trimmer which in turn is connected between ground and VDD: adjusts the contrast of the characters.

I PIN dal 7 al 10 (D0-D4), they must be connected to ground or left free: the LCD works with bus a 4 bit.

Let's look at the buttons now:

Starting from the left, we find the button Light to turn on / off the display backlight.

Below is the button TIMER which activates / deactivates the timer: the state, is displayed on the second line of the LCD with Ton or Toff. Naturally its toff, the relay will never be activated.

Below is the button Manual. It is used to carry out tests, activate the pump. This command is displayed by the yellow led on the front panel.

Let's continue with two buttons + e that are used during the various programming of the two menus.

The MENU2 O SET TIMER which allows you to enter the programming of the timer times. It works in the following way: premend it, you access the programming of the START HOUR timer. If you don't touch the buttons + e – pressing menu2 again switches to START MINUTES timer. If they don't change, advance with menu2 to STOP HOURS timer. If you don't change, com menu2 continue with STOP MINUTES timer. With menu2 you continue with PUMP EVERY: . This is the cyclicality of actuation then we pass to PUMP PER: which is the duration of the pump on.

MENU2 ends here, but I remember that ONLY at the first start after loading the flash of the PIC, the EEProm is empty so it is necessary to make a change with the keys + e – of one of the values. If a change has been made, all settings are stored in the EEprom including the calculated data from the memory location 16 as described above. I repeat only at the first start.

The button remains MENU1 O Set Clock which is used to set the clock and calendar of the DS1307. The settings are made in the same way as in menu2. First day of the week, then the day of the month, the month and finally the year. Continue with hour and minutes. At this point, at the press of MENU1, the data is sent to the RTC and from there it starts with seconds = 0. This button does not protrude from the container, its use being quite rare.

In the LCD, we also find two other symbols at the end of the third and fourth line: an asterisk * indicates that we are within the START / STOP range. A appears on the fourth line # which indicates the active relay such as the red LED on the front of the container and the one near the exit (D4).


This is the power supply, simple and filtered since it feeds a pump through the relay.

Left, there is the 12Vdc input where I connect a 12V 5A power supply. It continues for two ways, the first through the 6.3A fuse and through the relay (which is the one commanded by the PIC). Below are several FAST diodes to try to eliminate as much as possible the disturbances generated by the activation of the pump. D2 is a double diode in TO220 while D3 I connected it directly to the output connector. The LED D4, serves to indicate with its ignition, that in practice the F1 fuse is not broken. The indication of the active relay, we also got it from the main board and shown on the front panel with a red LED. The second way, starts from D1 and serves to supply the 5VDC for the whole circuit through an LM7805 equipped with a small heatsink. A note to note is precisely the presence of groups D1 and C3 that at the moment of activation of the pump, should ensure that any excessive voltage drop on the power supply does not disturb the PIC.


As for the software I used the Proton basic since I have known the basic for many years, since the days of the ZX80, ZX81, Spectrum, QL, Qbasic for dos and Visual basic for windows

From the following link you can download the file in basic just copy it into the blank page of PROTON and fill it in.

The resulting .hex file, it will be loaded into the PIC with a pickit2 or pickit3 or other device of your choice.

The Proton is a very good program, I have been using it for a short time but I always discover interesting features: allows it to be used FREE for different types of PIC including 16F876. Thanks to Picmicro675 who made me understand the advantages of this program and many very useful functions in programming, not to mention that the compiled takes up less flash than other compilers and is faster to execute: and it is not cheap.

Let's see how the program is structured. The initial part, collects all the setting parameters of the PIC and the devices used and the definition of the variables used. The use of interrupts is also enabled, which I used as I will explain later. It clearly starts with the Main which is the main program where all the commands that are executed are described. First, the sub is called INIT section where registers and variables are initialized then you start by reading the DS1307, the keys and you act accordingly. There are many subs that process the data they are given and return the results. We have below the sub to set the timer: here is a variable “modification” which is set (=1) if any data is modified and consequently all the relative data is stored, nella EEprom. Below is the sub to set the clock / calendar similar to the timer setting. We have thus come to the section that manages interrupts. I had to use two of them and precisely one that reacts to the pressure of one of the keys connected on the B port 4 a 7. The second one, relative to the RB0 that hears the pressure of the button on the door B. 0. With these two interrupts, I manage the switching on of the display backlight. By pressing a button on ports b4-7, I use the TIMER1, to generate an interrupt every 100mS : counted 10 interrupt, i get 1 according to what I use for a timing of the backlight counting 60. The button on Portb0 instead, I use it to turn the backlight on or off without timing. Finally, there are two tables for converting from number to day of the week and the second from number to month.


Here is the completed project:

Internal view: you can see the connectors for the display and the one for the front buttons and LEDs. Down, the stabilizer and the relay. Above the relay the CR2032 battery.





Below is a rear view of the display, keyboard and led


Internal view of the components side








Welding side: down, note that little ring (pulp) made with wire for wire-up, serves to give greater quartz shielding of the RTC.

For yellow labels: I created them with Excel with various attempts for the size and centering of the characters. Then I cut them out, double-sided tape to attach them to the container and transparent tape to protect them.




Assembly completed, job done. I hope I have not annotated anyone, and I also hope this project can be useful.


6 replies
  1. piero55
    piero55 says:

    Thanks Giuseppe.
    I agree with you about the accuracy but I think it may be acceptable. I mounted two as you can see in the photos, one on a breadboard and the other “boxed”. I have been keeping them on for several days and I see that the accuracy is acceptable, I check them with radio controlled clocks. Then, being fixed with the “recycling” of the components, I used what I have in the drawers.
    Thank you, Pierluigi

  2. Giuseppe
    Giuseppe says:

    Congratulations on the realization of the project . Check the Ds1307 could bring a time error caused by the crystal drift.
    For greater accuracy you can use for those who want a DS3231 .

  3. piero55
    piero55 says:

    And, we had also thought about the hygrometer, but at the moment it was not needed. Anyway, there is space for both HW and SW, I'll think about it.

  4. Picmicro675
    Picmicro675 says:

    A practical timer with customized periods. A really nice project.
    For the construction, mounting on a multi-hole with fast assembly routing is also suitable. If it were a project that required greater compactness, then you can think of those made by professional services.
    Then saw the purpose of humidifier, you could add a humidity sensor.

  5. piero55
    piero55 says:

    I enjoy doing these projects, I don't make them for work so I don't waste time on the printed circuit. I stopped about twenty years ago when I made them with double-sided photoengraving. Then I was no longer able to find quality presensitized fiberglass: they were no longer good so I quit. I have everything I need, but I don't take it anymore.

  6. Amilcare
    Amilcare says:

    Original project, complete in every part and easily replicable.
    Only a small flaw is the realization on millefiori which does not make the realization professional.
    Between us who cares, they have all the elements to get it printed on them. When I have to free my mind as in these days I also try complex creations on millefiori. One way to “unplug” and keep other thoughts away.


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply