You are on page 1of 11

instructables

How to Make a Arduino Digital Clock

by Madrajib

Digital clocks are one of the great invention in the components all by yourself....
field of science.
I have used 4 7 segment common anode display to
Have you ever wondered "How to make your own display the digits, 3 SPDT switches , which i took
digital clocks , just like in movies! "???? apart from an old mouse, some wires and an arduino.
we can set the time holding the adjust key and
Well i have also spent ,my childhood in a dream to pressing the minute or hour key to change the minute
built my very own digital clock.. so i built one for my or the hour to our need..!
self ...
So Lets get started...!
And am going to show you, How you can built an
amazing digital clock with little ease and little

https://www.youtube.com/watch?v=71KbOLMe48k

How to Make a Arduino Digital Clock: Page 1


Step 1: Components Required

Here the Components that you will Require : same for both of them).

1. An Arduino uno. you can buy them from snapdeal , they are great ! i
would recommend them from the site.
2. 4 7 segment common anode displays (if you have
a 4 digit seven segment , don't worry the circuitry is 3. 3 spdt Switches (which i scavenged from an old

mouse ). 5. A breadboard.

4.some wires and jumper wires (any one will do!). 6. 4 1kohm resistors.

Step 2: Wiring the Displays in the Breadboard!

Make the connections as shown in the picture above.. its quite simple.!

Take care of the connections , as coz there are too many wires you might get confuse.

Remmenber All a,b,c,d,e,f,g,dot segments of 4 displays are connected together.... and the com of every display i.e
3 and 8 are connected together with the resitors...

Do not worry!! , go slowly,and have some patience , you can do it.

How to Make a Arduino Digital Clock: Page 2


Step 3: Adding the Resistors and the Keys

Attach 1kohm resistor with each com of the displays ... as shown in the figure..!

Add the Spdt switches or if you have push on buttons that would be great !...

How to Make a Arduino Digital Clock: Page 3


Step 4: Connecting to Arduino

Now the connections are done for the display and the For display pins
switches ... now time is to connect them to the brain..
display 1 to pin 10
it is simple..
display 2 to pin 11
For segment pins!
display 3 to pin 12
a to pin 2
dispaly 4 to pin 13
b to pin 3
now for the keys
c to pin 4
key 1 which is the adjust switches ...
d to pin 5
key 2 and key 3 are hour changing and minute
e to pin 6 changing switches..

f to pin 7 we have to hold the adjust key1 and press the desire
key to change the hour or the minute..!
g to pin 8
see the pic above for the connection for the keys ..
dot to pin 9 we have used the analog pins and used them as

digital input pins... yes thats true we can use them as


digital i/o pins too..

How to Make a Arduino Digital Clock: Page 4


Step 5: Adding the Code!!!!

Now the most cool part ... writing and adding the code Please add the Time Folder in Time.zip, in your
to the arduino.... Arduino's libraries folder.

I have attached the code and the time library file .. for eg in my system:
calculating the time and displaying it....
C:\Program Files (x86)\Arduino\libraries
In the code the hour() function tells us the hour, and
the minute() function the minute , from the time we
have switched on the board. the time fades dies when
the power to the board is cut of.. and it starts again
from 00:00 every time... Do feel flexible in changing the code for your needs ...
and if you have some quarries feel free to ask.
Also i have attached a 12 hour format code too. It just
uses hourFormat12() function to get the 12 hr Have fun making it...
format.
note: I have updated the Time.zip file as it was
By default the Time library returns 24hr formated deprecated in newer versions of Arduino IDE.
time.

Note:

Download
https://www.instructables.com/ORIG/F2T/UW2W/IHDP0UUQ/F2TUW2WIHDP0UUQ.ino

Download
https://www.instructables.com/ORIG/FK5/GNI8/JFCTBI3J/FK5GNI8JFCTBI3J.zip

Download
https://www.instructables.com/ORIG/F0T/0G9X/JG74UGG2/F0T0G9XJG74UGG2.ino

Hello, I have the error while compiling the code so please solve it
Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Users\gj\Downloads\final_clock_arduino_12hr\final_clock_arduino_12hr.ino: In function 'void
loop()':
final_clock_arduino_12hr:59: error: 'hour' cannot be used as a function
int hour = hour();

How to Make a Arduino Digital Clock: Page 5


