 This right here is an RTC module, also known as a real-time clock. An RTC module is like a mini clock inside of electronic gadgets. It's job and the only thing it has to do is to keep track of the current time, even when the main device is turned off. Before we get started on everything you need to know about how to integrate this into your projects, all I want to say is that if you enjoy these type of breakdown tutorial videos, all you got to do is subscribe to the channel and give the video a like to Just like a wristwatch keeps time, an RTC module keeps time for electronic devices. It tells them the current hour, minute, second, and even the date. An RTC module usually has a super small battery like the one that you can see here, I think they're called coin cell batteries. And that's what allows you to keep this thing powered, even if the mainline or the whole project loses power, so that you're always keeping track of time no matter what. Because if you only counted time when you had power, if you didn't have power for five minutes and then you continued counting time, you would be five minutes off of the real world time. So by keeping a battery in this module, we can make sure that it always has a power source so that it will never lose track. Inside the RTC, there's a tiny piece of quartz crystal, just like in many wristwatches. And when you run electricity through a quartz, it vibrates at a very precise frequency. Then the RTC can listen to those vibrations to count seconds, minutes, hours, days, and more. And super accurately, it's like counting ticks of a watch or a clock. Every time you hear tick, let's say it would be one tick, one second. On the actual board, there's also a little bit of memory so that whenever we count time, it stores it on the board so that if anything happens, we can always check what the last counted time was on it. So when you turn on a device, the RTC module has the time already set to it. So if you wanted to do something based off of time, like every morning at eight in the morning, you want to water the plants, you can use this to keep track of the time. And then when it's eight in the morning, you can activate a pump to push water to your plants. So an RTC module is really essential for most devices to keep track of time accurately. We have them in our computers, servers, smartphones, appliances, they're absolutely everywhere. To use this in a demo, we're going to need a couple different things. You're going to need a microcontroller. Me, I'm going to be using Arduino. You're going to need the actual module, and you're going to need some cables to connect it all up. We're only going to need four cables today. On the RTC module, we have five pins starting with ground, VCC, SDA, SCL, and SQW. On the RTC module, we have five different pins starting with ground, then VCC, SDA, SCL, and SQW. We're only going to be using the first four. So you do not need to use SQW or yours might say DS. Either way for the pinout, I would recommend looking at what the name of your board is and then search up your microcontroller. So let's say Arduino, then this, and then pinout. And it'll show you the wiring diagram for your specific setup. So we're just going to go and plug into the first four cables. And then we're going to run these cables to the Arduino. As always, we have ground and VCC. We're going to be running our ground to ground. And our VCC, we're going to use five volts. So in my case, that's the yellow cable that's going to go into five volts. Then we have SCL and SDA. SDA is going to go to A4 and SCL is going to go to A5. Now, like I said before, depending on your board, those numbers might change. So just make sure you look up for your board and for your specific RTC module, what the wiring diagram is. After that, the rest should be pretty much the same. So let's just plug Arduino into the computer and we can get started with the code. To make our lives a little bit easier, we're going to be using a library today. So we're just going to go and include RTC lib, which we're going to have to go and download in our library manager. One thing, before we start on the code, I made a little mistake, reverse the SCL and the SDA. So SCL should be going to pin number four, A4, and SCL should be going to A5. So we go for this one right here, RTC lib by Adafruit. We're just going to install that and install all the packages that are related to that. That should take a second and then we're good to go. Once you have your library, the next step you can do is declare an RTC library for your specific module. So us, it's D1,307. And then we're going to call that to RTC, which is going to be what we're going to call it, just our variable name. After that, this you can just copy paste. It's just going to be an array of the days of the week. So Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday. Then in our setup, we can do two things, which is declare our serial dot begin so that we can start putting things in the console. And then a little function that if there's an error and the RTC clock is not communicating with our board, we're just going to exit the program or we're going to throw an error. So we're going to put in the console that we couldn't find RTC. And we're going to serial flush and we're going to do a little while loop to make sure we don't continue with any other part of the code. Then once you make sure your RTC clock is connected, you can move on to do this part right here. In here, we're going to set our RTC's memory, so the actual memory on the board where it starts counting. We're going to set it here with the PC time and date. So it's going to read off of your computer. So we're hoping your computer is at least somewhat accurate. And then using that number, it will count now forever until the battery dies. So this you would only technically have to run once when you run the program and then you can comment it out and never run it again. Or let's say your computer, it's slightly off or it's not the time zone you want to use. You can use this right here, starting with the year and going down to the minute and hour. So that would actually mean this. January 22nd, 2021 at 3 a.m. Because 3-0-0, 3 a.m. Now once we have everything set up, we're good to move on to our loop. And in our loop, it's just going to be a massive wall of printing. We're just going to print everything off of our RTC clock. So we're going to go date time now. Now being our time that we're reading at this moment off of our RTC. So RTC.now is going to give us our time at this second. And then we're going to go and we're going to read every specific part of that. So year, month, day, day of the week. And then we're going to put day of the week here and that's going to pull whatever word we want here. Because technically it's going to give us Sunday, Monday, Tuesday, whatever as one, two, three, four, five, six, seven. So just by putting a number there, we can actually call on the text so we can actually understand what it means by day of the week. Then close that off in the brackets. Hour, minute, second, and that's it. And then in each one we say for decimal. Because we're doing a conversion. Because we're getting certain style of data from here. And then we're going to convert it into something readable using all these different techniques. So we're going to upload that to the board. We're going to make sure everything's saved. No upload port provided. So we have to click on here, select the board. We're going to make sure it uploads to the board. And we have a delay of one second to make sure it doesn't go crazy. Now that it's done, we're just going to go to tools, serial monitor. We're going to clear the console. And we can see here now we get date and time. Today is Thursday at 10 o'clock. And I can confirm that it is 12, 14, 2023. Here it's written weird. I would have done it, you know, the American or Canadian way. But as you can see, the RTC module is holding time. Now one thing I want to show you is, let's say we comment out this piece of code right here. This piece of code is what resets the new time. So now if I turn it off and I start it again, we can see that the time it's accurate. We can see that it's exactly 10.02. So 10, 2, and this is the second counter. And then eventually it'll turn to 10.03. And that's because the battery in the RTC module keeps it alive. Let's call it that. But what if we unplug the Arduino so that it stops printing the time, then we go to the RTC module and we actually remove the battery. Now I might need some tools to do this, but we're going to make it happen. Looks like I broke it, but we should still be good to go. So now the battery is out. The RTC module is not running. So let's wait a little bit. And then I'm going to upload to the board again. We're going to go read from the serial monitor. And we can see now we're getting 0000 because something went wrong. The RTC module is not keeping time anymore. It has completely restarted. It's lost power. It doesn't know what's happening. Now what I could do is let's say go in here, uncomment this, and reset the module again. So we're going to start the code and let's clear this out quickly. You can see it's going to go back to a normal time. 1004, I can confirm. It's 1004. But what happens if we unplug and re-plug? So let's unplug at 1045. 104445. So here, 10445. And then I'm going to plug it back in. And most of us would expect it to be now 10 and 5. But as you can see, all it's doing is continuing to account where it's left off. So right now, in the real world, it's 1005. But here, but right here, it's still 1004 for at least another 10 seconds. So once again, if we unplug everything, we'll put a little battery in there. Re-plug it. We set the new time. Then we uncomment that. And we re-upload the code one more time. We can see that now we're at an accurate time. And as long as the RTC module has that little battery, and I think should run forever, I think there's a calculation of how long it should run technically. It's like, I don't know, some crazy number, like 30 years or some crazy number. I'll put it up on the screen. So as long as that thing has power, no matter what, if I take the power cable, wherever it is, it's this one and I unplug it. And now the RTC module doesn't have power. We're still going to have accurate time. So that's how the RTC module works. Everything you need to know about it, how it works down in a technical way, how to use it, make sure you have a battery in it, all the good things. And that's all we have for the breakdown for the RTC module. I hope this helped you understand how it works technically, how to connect it up, and how to make it work for your own projects. Now all you need to do is take that time and do something with it. If you have any questions, concerns, things I missed, things I made a mistake for, let me know in the comments or join the Discord where we have people that can help you out. If you want to support this video, all you got to do is give the video a like and subscribe to the channel to support the channel. I think in the next video, we're going over wireless phone chargers, how they work, and how to make them yourself. So if you're looking forward to that, I'll see you there.