stevie135s
Published © CC BY-SA

RTC DS1302 Clock on Nokia5110 with a Nano

Real Time Clock DS1302 using Arduino nano, Power Saver and Pir activated backlight (optional)

BeginnerProtip644
RTC DS1302 Clock on Nokia5110 with a Nano

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Adafruit Nokia 5110 LCD
×1
rtc ds1302 module
×1
Pir module
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

Nokia Lcd Nano Rtc Pir

Code

RTC Nokia5110 and Nano

Arduino
#include <Arduino.h>
#include <Ds1302.h>
#include <Adafruit_PCD8544.h>  // include adafruit PCD8544 (Nokia 5110) library
#include <LowPower.h>
 int Pir = 11;
 int Screen = 10;
 bool State = false;

 
// DS1302 RTC instance
Ds1302 rtc(9,7,8); // 
// Nokia 5110 LCD module connections CLK, DIN, D/C, CS, RST (opposite to the actual pin positions !!)
Adafruit_PCD8544 display = Adafruit_PCD8544(6,5,4,3,2);
const static char* WeekDays[] =
{
    "  Mon   ",
    " Tues   ",
    "  Wed   ",
    " Thurs  ",
    "  Fri   ",
    "  Sat   ",
    "  Sun   "
};


void setup() {
    pinMode(Pir,INPUT);
    pinMode(Screen,OUTPUT);
    display.begin();
    // initialize the RTC
    rtc.init();
    display.setContrast(60);
    display.clearDisplay();   // clears the screen and buffer
    display.drawRect(0, 0, 84, 30, BLACK);
    display.drawRect(0, 29, 84, 12, BLACK);
    
}


void loop()
{
    if (digitalRead(Pir) == HIGH && State == false)  {
      digitalWrite(Screen,HIGH);
      State = true;
    }
    if (digitalRead(Pir) == LOW && State == true)  {
      digitalWrite(Screen,LOW);
      State = false;
    }
    // get the current time
    Ds1302::DateTime now;
    rtc.getDateTime(&now);
    static uint8_t last_second = 0;
    if (last_second != now.second)
    {
        last_second = now.second;

        display.setTextColor(BLACK);
        display.setTextSize(2);
        display.setCursor(6,10);
        if (now.hour <= 9) { //If Hour is single figures, put a 0 in front
        display.print("0");
        }
        display.print(now.hour);
        display.print(":");
     if (now.minute <= 9) {  //If Minute is single figures, put a 0 in front
        display.print("0");
     }
        display.print(now.minute);
  //      display.print(":");
        display.setTextSize(1); 
        if (now.second <= 9) {  //If Seconds is single figures, put a 0 in front
        display.print("0");
     } 
        display.print(now.second);

        
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print("/");
        display.print(now.month);
        
        display.display();

        
        display.setTextColor(WHITE);
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print("/");
        display.print(now.month);           
        
                
        
        display.setTextSize(2);
        display.setCursor(6,10);
     if (now.hour <= 9) {
        display.print("0");
    }
       display.print(now.hour);
       display.print(":");
     if (now.minute <= 9) {
       display.print("0");
  }
       display.print(now.minute);
  //     display.print(":");
       display.setTextSize(1);
     if (now.second <= 9) {
       display.print("0");
  } 
      display.print(now.second);
 
// No need to display the screen again
 
    }
  //  delay(100);
  LowPower.powerDown(SLEEP_250MS,ADC_OFF,BOD_OFF);
}

Credits

stevie135s
28 projects • 12 followers
I've been interested in microprocessors for a long time.

Comments