Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

1

DIGITAL CLOCK PROJECT REPORT


DEPARTMENT OF ELECTRICAL ENGINEERING
INDIAN INSTITUTE OF TECHNOLOGY HYDERABAD

ID1035: INDEPENDENT PROJECT


Professor: Dr.G.V.V Sharma
Designed by: MD. AAMIR SOHAIL
EE16BTECH11021

1 AIM OF THE PROJECT 4 BASIC CONCEPT


• We know that 60 seconds equal to 1 minute
Designing a 6-digit digital clock using 6-seven
and 60 minutes equal to 1 hour. Hence the
segment display, Atmega328P AVR microcontroller
minute section is drive by second section and
and programming.
hour section by the minute section. Each of the
minute and second section has been designed to
2 INTRODUCTION give a count from 00 to 59 after which it resets
to 00. And the hour section to give a count
A digital clock is a type of clock that displays from 00 to 11 hours after which it resets to 00.
the time numerically (i.e. in numerals), where as an For each cycle of 00 to 59 in second section
analog clock, displays the time by the positions of the minute section increases its count by 1.
rotating hands. Similarly for each cycle of 00 to 59 in minute
To represent the time, most digital clocks use a section the hour section increases its count by
seven-segment LED or LCD for each of desired 1. In this way when the clock reaches 11hrs.
digits. They also used other elements to indicate 59mins. 59secs. Each of the section resets to
whether the time is AM or PM, or simply use 12 00 giving us a display 00.00.00.
or 24 hour format. Some of the digital clock has • To display all the 6 digits a large amount
alarm function also. Now a days, they also include of pins are needed to power it, so a special
date and day display. technique is used called MULTIPLEXING.

Multiplexing works by switching between the


3 OBJECTIVE digits one by one very fast and by so creating an
illusion that of all displays are working at the same
I have implemented the digital clock that displays time. This works by connecting all the 7 (a-g) pins
time in hours, minutes and second. The objective of of the seven segment display to the same one on
the project is to implement all the basic function a different segment. This reduces the no. of pins
of the digital clock which we find in our daily life required. Now we need only 7 pins.
routine. The features likes 24 hour display, clock
setting etc. CODE HAS BEEN DESIGNED BY KEEPING
HOW TO USE: The user can set the clock by THE BASIC CONCEPT IN THE MIND.
the set buttons (one for minutes and the other for
hours) and toggle between hour and minute to set
the current time. There is a reset button to start the
clock from the beginning.
2

5 MODULE STRUCTURE 8 COMPONENT DESCRIPTION


The entire project is divided into five modules. 1) ATMEGA328P: Atmel- ATmega328P is an 8-
They are as follows: bit microcontrollers. Atmel- Atmega328 MCUs
1) CIRCUIT DESIGNING SECTION. (using execute powerful instructions in a single clock
multiplexing). cycle, allowing the device to achieve through-
2) PROGRAMMING SECTION. puts approaching 1 MIPS per MHz while
3) TESTING SECTION (on the breadboard). balancing power consumption and processing
4) DESIGNING OF THE PCB. speed.
5) ASSEMBLY SECTION.

6 TOOLS REQUIRED
6.1 For PCB designing part:
1) Soldering Iron
2) Solder wire
3) Small needle plier
4) Small cutter
5) Wire striper

6.2 For Circuit testing part:


1) Breadboard
2) Jumper wires
3) Arduino UNO
4) Data cable (for the power supply to the Ar-
duino)
Fig. 1: ATMEGA328P

6.3 For programming part: Features


1) Arduino IDE a) High Performance, Low Power AVR 8-Bit
Microcontroller
b) Advanced RISC Architecture
7 COMPONENT USED c) Max I/O Pins: 23
d) Flash Analog Comparators: 1
For PCB Designing and Testing e) Temp. Range: -40 to 85 ◦C

S. No Material Quantity Applications


1 Atmega328P 1 a) Home and Building Automation
2 Crystal oscillator-16MHz 1 b) Industrial Automation
3 22pF capacitor 2 c) Sensors
4 220ohm resistor 6
5 10 kohm resistor 1 2) SEVEN SEGMENT DISPLAY: A seven-
6 Seven segment display 6 segment display is a form of electronic display
7 Button 1 device for displaying decimal numerals that is
8 Potentiometer 2 an alternative to the more complex dot matrix
9 PCB board 1 displays. Seven-segment displays are widely
10 Rainbow wires stripes 2 used in digital clocks, electronic meters, basic
calculators, and other electronic devices that
display numerical information.
3