^
final_clock_arduino_12hr:60: error: 'hr' was not declared in this scope
int timp = ( (hr>12)?(hr%12):hr)*100+minute();
^
final_clock_arduino_12hr:60: error: 'minute' was not declared in this scope
int timp = ( (hr>12)?(hr%12):hr)*100+minute();
^
C:\Users\gj\Downloads\final_clock_arduino_12hr\final_clock_arduino_12hr.ino: In function 'void
set_time()':
final_clock_arduino_12hr:80: error: 'minute' cannot be used as a function
byte minute = minute();
^
final_clock_arduino_12hr:81: error: 'hour' cannot be used as a function
byte hour = hour();
^
final_clock_arduino_12hr:85: error: 'minutes' was not declared in this scope
minutes1=minutes;
^
final_clock_arduino_12hr:86: error: 'hours' was not declared in this scope
hours1=hours;
^
final_clock_arduino_12hr:131: error: 'setTime' was not declared in this scope
setTime(hours,minutes,0,0,0,0);
^
exit status 1
'hour' cannot be used as a function
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Good day sir. Ahmm can i ask if the code for the hour sir because just like the others sir we do
have the same problem that hour was not declared. Im hoping you can help me with this sir. Thank
you
how can i convert this 24 hours digital clock code to 12 hours format???
Or can you give me the 12 hours format digital clock code for this same diagram????
Madrajib is it a 24 hour clock
Yes , Ed Marjosef.

how to convert it 24 hours to 12 hours formate sir????


Thank you very much sir
Dear Sir,
I have a letest arduino version software and I have follow of your instruction and i have alredy

How to Make a Arduino Digital Clock: Page 6


connect breadboard to arduino wires of your instruction.When i have download of your first link
Sketch file and open in arduino but upload not properly.I dont know any technical problem show
here.Please tell me How to upload directly without any programing.Thank you sir.If you want E-
mail me for sending any code Sketch file please send (ayandeysarkar76@gmail.com).I likes your
videos every time....I hope you understand and I wish you are help me for this problem
journey.Thank you.

Show less

REPLY
Hour was not decrared in this slope ...please help me out...??

Sorry Raj for late reply. I think you have a Time folder already
in the libraries folder. delete all time Time folder and then download
the file and add it ...
It is working fine in my system. Also are you running windows installer version or

Windows ZIP
file for non admin install.
I am have a installer version .
Sorry RajA46 for such an late reply and error. actually the Time library i have used was for old
version of arduino ide. it was update after arduino ide 1.6.1 version, hence the error.
here is the link to new updated library, but before you use it delete the Earlier Time folder from
libraries folder
C:\Users\lenovo\Documents\Arduino\libraries and also from
C:\Program Files (x86)\Arduino\libraries
now dowload the zip file and add it to arduino,
https://github.com/PaulStoffregen/Time.git
To add it go to sketch->Include Library->Add .Zip Library and find the zip file.
after that go to sketch->Include Library->Time
And it will work.
yeah i have the same problem too. pls, i really need your help, hour is not declared in the scope

Hi. I just followed the note you have provided, and sadly there is always an error in verifying the
code. Is there any alternatives you could suggest in order to fix the error? The error always says
that the "hour' was not declared in this scope. Though, I'd already add the time folder in time.zip in
my arduino's libraries folder. Please reply. I'm truly in need of help. Thank ypu.
did you add the zip file without unzipping it???
Try this:
Delete the time library from the libraries folder.
open arduino ide.
select "Sketch" tab from the top left menu bar.
select "Include Library" and select Add .ZIP Library from the drop down.
located the time.zip file and press ok.
this would include the time library to the Arduino libraries,
How to Make a Arduino Digital Clock: Page 7
and now include the library by again selecting including library option and selecting time library
from the drop down
Sorry MikeK277 for such an late reply and error. actually the Time library i have used was for old
version of arduino ide. it was update after arduino ide 1.6.1 version, hence the error.
here is the link to new updated library, but before you use it delete the Earlier Time folder from
libraries folder
C:\Users\lenovo\Documents\Arduino\libraries and also from
C:\Program Files (x86)\Arduino\libraries
now dowload the zip file and add it to arduino,
https://github.com/PaulStoffregen/Time.git
To add it go to sketch->Include Library->Add .Zip Library and find the zip file.
after that go to sketch->Include Library->Time
And it will work.
Dear Sir,
You can give me arduino digital clock "code",i can not found.please help me.
Dear AyanS14, the code it right there in the instructable page.
Under the STEP 5: ADDING THE CODE!!!!
Below the image you will seen final_arduino.ino name click it it shall start downloading..
Sorry AyanS14 for such an late reply and error. actually the Time library i have used was for old
version of arduino ide. it was update after arduino ide 1.6.1 version, hence the error.
here is the link to new updated library, but before you use it delete the Earlier Time folder from
libraries folder
C:\Users\lenovo\Documents\Arduino\libraries and also from
C:\Program Files (x86)\Arduino\libraries
now dowload the zip file and add it to arduino,
https://github.com/PaulStoffregen/Time.git
To add it go to sketch->Include Library->Add .Zip Library and find the zip file.
after that go to sketch->Include Library->Time
And it will work.
Error: 'hour' was not declared in this scope
that is my error help me please i tried everything i read in the comments for the same problem but
nothing happened. please help

