Arduino Tutorial 35- Real Time Clock using DS1302 RTC Module

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome back to my youtube channel so in this new tutorial we're going to create a real-time clock as you can see we have the date and the time displayed on this lcd display basically we're going to use this module that is called rtc or real-time clock i'm using the ds-1302 module but you could use other versions we're going to use a library that supports more than one version of this rtc module so before we get started consider subscribing to our channel and hit the bell icon that helps me a lot and let's jump right into it [Music] so in this new tutorial you will need the arduino uno the lcd display and the rtc module so this is called the s1302 rtc module which we're gonna use to get the date and the time then we're gonna display it on this lcd display first let's see how to hook it up to the arduino as you can see it consists of 5 pins we have the vcc which goes to the 5 volt pin of the arduino or in this video we're gonna use the 3.3 volts and we're gonna use the 5 volt pin to power the lcd display then we have the gnd which goes to the gnd of the arduino after that we have three more pens the clk or clock the data pin and the reset pin or rst we're gonna hook up these to the digital pins number six seven and eight of course you could use any of the digital pens in this video we're gonna connect the clk to the digital pin number six the data goes to digital pin number seven and finally the rst goes to digital pin number eight i'm gonna take the red wire and connect the vcc of the module to the 3.3 volts we're gonna use the five volts to power the lcd display then we have the gnd goes to the gnd of the arduino after that i'm gonna connect the clk to the digital pin number six the data goes to digital pin number seven and finally we have the rst i'm gonna hook it up to digital pin number eight also we're gonna need this lcd display i've talked about it in our previous videos make sure to check it out you could follow this image we're gonna connect the gnd to the gnd the vcc to the five volt pin of the arduino then we have the sda and the scl the sda needs to be connected to the analog pan a4 and the scl goes to the analog pin a5 you could also use these two pins so this is the sda and this is the sel as you can see we have our four wires i'm gonna connect the brown wire to the gnd the red wire is the vcc which goes to the five volt pin of the arduino then we have the yellow wire is the sel which goes to the analog pin a5 and the sda goes to the analog pin a4 now let's plug the usb cable so that we can upload the code first you will need to install two libraries you could go to tools then manage libraries the first one is liquidy crystal underscore i2c basically you need to go all the way down and search for the same name liquid crystal i2c and it is this library by marco schwartz i've already installed it and we have another library to deal with the rtc module just search for rtc then ds and it is the second one rtc by makuna and as you can see it supports more than one version of the rtc module like the ds-1302 the 1307 and so on you could also use other boards like the esp8266 anyway once you install this library let's explain the code that will display the date and the time first i've included these libraries like the liquid crystal underscore i2c then we have three wire dot h and the rtcds1302.h so this comes with the second library by makuna then we've created two objects the first one is the lcd display with these three parameters this is the address of the i2c module then we have the number of columns and the number of rows i've talked about the lcd display in one of my previous videos go ahead and check it out then you need to add two more objects the first one is three wire the name is my wire you could call it whatever you want then we have to pass in three numbers and these are the data the clock and the rst pens so make sure to put these in this order then we've created the rtc object so the type is rtcds1302 and it takes the three wire object then i've called it rtc and this takes the wires which is this object my wire then under the setup function we've used these lines of code to initialize the lcd display then we've added rtc.begin after that i've created this rtc datetime object so whenever you start using this module you need to fix the date and the time then this module uses this battery to keep track of the date and the time anyway you will use these lines of code once then you could get rid of them basically we are getting the current time using the rtcdatetime object this takes the date and the time so these are built-in variables that you could use to get the date and the time from this computer after that we can set it using rtc dot set date time and this method takes the object current time and it will fix it so let's upload the code but before that make sure that you have this battery plugged in then we can get rid of these lines of code or let's comment this and under the loop function we can get the current time by creating this rtc date time object i gave it a name now equals rtc dot getdatetime so this method returns the date and the time as an rtc daytime object then i've used the methods now.day to get the day now.month to get the month and so on first we need to clear the lcd display and set the cursor at the first column and the first row after that we can print the date using the date message then we add the day and the slash then the month and the year after that i've changed the position of the cursor to the second line using set cursor 0 1 so 1 is the index of the second row then i've printed the time and added the values now.hour to get the current hour now.minute and finally now.second and these are separated using this column and finally i've added a little bit of delay and that's pretty much it so you will find this code under the description of the video let's upload it again without these lines of code and there you go we have a real-time clock as you can see we have the date on top and the time at the bottom and if we unplug the usb cable this module will save the date and the time and whenever the power goes back you see it's correct so i hope you enjoyed this video if you have any question or comment make sure to write it under the comment section down below in the next video we are going to improve this project a bit basically we're gonna add this keypad i've talked about the keypad in one of my previous videos make sure to check it out we're gonna hook it up to the arduino then we'll be able to fix the date and the time using these buttons so try to think about it and i will see you in the next one you
Info
Channel: Enjoy Mechatronics
Views: 72,264
Rating: undefined out of 5
Keywords: Arduino, tutorial, enjoy mechatronics, how to, electronic, microcontroller, coding, lessons, software, arduino uno, electronics, programming, getting started, Tutorial, DS1302, Real Time Clock, Arduino RTC, real time clock, arduino tutorial, arduino clock, Tiny RTC, arduino uno r3, arduino poject, real time module, ds3231 arduino module, ds3231 arduino clock, ds3231 arduino code, ds1302rtc arduino code, arduino real time clock, LCD, ds1307, Liquid Crystal
Id: MfmK55TREuQ
Channel Id: undefined
Length: 10min 6sec (606 seconds)
Published: Fri Apr 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.