3) POTENTIOMETER: A potentiometer is a
variable resistor. It has three pins one for
output (wiper) and the other two for power and
ground.
Potentiometers work by having a resistive ele-
ment inside. Both end terminals are attached to
it, and do not move. The wiper travels along the
strip when the knob is turned. The closer the
wiper is to the end terminal, less the resistance,
because the path of the current will be shorter.
The further away it moves from the terminal,
Fig. 2: SEVEN SEGMENT DISPLAY the greater will be the resistance.

There are two types of seven segment displays


a) Common Cathode
b) Common Anode (I have used common cath-
ode)

Fig. 5: Potentiometer

Fig. 3: Types of seven segment display

Fig. 6: Potentiomter Symbol

Fig. 4: Seven Segment Display logic


4

9 MODULE DETAILS 9.2 PROGRAMMING SECTION

9.1 CIRCUIT DESIGN SECTION I have used c programming and arduino program-
7 a-g pins of the one segment are connected to ming language. I have written the program step by
the same one of the other segment. COM- pins of step:
each display are connected to the 220 ohm resistors
and then to the digital output pins of the Arduino 1) For single digit common cathode display
as shown in figure. The 7 a-g pins of one segment void setup()
is connected to the 0-6 digital output pins of the {
Arduino. The push button has been used for the pinMode(2,OUTPUT);
reset purpose, Pin A0 has been used for the INPUT pinMode(3,OUTPUT);
given by push button. The A1 and A2 analog read pinMode(4,OUTPUT);
pins are used for the potentiometer, they are used pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
to change the value of minute and hour as per our pinMode(7,OUTPUT);
desire, instead of resetting the clock. pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
void display(int N)
{
A=N%2;
N=N/2;
B=N%2;
N=N/2;
C=N%2;
D=N/2;
a=C&&!B&&!A||!D&&!C&&!B&&A;
b=C&&!B&&A||C&&B&&!A;
c=!C&&B&&!A;
d=!D&&!C&&!B&&A||C&&!B&&!A||C&&B&&A;
e=C&&!B||A;
f=!D&&!C&&!B&&A||B&&A||!C&&B&&!A;
g=C&&B&&A||!D&&!C&&!B;
}
void loop()
{
if(x==10)
{
x=0;
display(x);
}
Fig. 7: BLOCK DIAGRAM (Not scaled to pin else
configuration) {
display(x);
}
x=x+1;
digitalWrite(2,!a);
digitalWrite(3,!b);
digitalWrite(4,!c);
digitalWrite(5,!d);
digitalWrite(6,!e);
digitalWrite(7,!f);
digitalWrite(8,!g);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
5

delay(1000); void disp(int X)


{
} E=X%10;
A=E%2;
E=E/2;
2) For two seven segment display using 14 pins B=E%2;
E=E/2;
int A,B,C,D,E; C=E%2;
int a,b,c,d,e,f,g; D=E/2;
int Y=0; a=A&&!B&&!C&&!D||!A&&!B&&C&&!D;
int dec=0,dec1; b=A&&!B&&C&&!D||!A&&B&&C&&!D;
void setup() c=!A&&B&&!C&&!D;
{ d=A&&!B&&!C&&!D||!A&&!B&&C&&!D||A&&B&&C
pinMode(0,OUTPUT); ,→ &&!D;
pinMode(1,OUTPUT); e=A&&!B&&!C&&D||A&&B&&C&&!D||!A&&!B&&C
pinMode(2,OUTPUT); ,→ &&!D||A&&!B&&C&&!D||A&&B&&!C&&!D||
pinMode(3,OUTPUT); ,→ A&&!B&&!C&&!D;
pinMode(4,OUTPUT); f=A&&B&&C&&!D||A&&B&&!C&&!D||!A&&B&&!C
pinMode(5,OUTPUT); ,→ &&!D||A&&!B&&!C&&!D;
pinMode(6,OUTPUT); g=A&&B&&C&&!D||A&&!B&&!C&&!D||!A&&!B&&!C
pinMode(7,OUTPUT); ,→ &&!D;
pinMode(8,OUTPUT); digitalWrite(7,!a);
pinMode(9,OUTPUT); digitalWrite(8,!b);
pinMode(10,OUTPUT); digitalWrite(9,!c);
pinMode(11,OUTPUT); digitalWrite(10,!d);
pinMode(12,OUTPUT); digitalWrite(11,!e);
pinMode(13,OUTPUT); digitalWrite(12,!f);
} digitalWrite(13,!g);
void display(int N) }
{ void loop()
A=N%2; {
N=N/2; dec1=dec/10;
B=N%2; if (dec<10)
N=N/2; {
C=N%2; display(dec);
D=N/2; disp(dec1);
}
a=A&&!B&&!C&&!D||!A&&!B&&C&&!D; else
b=A&&!B&&C&&!D||!A&&B&&C&&!D; {
c=!A&&B&&!C&&!D; disp(dec1);
d=A&&!B&&!C&&!D||!A&&!B&&C&&!D||A&&B&&C display(dec%10);
,→ &&!D; }
e=A&&!B&&!C&&D||A&&B&&C&&!D||!A&&!B&&C dec=dec+1;
,→ &&!D||A&&!B&&C&&!D||A&&B&&!C&&!D|| delay(1000);
,→ A&&!B&&!C&&!D; }
f=A&&B&&C&&!D||A&&B&&!C&&!D||!A&&B&&!C
,→ &&!D||A&&!B&&!C&&!D;
g=A&&B&&C&&!D||A&&!B&&!C&&!D||!A&&!B&&!C
,→ &&!D;
digitalWrite(0,!a);
digitalWrite(1,!b);
digitalWrite(2,!c);
digitalWrite(3,!d);
digitalWrite(4,!e);
digitalWrite(5,!f);
digitalWrite(6,!g);
}
6

