DIY Digital Clock with Temperature Display using PIC Controller

jojo December 31, 2014 6 Comments

One of the most enjoyable part of being an electronics person is creating your own gadgets and using them in daily life. In this article, we are building one of those with the help of SoloPCB design tools, a digital desk clock with temperature display feature.

Digital Desk Clock with Temperature Display


The brain of the circuit is a Microchip PIC18F252 microcontroller. It acquires precise time information from DS1307 real time clock via I2C interface and displays it on four digit 38 mm seven-segment display with the help of MAX7219CNG display driver. The temperature data is read by the on-chip ADC module of the microcontroller from LM335 temperature sensor which outputs 10mV per kelvin degree linearly. The temperature data is also displayed periodically.

The PIC microcontroller and the peripheral ICs mentioned above needs 5V regulated supply to operate. The step-down converter in the power section of the circuit, LM2574N-5.0, converts 12VDC input voltage to 5VDC and lets to draw 500mA without any significant heating problem.

There are two LEDs on the board indicates power and functional status and the buttons let the user adjust the time and display the temperature manually.

The Circuit and the PCB Design

The circuit and the PCB of the project are drawn in SoloPCB. SoloPCB is a very powerful tool which integrates the circuit design to the PCB design and the fabrication. You can download SoloPCB from FabsSream for free. The circuit and the PCB files of the project are provided in SoloPCB format. You can download the design files including the symbol and the footprint libraries by using the download link below.

Download Design Files

The following video demonstrates how to import the project libraries, open and synchronize the schematic and PCB files.

There are also video tutorials available in the Videos category showing how to use the SoloPCB tools.

The circuit schematic of the digital desk clock and a screenshot from its PCB can be seen below.

Digital Clock Circuit using PIC Micro Controller


After the PCBs fabrication, the components listed below are assembled on the board.

Bill of Materials:

Quantity Part Description Designator
1 CR2032 Battery Holder B1
1 22uF 16V Tantalum Capacitor C1
1 10uF 16V Electrolytic Capacitor C10
1 220uF 16V Electrolytic Capacitor C2
5 100nf 63V Ceramic Capacitor C3 C6 C7 C8 C9
2 22pF 50V Ceramic Capacitor C4 C5
1 MBR-150 1A 50V Schottky Diode D1
1 3mm Red LED D2
1 3mm Green LED D4
1 LM335 Temperature Sensor D3
1 BAT42 200mA 30V Schottky Diode D5
1 DC-001 Power Connector J1
1 1×5 2.54mm Male Header J2
1 2×4 2.54mm Male Header J3
1 150uH 850mA Inductor L1
4 38mm Common Anode 7 Segment Display LD1 LD2 LD3 LD4
3 330R 1/4W Resistor R1 R2 R11
6 10K 1/4W Resistor R3 R4 R5 R7 R8 R10
1 2K 1/4W Resistor R6
1 27K 1/4W Resistor R9
3 SPST-NO 6mmx3.5mm Tactile Switch SW1 SW2 SW3
1 LM2574N-5.0 0.5A Step-Down Converter U1
1 PIC18F252-I/SP Microcontroller U2
1 28 Pin DIP Socket 300mil U2 Socket
1 MAX7219CNG 8 Digit Display Driver U3
1 DS1307+ Real Time Clock U4
1 32.768KHz Crystal Y1
1 10Mhz Crystal Y2


All the components are through hole type so there is no need for a very good soldering skill.


The assembled board can be seen below.


The following sections explains the circuit operation in more detail.

The Power Section

We will use a 12V AC-DC power adapter to power the board. We need to convert 12VDC to 5VDC level that the ICs need and supply the required amount of current to the components. Not to deal with the heating problems, we should use a step down DC-DC converter. We choose LM2574N-5.0 fixed 5VDC step-down converter which can provide up to 500mA continuous current. LM2574 supports wide input range up to 40VDC and provides high efficiency. It requires only two capacitors, one power inductor and one Schottky diode as the external components.

It is always a secure way to assemble the power section first and test its output during the first design validation of the circuit. By this way the remaining sections won’t be affected due to any power section failure.

A 3mm LED is connected to 5VDC output of LM2775 through a current limiting resistor to indicate the power on status.

The Microcontroller Section