Sorry JomarG1 for such an late reply and error. actually the Time library i have used was for old
version of arduino ide. it was update after arduino ide 1.6.1 version, hence the error.
here is the link to new updated library, but before you use it delete the Earlier Time folder from
libraries folder
C:\Users\lenovo\Documents\Arduino\libraries and also from
C:\Program Files (x86)\Arduino\libraries
now dowload the zip file and add it to arduino,
https://github.com/PaulStoffregen/Time.git
How to Make a Arduino Digital Clock: Page 8
To add it go to sketch->Include Library->Add .Zip Library and find the zip file.
after that go to sketch->Include Library->Time
And it will work.
I made it. Would u tell me how to add 2 more display for showing seconds?
Very good project!
It work but I had many problems in including libreries: I had to load the Time.lib.h library too, so:
"
#include <Time.h>
#include <TimeLib.h>
#include <Time.h>
//modified by Madrajib
..."
Here are some photos: I use a 4 digits module and buttons.
Thanks for this work.

i've done whatever changes you mentioned here. but wont work
please give me solution for it
hi
can also please give the code in plain text. thanks
hi
It was a nice project. Can you give me code for common cathode please.
How Can I implement this clock via 8051 microcontroller please answer.
Hello iis it possible to use a bcd segment instead of the switches?

Which Switches are you talking about?

spdt switches

The lights that are under the numbers all light up and flash. When I unplug the ground, the flashing
stops but then the brightness/dimness to differentiate between on and off are so similar, you can't
tell what number it is. The buttons don't work and won't let me change anything. Please help.
I have done it..... very good project. I like it.
Thats great .. Thanks

Hi there. I can't find any anode seven segments nearby. Is it possible to replace the anode
segments by cathode seven segments? And how to do it. Thanks!
Sorry ixixvi for such an late reply , i had final semester examinations going on.
You have to change a lot of code in the program ..
you can use not gate ics to the to all the pin ..

How to Make a Arduino Digital Clock: Page 9


Madrajib, I have added library and I have windows 10 too, but it still shows 'Hour was not decrared
in this slope'
Sorry Raghav for late reply. I think you have a Time folder already in the libraries folder. delete all
time Time folder and then download the file and add it ...
It is working fine in my system. Also are you running windows installer version or

Windows ZIP
file for non admin install.
I am have a installer version .
i made it
I have also include the library bt it still shows hour is not declared in this scope, please help me i
have done all steps just stuck in code?
That's great ... Share it on instructable or in YouTube ..

Thank you Madrajib ... I didn't use 7 segment instead I use the LED's as seven segment

Can any of you help me out even I'm trying with the same with LED's as 7 segment display. I'm
receiving the time from internet via esp8266 and want it to display on the LED's. I'm able to get the
time but couldn't able to display as each digit requires 7 control and total (7*4) control and the
arduino doesnt have that many outputs. This project helps me but im not able to understand it.
Could you please help in the common connection and what will be it if we use only LED's as 7
segment
And aslo I got rid of the resistors because the lights on the LED's are low when added a resistor,
but when I got rid of it glows bright, but not too bright it's just slight of it... Anyways thank you so
much for the project
thats cool.. the leds required a bit more voltage than the segment .. may be thats the reason..
anyways it great that you made it in your own way.. keep going.
source code kaha hai bro

Bro Step 5 me hai... View all steps click karne se ayega sare steps!

Hi Rajib,
Nice post. But what if I want to make this clock with
bigger say 4 inches 7 segment display numbers. What changes do would I
need? Please provide the schematic and part details if you have.
Thanks
Hie Travi, can you supply me the data sheet of 7 segment display you will be using so that I can
make the schematic .
Here is the link for datasheet:
elektrologi.kabarkita.org/wp-content/uploads/2015/08/LCS-40012YG11.pdf
Hi Rajib,
Thanks for quick reply. I want to use this common cathode 7segment display (green color). Please
provide the schematic, program code and parts detail to my email id. Thanks in advance
Regrds,
Ravi

How to Make a Arduino Digital Clock: Page 10


Hello thanks very much i made it and it working perfectly but i need your help i won't to add RTC to
it can you help me

How to Make a Arduino Digital Clock: Page 11

You might also like