3) For two seven segment display (counting a=A&&!B&&!C&&!D||C&&!A&&!B&&!D;


from 0-99) using seven pins b=A&&C&&!B&&!D||B&&C&&!A&&!D;
c=B&&!A&&!C&&!D;
int dec=0; d=A&&!B&&!C&&!D||C&&!D&&!A&&!B||A&&B&&C
void setup() ,→ &&!D;
{ e=A&&!B&&!C&&D||A&&B&&C&&!D||A&&!B&&C&&!
pinMode(2,OUTPUT); ,→ D||!A&&!B&&C&&!D|| A&&B&&!C&&!D||A
pinMode(3,OUTPUT); ,→ &&!B&&!C&&!D;
pinMode(4,OUTPUT); f=A&&B&&C&&!D||A&&B&&!C&&!D||!A&&B&&!C
pinMode(5,OUTPUT); ,→ &&!D||A&&!B&&!C&&!D;
pinMode(6,OUTPUT); g=!A&&!B&&!C&&!D||A&&!B&&!C&&!D||A&&B&&C
pinMode(7,OUTPUT); ,→ &&!D;
pinMode(8,OUTPUT); digitalWrite(9, LOW);
pinMode(9,OUTPUT); digitalWrite(10, HIGH);
pinMode(10,OUTPUT); digitalWrite(2, !a);
} digitalWrite(3, !b);
void display(int z) digitalWrite(4, !c);
{ digitalWrite(5, !d);
int N=z%10; digitalWrite(6, !e);
z=z/10; digitalWrite(7, !f);
int A,B,C,D; digitalWrite(8, !g);
int a,b,c,d,e,f,g; delay(2);
A=z%2; }
z=z/2; void loop()
B=z%2; {
z=z/2; if(dec!=100);
C=z%2; else
D=z/2; {
dec=0;
a=A&&!B&&!C&&!D||C&&!A&&!B&&!D; }
b=A&&C&&!B&&!D||B&&C&&!A&&!D; for(int i=0;i<250;i++)
c=B&&!A&&!C&&!D; display(dec);
d=A&&!B&&!C&&!D||C&&!D&&!A&&!B||A&&B&&C dec++;
,→ &&!D; }
e=A&&!B&&!C&&D||A&&B&&C&&!D||A&&!B&&C&&!
,→ D||!A&&!B&&C&&!D||A&&B&&!C&&!D||A
,→ &&!B&&!C&&!D;
f=A&&B&&C&&!D||A&&B&&!C&&!D||!A&&B&&!C
,→ &&!D||A&&!B&&!C&&!D;
g=!A&&!B&&!C&&!D||A&&!B&&!C&&!D||A&&B&&C
,→ &&!D;
digitalWrite(10,LOW);
digitalWrite(9, HIGH);
digitalWrite(2, !a);
digitalWrite(3, !b);
digitalWrite(4, !c);
digitalWrite(5, !d);
digitalWrite(6, !e);
digitalWrite(7, !f);
digitalWrite(8, !g);
A=N%2;
N=N/2;
B=N%2;
N=N/2;
C=N%2;
D=N/2;
delay(2);
7