The circuit is built around Microchip PIC18F252 microcontroller. Mainly it communicates with the real time clock, display driver and the temperature sensor via digital I/O and analog input ports and displays the gathered information on the seven-segment displays. It also gets the pre-defined user commands such as adjusting the time and displaying the temperature via the push buttons.

There are some essential connections and external components that must be considered while building the circuit. First of all a crystal oscillator should be connected to OSC1 and OSC2 pins with 22pf ceramic capacitors coupled to ground. PIC18F252 supports up to 16MHZ input clock. To be able to function the MCU at the highest speed, we can use a 10MHZ clock and activate the Phase-Locked-Loop (PLL) module of the MCU which quadruples the clock frequency.

Another essential connection is connecting the MCLR pin to VDD, namely +5VDC in this circuit. A 10K pull up resistor is used for this connection. A pushbutton which is connected between the MCLR and the GND can be used as the reset button.

A bypass capacitor has a value of 100nF is also an essential component for the input power line of the MCU. It should be connected as close as possible between the VSS and the VDD pins. If it is not connected, the MCU will reset itself due to lack of instant current which cannot be drawn due to the inductance of the power line. Using a bypass capacitor will provide the required charge with low inductance since it is very close to the microcontroller.

The microcontroller should be programmed frequently while developing Its embedded software. It is really difficult to unmount and then mount the MCU after programming. To solve this problem, In Circuit Serial Programming method is used to program the MCU while it is mounted on the board. MCLR, VDD, VSS, PGD and PGC pins of the MCU should be extended to an ICSP connector for this purpose. But there is a trick that should be considered while doing this. Not to power the rest of the circuit while ICSP, a Schottky diode should be connected between the main supply and the VDD pin. So diode will prevent powering the whole circuit by using the programmer’s supply. You can find more information about ICSP in this document.

The Real Time Clock – DS1307

Real time clocks are integrated circuits which can provide the current date and the time information. They can precisely update the time by using the clock input which is generally 32.768 kHz. We use DS1307 RTC IC for this purpose. It communicates via I2C protocol. It can provide second, minute, hour, day of the week, month and the year information. It supports 12 and 24 hour formats.

To be able communicate via I2C, we need to connect two inputs of the PIC to the SCL and the SDA pins of DS1307. Those lines should be pulled-up to 5VDC supply via resistors which are 10K in our circuit.

One of the most important feature of DS1307 is continuing to run while the circuit power is off. Of course a backup supply is needed to power the IC in this case. A CR2032 cell is mounted by using the appropriate battery holder for this purpose and it is connected to the battery power inputs of DS1307.

The Seven Segment Display Driver

We use four 38 mm seven segment displays to show the time and the temperature. To make it easier to control the displays with the microcontroller, we use MAX7219 display driver IC which communicates via SPI interface. It can drive up to eight seven-segment common anode displays. An external resistor is used to limit the LED currents.

There is only two bypass capacitors and one current limiting resistor as the external components. The current limiting resistor is 27K to limit the each segment current to 20mA. In 37mm displays, there are two LEDs for each bar segment. But the dots have only one led inside.

The Temperature Sensor

LM335 is a zener type temperature sensor which has a variable reverse breakdown voltage depending on the temperature. The voltage that can be measured between the positive and the negative terminals is 10mV/kelvin. For example when we read 2980mV, this means 298 kelvin degrees and when we convert it, we can easily find 298-273 = 25 centigrade degrees. We use the 10 bit ADC module of the microcontroller to read this analog data, then convert it and display on the seven-segment LEDs.


The Embedded PIC Software

The embedded software of the project is developed in MikroC for PIC. The source code is given below for download. Please feel free to ask your questions and share your comments by using the comments field below.

Download Program/Code for Digital Desk Clock


  • September 1, 2015

    Great website. A lot oof useful information here. I’m sending it to a few friends ans also sharing in delicious.
    And naturally, thanks for your effort!

  • Ramdass
    June 14, 2015

    Is this available in Kit form? If yes, at what cost?

    • jojo
      July 2, 2015

      Ramdass- This kit is not available right now. However we may make the kit available in future. Please visit our store for kits and modules.

  • MH
    January 22, 2015

    Well.. I am regular reader of circuits today. I am engineering student seeking a great information for my final year project. This seems very good and simple project.

  • Avinash
    January 2, 2015

    What is the meaning of DIY …??

    • jojo
      January 2, 2015

      DIY – Do It Yourself

Leave a Reply to Avinash Cancel reply

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