Components and supplies
Nokia 5110 LCD
rtc ds1302 module
Arduino Nano R3
Breadboard (generic)
Pir module
Project description
Code
RTC Nokia5110 and Nano
arduino
1#include <Arduino.h> 2#include <Ds1302.h> 3#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library 4#include <LowPower.h> 5 int Pir = 11; 6 int Screen = 10; 7 bool State = false; 8 9 10// DS1302 RTC instance 11Ds1302 rtc(9,7,8); // 12// Nokia 5110 LCD module connections CLK, DIN, D/C, CS, RST (opposite to the actual pin positions !!) 13Adafruit_PCD8544 display = Adafruit_PCD8544(6,5,4,3,2); 14const static char* WeekDays[] = 15{ 16 " Mon ", 17 " Tues ", 18 " Wed ", 19 " Thurs ", 20 " Fri ", 21 " Sat ", 22 " Sun " 23}; 24 25 26void setup() { 27 pinMode(Pir,INPUT); 28 pinMode(Screen,OUTPUT); 29 display.begin(); 30 // initialize the RTC 31 rtc.init(); 32 display.setContrast(60); 33 display.clearDisplay(); // clears the screen and buffer 34 display.drawRect(0, 0, 84, 30, BLACK); 35 display.drawRect(0, 29, 84, 12, BLACK); 36 37} 38 39 40void loop() 41{ 42 if (digitalRead(Pir) == HIGH && State == false) { 43 digitalWrite(Screen,HIGH); 44 State = true; 45 } 46 if (digitalRead(Pir) == LOW && State == true) { 47 digitalWrite(Screen,LOW); 48 State = false; 49 } 50 // get the current time 51 Ds1302::DateTime now; 52 rtc.getDateTime(&now); 53 static uint8_t last_second = 0; 54 if (last_second != now.second) 55 { 56 last_second = now.second; 57 58 display.setTextColor(BLACK); 59 display.setTextSize(2); 60 display.setCursor(6,10); 61 if (now.hour <= 9) { //If Hour is single figures, put a 0 in front 62 display.print("0"); 63 } 64 display.print(now.hour); 65 display.print(":"); 66 if (now.minute <= 9) { //If Minute is single figures, put a 0 in front 67 display.print("0"); 68 } 69 display.print(now.minute); 70 // display.print(":"); 71 display.setTextSize(1); 72 if (now.second <= 9) { //If Seconds is single figures, put a 0 in front 73 display.print("0"); 74 } 75 display.print(now.second); 76 77 78 display.setCursor(0,31); 79 display.print(WeekDays[now.dow -1]); 80 display.print(now.day); 81 display.print("/"); 82 display.print(now.month); 83 84 display.display(); 85 86 87 display.setTextColor(WHITE); 88 display.setCursor(0,31); 89 display.print(WeekDays[now.dow -1]); 90 display.print(now.day); 91 display.print("/"); 92 display.print(now.month); 93 94 95 96 display.setTextSize(2); 97 display.setCursor(6,10); 98 if (now.hour <= 9) { 99 display.print("0"); 100 } 101 display.print(now.hour); 102 display.print(":"); 103 if (now.minute <= 9) { 104 display.print("0"); 105 } 106 display.print(now.minute); 107 // display.print(":"); 108 display.setTextSize(1); 109 if (now.second <= 9) { 110 display.print("0"); 111 } 112 display.print(now.second); 113 114// No need to display the screen again 115 116 } 117 // delay(100); 118 LowPower.powerDown(SLEEP_250MS,ADC_OFF,BOD_OFF); 119} 120
RTC Nokia5110 and Nano
arduino
1#include <Arduino.h> 2#include <Ds1302.h> 3#include <Adafruit_PCD8544.h> 4 // include adafruit PCD8544 (Nokia 5110) library 5#include <LowPower.h> 6 7 int Pir = 11; 8 int Screen = 10; 9 bool State = false; 10 11 12// DS1302 13 RTC instance 14Ds1302 rtc(9,7,8); // 15// Nokia 5110 LCD module connections CLK, 16 DIN, D/C, CS, RST (opposite to the actual pin positions !!) 17Adafruit_PCD8544 18 display = Adafruit_PCD8544(6,5,4,3,2); 19const static char* WeekDays[] = 20{ 21 22 " Mon ", 23 " Tues ", 24 " Wed ", 25 " Thurs ", 26 27 " Fri ", 28 " Sat ", 29 " Sun " 30}; 31 32 33void 34 setup() { 35 pinMode(Pir,INPUT); 36 pinMode(Screen,OUTPUT); 37 display.begin(); 38 39 // initialize the RTC 40 rtc.init(); 41 display.setContrast(60); 42 43 display.clearDisplay(); // clears the screen and buffer 44 display.drawRect(0, 45 0, 84, 30, BLACK); 46 display.drawRect(0, 29, 84, 12, BLACK); 47 48} 49 50 51void 52 loop() 53{ 54 if (digitalRead(Pir) == HIGH && State == false) { 55 digitalWrite(Screen,HIGH); 56 57 State = true; 58 } 59 if (digitalRead(Pir) == LOW && State == true) 60 { 61 digitalWrite(Screen,LOW); 62 State = false; 63 } 64 // 65 get the current time 66 Ds1302::DateTime now; 67 rtc.getDateTime(&now); 68 69 static uint8_t last_second = 0; 70 if (last_second != now.second) 71 { 72 73 last_second = now.second; 74 75 display.setTextColor(BLACK); 76 77 display.setTextSize(2); 78 display.setCursor(6,10); 79 if 80 (now.hour <= 9) { //If Hour is single figures, put a 0 in front 81 display.print("0"); 82 83 } 84 display.print(now.hour); 85 display.print(":"); 86 87 if (now.minute <= 9) { //If Minute is single figures, put a 0 in front 88 89 display.print("0"); 90 } 91 display.print(now.minute); 92 93 // display.print(":"); 94 display.setTextSize(1); 95 if 96 (now.second <= 9) { //If Seconds is single figures, put a 0 in front 97 display.print("0"); 98 99 } 100 display.print(now.second); 101 102 103 display.setCursor(0,31); 104 105 display.print(WeekDays[now.dow -1]); 106 display.print(now.day); 107 108 display.print("/"); 109 display.print(now.month); 110 111 112 display.display(); 113 114 115 display.setTextColor(WHITE); 116 117 display.setCursor(0,31); 118 display.print(WeekDays[now.dow -1]); 119 120 display.print(now.day); 121 display.print("/"); 122 display.print(now.month); 123 124 125 126 127 display.setTextSize(2); 128 129 display.setCursor(6,10); 130 if (now.hour <= 9) { 131 display.print("0"); 132 133 } 134 display.print(now.hour); 135 display.print(":"); 136 if 137 (now.minute <= 9) { 138 display.print("0"); 139 } 140 display.print(now.minute); 141 142 // display.print(":"); 143 display.setTextSize(1); 144 if (now.second 145 <= 9) { 146 display.print("0"); 147 } 148 display.print(now.second); 149 150 151// No need to display the screen again 152 153 } 154 // delay(100); 155 156 LowPower.powerDown(SLEEP_250MS,ADC_OFF,BOD_OFF); 157} 158
Downloadable files
Nokia Lcd Nano Rtc Pir
Nokia Lcd Nano Rtc Pir
Comments
Only logged in users can leave comments
stevie135s
5 Followers
•11 Projects
0
0