4) For potentiometer (individually) 6) Combining code 5, 6 and code for digital


clock without potentiometer and push but-
const int ledPin = 9;
const int potPin = A0; ton.
int value; int A,B,C,D,a,b,c,d,e,f,g,h,j,k,l,m,n,ti
,→ =1;
void setup() long int x,z,y,dec=0,cou,tcou=0,p,o;
{ void setup(){
pinMode(ledPin, OUTPUT);
pinMode(potPin, INPUT); pinMode(0,OUTPUT);
} pinMode(12,OUTPUT);
pinMode(2,OUTPUT);
void loop() pinMode(3,OUTPUT);
{ pinMode(4,OUTPUT);
value = analogRead(potPin); pinMode(5,OUTPUT);
analogWrite(ledPin, value); pinMode(6,OUTPUT);
delay(100); pinMode(7,OUTPUT);
} pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
5) For push button (individual) pinMode(11,OUTPUT);
int push=2; pinMode(1,OUTPUT);
void setup()
{ }
pinMode(2,INPUT); void display(long int N,int P,int T){
pinMode(13,OUTPUT); A=N%2;
} N=N/2;
void loop() B=N%2;
{ N=N/2;
push=digitalRead(2); C=N%2;
if(push==0) D=N/2;
{ a=A&&!B&&!C&&!D||!A&&!B&&C&&!D;
digitalWrite(13,HIGH); b=A&&!B&&C&&!D||!A&&B&&C&&!D;
} c=!A&&B&&!C&&!D;
else d=A&&!B&&!C&&!D||!A&&!B&&C&&!D||A&&B&&C
{ ,→ &&!D;
digitalWrite(13,LOW); e=A&&!B&&!C&&D||A&&B&&C&&!D||!A&&!B&&C
} ,→ &&!D||A&&!B&&C&&!D||A&&B&&!C&&!D||
} ,→ A&&!B&&!C&&!D;
f=A&&B&&C&&!D||A&&B&&!C&&!D||!A&&B&&!C
,→ &&!D||A&&!B&&!C&&!D;
g=A&&B&&C&&!D||A&&!B&&!C&&!D||!A&&!B&&!C
,→ &&!D;

digitalWrite(0,HIGH);
digitalWrite(8,HIGH);

digitalWrite(9,HIGH);
digitalWrite(10,HIGH);

digitalWrite(11,HIGH);
digitalWrite(12,HIGH);

digitalWrite(P,LOW);
digitalWrite(7,!a);
digitalWrite(6,!b);
8

digitalWrite(5,!c); else{
digitalWrite(4,!d); dec=-1;}
digitalWrite(3,!e);
digitalWrite(2,!f);
digitalWrite(1,!g); dec++;
ti++;
while(1<10){ }
cou=millis() ;
if(cou-tcou>=T)
break;

} }
tcou=cou;

} SOURCE FOR LEARNING PROGRAMMING:


