This is my first Instructables.
Here I am going to show you how to make Digital clock using Arduino Uno (while final assembling I used Arduino Nano because of its small size). Instead of giving load on Arduino I am using Real Time Clock (RTC) for timing purpose. Great thing about it is using only one shift register. I am using 4 seven segment display. To avoid wiring mess on breadboard i directly connected the seven segment display on the perf board.
Step 1: What Do We Need?
Here is the list of the parts required for building this:
1) Arduino Uno or nano will do.
2) 4*Seven segment displays we are common cathode.
3) RTC module or you can make it of your own as I did.
the parts for RTC module:
a: DS1307 ic
b: 32.768Khz crystal
c: CR2032 coin cell
d: CR2032 battery holder (I used through hole one)
e: 47K ohm *2 resistors (used as pull up resistors)
4) 74HC595 ic shift register.
5) 2*Red leds 3mm.
6) 2*22k ohm resistor used for current limiting.
7) Prefboard one for mounting the displays and other for the circuitry.
8) A plastic project box for fitting in all the parts.
Tools we need for making this
1) Solder iron.
2) Solder wire.
3) Saw or cutting tool.
4) Hot Glue gun.
5) Wire Striper.
6) Digital Multimeter.
Step 2: The 4 Seven Segment Displays
First we need to check whether our seven segment display is so common anode type or common cathode type. For this we will need the Digital Multimeter. Put the multimeter on the continuity mode and connect the positive wire to common pin of the display and the negative wire to any pin of the display if the display glows then it is common anode. Now connect the negative wire to the common pins of the display and positive to any other pins if the display glows then it is common cathode.
Here we are using 4 seven segment displays separately instead of using the 4 digit seven segment. In 4 digit seven segment display all the a,b,c,d,e,f,g pins of one seven segment display is connected to corresponding pins of all other displays. So we will do the same here we will solder all the a,b,c,d,e,f,g pins of one seven segment to all other.
Note: Not to connect the common pins of the all the seven segment display we will need them for selecting the individual displays.
Step 3: Getting RTC Ready.
You can use the RTC module directly or make one for yourself.
A real time clock is basically just like a watch - it runs on a battery and keeps time for you even when there is a power outage! Using an RTC, you can keep track of long timelines, even if you reprogram your microcontroller or disconnect it from USB or a power plug.
Why to use RTC ?
Most microcontrollers, including the Arduino, have a built-in timekeeper called millis() and there are also timers built into the chip that can keep track of longer time periods like minutes or days. The millis() only keeps track of time since the Arduino was last powered. That means that when the power is turned on, the millisecond timer is set back to 0.
Connect the circuit as shown in the schematics. The RTC is an i2c device, which means it uses 2 wires to to communicate. These two wires are used to set the time and retrieve it. On the Arduino UNO, these pins are also wired to theAnalog 4 and 5 pins. For programming the arduino we will use the library provided by Adafruit RTClibrary Install the library and load up the sketch (which is also found inExamples→RTClib→ds1307) and upload it to your Arduino. Opening the Serial Monitor and setting the appropriate baud rate you will see the correct time and date. Your time is now set, you can use it according to your need. Remember it will retain the time as long as the coin cell battery is connected to it. This coin cell battery can remain for almost 3-4 years so there is no need to change the time once its set.
Step 4: How to Display Numbers on the Seven Segment Display
After configuring the display now it is time to display the number. For displaying the numbers we are using a shift register 74hc595. Here we will write down all the inputs for displaying the numbers. The input to the seven segment display is binary. The shift register we are using is of 8 bits. We will need only 7 pins out of it so we will use only D0 to D6 . There is photo above showing the truth table of seven segment display and its corresponding input in binary as well as in decimal. We will use this decimal number as input to the shift register.
The statement given below shifts out the decimal number to the shift register. This decimal number corresponds to the number displaying on the seven segment.
MSBFIRST is used as we are not using D7 pin of shift register and from the truth table we can see that decimal number we got are in same order.
shiftOut(dataPin, clockPin, MSBFIRST,decimalNumber);
Step 5: How It Works?
Using RTCLib we will get the time. As we are using 4 seven segment display we will retrieve only hours and minutes. Now we know how to display the numbers on the seven segment display we will convert the time into a 4 digit number. This can be done as follows
int h = now.hours();
int m = now.minute();
int number = h*100+m;
If time is 7 hours 30 minutes it will be 0730 as 4 digit number.
But now problem here is the time is 4 digit number and we can display only one digit at a time using one segment display. This can be solved using a technique called multiplexing. Multiplexing is a kind of illusions. Using the property of human eye called persistence of vision. Here each display is turned on for very short period of time and this is done so fast that our eyes cannot distinguish between them. It appear as a 4 digit are turned on displaying the time.
This 4 digit number is broken down into thousands,hundreds,tens and units digit. This can be done as follows:
Here number is the 4 digit number corresponding to the time.
int a = number/1000%10; //Separating thousands digit from the number
int b = number/100%10; //Separating hundreds digit from the number
int c = number/10%10; //Separating tens digit from the number
int d = number%10; //Separating units digit from the number
We need to give input to the each and every display explicitly. This can be done using the COMM pin of the display.
As we are using common cathode display we have to pull that particular pin LOW to display the number. You ca see it in the code before giving input the pin is pulled LOW once the input is given it is displayed on corresponding seven segment display. After this the pin is pulled HIGH to unable the display. So that it wont interfere with the other.
Step 6: Program
Firstly you need to install the RTClib in your Arduino IDE. Then open the code given below and upload it to your arduino. As long as the circuit is properly connected it should work fine.
You also modify this code. I tired to keep it simple without using the functions. You can use function for displaying the time and also for converting time into equivalent decimal number.
Attaching the pdf as well as .sch file of the schematics and also the code.
Step 7: Final Assembling and References
For putting it all together I used a plastic black project box. Cut a window for the seven segment display. Also a hole for a power switch and power supply cord.