Real time clock DS1302 module and Nokia 5110 DIY lcd tutorial
Hey guys, in one of my previous tutorials, I made a tutorial on hoe to connect the nokia 5110 LCD to arduino, And now For this tutorial, we will be building something similar using the DS1302 RTC module and the Nokia 5110 display module.
What Will I Learn?
basically its on the title how`s the real time RTC and nokia 5110 LCD work together. and how to add zip file library to arduino IDE. so what is RTC DS1302 module its a micro controller like the arduino is simplified by using synchronous serial communication. Only three wires are required to communicate with the clock/RAM: reset(RST), data(DAT) line, and CLK (serial clock). enough of me speaking, let's just begin.
Requirements
CIRCUIT DIAGRAM
Difficulty
When its come to difficulties this tutorial is just a basic one, first we need to connect the wires and follow the diagrams download the zip file then connect the arduino to your computer then upload the code. so you have to follow the steps below.
Tutorial Contents
Lets start this First let's connect the Nokia 5110 display. Remember that the LCD runs on 3.3V pin on the uno board and some people have connected it to 5V, it has worked but gave some weird grahics effects, the LCD has 8 pins which will be connected to a specified pin ion the arduino.
The DS1302 module has a 3-wire communication interface with which it interacts with the microcontroller. A breakdown of its connection to the Arduino is given below
SOFTWARE
We are done building the circuit so lets start to set up and make a code for this. we are going to use the arduino ide, to set the sketch for this, if you dont have make sure to download the Arduino IDE for your specific operating system. I’ll leave a link to where you can download this software: https://www.arduino.cc/en/Main/Software
-To get the RTC code for DS1302 library we need to download the zip file library from https://github.com/msparks/arduino-ds1302
-To get the nokia 5110 LCD library we need to download the zip file from rinkydinkelectronics you can download it directly here http://www.rinkydinkelectronics.com/library.php?id=47
when the download is finished open the zip file then copy the folder name LCD5110_Graph and RTC DS1302 unzip the folder to your desktop you can rename it as well.
Cut the folder of the libraries in your desktop then go to your folders then locate the arduino folder>> libraries then paste it there. and now the folder LCD5110_Graph and the RTC DS1302 is already in the arduino ide libraries.
To make writing the code easy for us, the first thing we need to do is to download the https://github.com/msparks/arduino-ds1302/blob/master/DS1302.h . After downloading the library, extract it and paste into your arduino libraries folder after which we can launch our arduino IDE to start writing the code.
The first thing we need to do like with every other code, is include all the libraries we will be using. or enough just copy the code here;
SOURCE CODE
#include
#include
#include
LCD5110 lcd(8,9,10,12,11);
extern unsigned char BigNumbers[];
extern unsigned char SmallFont[];
extern uint8_t clock[];
namespace {
const int kCePin = 5; //RST
const int kIoPin = 6; //DAT
const int kSclkPin = 7; //CLK
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Sunday";
case Time::kMonday: return "Monday";
case Time::kTuesday: return "Tuesday";
case Time::kWednesday: return "Wednesday";
case Time::kThursday: return "Thursday";
case Time::kFriday: return "Friday";
case Time::kSaturday: return "Saturday";
}
return "(unknown day)";
}
}
void setup() {
setTime();
lcd.InitLCD();
lcd.clrScr();
lcd.drawBitmap(0, 0, clock, 84, 48);
lcd.update();
delay(3000);
}
void loop() {
printTime();
delay(1000);
}
void printTime() {
Time t = rtc.time();
const String day = dayAsString(t.day);
String month;
String date;
String hour;
String minutes;
month = String(t.mon);
date = String(t.date);
hour = String(t.hr);
minutes = String(t.min);
String fullDate = day+" "+month+"/"+date;
lcd.clrScr();
lcd.setFont(SmallFont);
lcd.print(fullDate,0,0);
lcd.setFont(BigNumbers);
if(t.hr<10)
{
hour = "0"+hour;
lcd.print(hour,7,18);
}else
{
lcd.print(hour,7,18);
}
lcd.print(".",35,18);
if(t.min<10)
{
minutes = "0"+minutes;
lcd.print(minutes,47,18);
}else
{
lcd.print(minutes,47,18);
}
lcd.update();
}
void setTime()
{
rtc.writeProtect(false);
rtc.halt(false);
Time t(2018, 1, 17, 12, 45, 50, Time::kWednesday); //Change this line to set time ex 2018 1/17 12:45:50
rtc.time(t);
}
On the last function (Void Settime()) of the code is for setting the time as the rtc ds1302 module does not come with the clock, correct.
To set the time, the first thing we need to do is turn off write protection for the ds1302 rtc module, so we can address it’s registers. Next we start the operation of the rtc using the rtc.halt(false) command. W/ this done the device is ready to recieve data, so we input the current time and date with kthursday if its a thursday or kmonday, if it’s a monday and so on (k)
lets upload it to the board and lets see how its works;
So thats it, This is my first project using the RTC module so i hope you enjoy this actitvity if want to learn how arduino works, and how to make a sketch, then maybe thisblog might help you, i was inspired by educ8 and electronic-lab for this wonderful stuff. so thats it, if you want to know and see my future activity follow me! and dont forget to follow me! thank you.
You can also check my previous posts:
How to connect nokia 5110 LCD to arduino
TM1637 4 digit 7-segment display with Arduino
How to adjust LED brightness using potentiometer/ visual programming XOD
How to make 12 LED chaser without shift
Control LED using Push Buttons/ Visual programming using XOD
Control Servo motor using Joystick
Stepper motor + Driver Uln2003 in arduino
Control Servo motor using potentiometer - arduino
Posted on Utopian.io - Rewarding Open Source Contributors












Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @pakganern I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x