void loop(){ Arduino.cc C-tutorial point
I have used Millis () function, display function,
if and else function etc.
if(analogRead(A0)>= 800){
dec = 0;
Millis () - When we use the delay () function
in our sketch, the program stops. The program
} waits until moving on to the next line of code.
else{ So, in this dead time we can’t process the input
x=analogRead(A1); data from sensors, as well as the outputs. The
long int r=(x*23*3600)/1023; delay () function is easy to use, but good only if
if(((p-r)>=3600)||((r-p)>=3600)){
we don’t have something else going on during the
dec =dec+r-p;
} p=r; delay. Otherwise, we have to use Millis (). Millis
x=analogRead(A2); () can seriously affect our project when we have to
long int s=(x*60*60)/1023; run multiple actions simultaneous. It’s the function
if(((o-s)>=60)||((s-o)>=60)){ which allow us to do multitasking on Arduino. It’s
dec =dec+s-o;} pretty simple to work with the delay () function. It
o=s; accepts a single number as argument representing
y=dec;
h=y%10;
the time in milliseconds. Using Millis () takes a little
y=y/10; bit of extra work compared to delay (). Calling the
j=y%6; Millis () function in the Arduino sketch returns the
y=y/6; number of milliseconds that have elapsed since we
k=y%10; start to run the program.
y=y/10;
l=y%6; If/else function- It allows us to grouped multiple
y=y/6; test into a single group. For example there is analog
m=y%10;
n=y/10;
input value from 0 to 1023 then we can grouped
if(dec<86400){ value less than 500 into one group and greater than
for(int i=0;i<100;i++) 500 into other group.
{
display(h,0,1);
display(j,8,1);
display(k,9,1);
display(l,10,1);
display(m,11,1);
display(n,12,5);
}
}
9

9.3 TESTING SECTION 9.4 DESIGNING OF THE PCB


The circuit is tested step by step as the program- Now it’s time to fix all the components on the
ming is done, to verify the program. First for single PCB board as per circuit diagram. It can’t be done
seven segment display (common cathode), then for randomly. First, I have design circuit diagram for
two digits using 14 pins, then for two digits but the PCB, like place of the Display, Atmega328p,
now I am using 7 pins, now the multiplexing come resistor, pushbutton, potentiometers etc. Then I have
into role and finally I have tested all the six digit. soldered all the part at their respective positions.
I have tested the working of potentiometer, push
button separately then I combined them with the
circuit.

Advantage of testing section: when I am testing


counting from 0-99 using 14 pins, I have encoun-
tered a problem
Problem: The ten’s place display was initially glow-
ing dim?
Answer: In the void setup I have initially not defined
the 7 to 13 pin as a output. I.e. why this section
is very useful for the program verifying purpose.
Finally the designed circuit is now tested on the
breadboard, all the connections are made on the
breadboard according to the circuit diagram, the Fig. 8: PCB Design — Front View
output and input wires are attached to the Arduino
UNO, then the data cable is connected to the laptop
for the power supply to the Arduino. After a lot of
efforts and debugging the clock works.

Results: The designed is performing well as ex-


pected. Furthur, the clock’s functionality is working
properly.It is taking 5V power supply. It is using all
the 6 seven segment display. When the reset switch
is pressed all the LEDs will get 0 and we can set
the time by selecting potentiometer switch and then
toggling between the hour and minute display to set
the current time.

Fig. 9: PCB Design — Rear View


10

9.5 ASSEMBLY SECTION 13 ACKNOWLEDGEMENT


Now the circuit designing part is complete, the A independent project is the golden opportunity
hard work is over and we assemble all the com- for learning and self development. I consider myself
ponents to get the Digital Clock. Now the At- very lucky and honored to have so many wonder-
mega328P is inserted at its respective place. With ful people lead me through in completion of this
the supply connected to 5V and then we operate project.
the clock to check the output. Finally the Clock is My greatful thanks to Guide: Dr. G.V.V Sharma
expected to operate normally with desired accuracy. who inspite of busy with his duties, took time out
to hear, guide and keep me on the correct path.He
was always involved in the entire process, shared
his knowledge, and encouraged me to think. I do
10 CONCLUSION not know where i would have been without him. A
humble THANKS for his efforts and help provided
The clock’s display is fully functional and it
to me to get such an excellent opportunity..
is capable of using all the digits of the seven
I would like to thanks the EE lab incharge,
segment display. The time setting and resetting is
assistants who monitored my progress and arranged
also working.
all the facilities to make the project easier.
Last but not the least i would like to thanks my
friends who shared so many valuable information
11 LESSONS LEARNT that helped in the successful completion of this
The Circuit was purely designed with the ba- project.
sic knowledge of C and Arduino programming. THANKS A LOT
Multiplexing also plays an important role in the
project and with the components provided by the
authority. A lot of things I have learned from this
project like soldering, programming,use of AVR mi-
crocontrollers, PCB designing, use of Arduino, use
of potentiometer and seven segment display,harware
implementation, designing of the commercially used
devices (beyond the just designing the circuit on the
breadboard only).

12 FUTURE WORK
In future we can change the clock format from 24
hour to 12 hour A.M/P.M format and also we can
make few changes in the code and use it to display
the date(mm/dd/yyyy format) in LCD.

You might also like