Hi! welcome to an Arduino tutorial from Robojax my name is Ahmad Shamshiri
in this video we are going to learn how to build a digital clock using any Arduino with ds1307
real-time clock module and this ht16k337 segment display you can get the data sheet and other files
related to this click by clicking the link below the video in the description which will take you
to robojax.com/learn/arduino. let's get started with this
a separate video explaining this ds-1307 with example with alarm and so many other options
and also a separate video fully explained this HT16K33 I’m not going to explain those here we
are going directly jump into wiring and coding I’m going to explain the code fully demonstrated
different features of it because this can display seconds you can turn it on and off
either the second can blink or that would be just a counter without further ado make sure to
thumb up the video and also subscribe so I get started with this this is a 3.2 inch tft lcd
screen based on esp-32 this has built-in wi-fi and Bluetooth and can be programmed with Arduino ide
the product is from MakerFabs and it has built-in camera you can play simple games you can display
text and you can use full features of esp32 I have introduction video for this product the link is
below the video in the description if you want to purchase the product from makerfaps.com the link
is also below this video now here I have used from five volts I’ve connected one wire from ground
from a4 and from a5 a4 is sda, a5 is scl if you're using other devices for example uno Ethernet sdsa4
a5 scl Arduino mega 20th sda and 21scl and the northern due there have been all mentioned I
will provide you the link for this as well and then from here I have connected one bunch of
wire for the real time clock and one bunch of wire of the same color to this display for the display
they are exactly the same order from left to right they are coming from left to right
you so you don't have to worry 5 volts ground sda and scl and here for this module this
purple is five volts five volt have been connected to vcc to the second pin and then ground is gray
I’ve been connected to the first one and then white is sda has been connected here to the sda
pen and the last pen black is scl and it has been connected to the last pen which is scl
Now let me explain the code because I’ve used library for ds1307 from adafruit
and I’ve used ht16k33 first you need to download and install this library
and then we need to install this library for this this is called rtclib that's from
adafruit let's go to sketch include library manage library or you can go to tools manage libraries
Wait for this to complete the bar graph
and you see rtclib just type rtclib
wait for few seconds and here it says rtclib by adafruit and here is the name of the person
glab so select that and install it install it
wait for this to complete and the installation is now completed and then type here
and then for http 16 k 33 type and weight
you will see a lot of options but the one that we are using is from rob tellart and it says
installed and in your case the install button will be here and just click and install it
and then close this this line wire is for I square c communication it's part of Arduino rtcl ibs that
adafruit library for real-time clock rtc so we are including the library here and from this
inside that there is a class and we are creating an object called rtc and this from this class for
display we use an instance of it and we create a object called segment and this and here we defined
and here we set the I square c address 0x70 watch the introduction video to this so you
will understand why we need that and these are the settings for the clock here we say show clock
show second true if we set that to true you will see here the time the seconds will be displayed
and this one 10 seconds mean after 10 seconds that this will be displayed whatever time you
set that is the intervals and the blank if you set this to sex three or five so
that number of times the second will blink and if you set it based on not blank based on time
then it will be for five seconds it will display without blinking and here show leading zero if
you said that you will see this if it's less than ten o'clock nine or from one to nine from zero to
nine you will see leading zero here but if you set this to false you will not see it and also show
second no blank if you don't want this to blink and just increment the number set this to true
this is used inside the code show second one show second two are functions
prototype that are used within the code this is part of the
clock to display it on the screen if you use it on the serial monitor inside the setup we check
for leonardo micro and zero if serial is not available it will just stay there
and this line initializes the real-time clock rtc.begin and this means not
if it is not true if it is not initialized then it will print this error for you
while one mean keeps it forever waiting and again there is another function is called
is running this is just redundant you can remove it and this line is printing on the serial monitor
this text this one that you see is coming from here this 9600
if you click on tools serial monitor or press ctrl shift m or open click in here the number that you
see on the right side on the lower section is 9600 if you set different number it will you will not
be able to see that this text make sure to set it to 99 000 seconds 600 so you can see the text
and this line if you want to set the time use it like this rtc adjust date time when
you say the time it takes the time and date from computer whatever is on your computer it will be
transferred here and I’ve not updated it but if you want to use your own time then do not use
this date and time and enter manually this is the year that's the month that's the day hour minute
and second so and uncomment that and set your own time so this will set you around time but you need
it only once you don't need to set it every time you just need it only once and once you upload it
the time will be set and this segment dot begin that's for the display that's for the speed of
I square c communication that is displaying that's setting the display on so turn this on
and sets the number of digits to four and this sets the test when you restart it if
I restart it you will see one test in terms of oh turns on all the segments
and this will turn it off because some of the segments will stay on so we'd have to turn it off
50 millisecond delay and then turn it on and then this sets the brightness from 1 to 15 which I’m
going to demonstrate it and from here we check if show leading zero is set to true to display zero
then it sets the spray to four otherwise it says set to three so this means otherwise
so it will set three digits so that zero will disappear if you don't like it and here we
initialize the rtc we create an object called now which we will use to get the time and here
segment display time this will display time and we pass hour using this now now dot hour will get
time for hour and now that minute will get the minute from this object and we'll pass it to
the display display column one min display this column keep it on for 500 millisecond
and display zero mean turn off and it will turn it off when the time is displayed so that blank
is coming due to these lines and here if we want to display the second after few seconds here
show second new blank if that is set then we go to uh show second
two function otherwise we go to shoe second one function which I’m going to explain them
and here show second one we get the second blank count how many times you want to blanket and we
store it here so we can update this not this and then here if show second is set to true
which means to display the second then we get the current millisecond subtract it from the
remember time which we give this millisecond to this because this will increment continuously
from the time that you start Arduino and we check it if it is greater than let's say if
it was set to five second then we know that okay the time has passed let's go for the count and
then the y will go with a count if it was three so if it is greater than zero which means three
then we get the time and then we increment the decrement account by subtracting one from it
and in this line we set the digit to two so the minute and hour will the hour will disappear
and then we display now second the second will be pass here and that's coming and this will turn it
off keep it on and then turn it off and then keep it off and then turn it on so that's why it was
blinking and then we set the time so we know how much time has passed we just remember this
to this variable we do exactly the same with show second two the difference is this time
the count is not one or two or three but it is five thousand
millisecond or whatever second you want for example three seconds for this to be displayed
so the counter will do the same thing exactly except we don't have here turn off
and on here we have display off and display on with some delay so it was blinking and here we
don't have it we just wait 50 millisecond it will uh run the loop this while loop until
whatever time you set pass like four second five seconds it will display and disappear and then
print time will print the time on the serial monitor which I just shown
and here now let me demonstrate it as you can see that the clock is running
and let's first set the time not with a computer but our own time
the year doesn't matter that's month day and hour let me set it to eight
and one and let me upload it so you will see the time will set from here
eight and one and it's started but and if you want to now display the leading zero here
if you set this to false and upload it and you will see that the leading zero
once the code is uploaded will disappear and now if you say show blank no blank right
now look after this 10 second it goes here and blinks six times because it is set to six times
let me set this to five seconds and here we say no blank if you say no blink to true
and upload the code then when it shows the second it will not blink it will be just a counter
now five seconds I set this to 5 second
and now it will be just number will increment
and it will come back and here show second if you set it to false this will not be displayed
and the code when it could approach that's that this is a test
so now it after five seconds or whatever it doesn't go because we set it to false and it
will never display the second and this one this line sets the brightness if you set it to 15
it will be very bright let's see
my room is a little bright I hope you can see the difference now it's very bright
now let's set it to one very dim so you can see it the difference perhaps on camera
now it's very dim but I’m gonna put it to 10 which is
because you in some environment you need to dim it because otherwise it will be very annoying
in dark rooms and also save energy if you want and power it up with battery
now let's set the time back to my computer time whatever it is upload it so so it will be this
from my computer whatever I have 1108 and you can see there is few seconds delay two or three
seconds when we upload the code so keep that in mind there is a delay because when the usb
when the usb puts a code and compiles it it gets the value and takes some time
thank you for watching an Arduino tutorial from robojax if you learned something and
found this useful please thumb up as this will help my video in the search algorithm of youtube
if you have comment or question please post it at the comment section below
I try to answer and reply and don't forget subscribe to get updates on my upcoming videos
a separate video with digital clock for this ds-3231 make sure to watch that video the
link is below the video in the description this tutorial I’m going to show you how we can build
an led seven segment display clock that's why we are using from pen two to thirteen and here is
the wiring diagram then we have c d e and because we have six wire here six pins on this an issue
here with the blank this goes half a second in this tutorial we are going to learn how to use
the millis or millisecond in Arduino programming in this video we are going to do the led blank
with different duration on time and off time using millet we are not going to use the delay