Arduino Digital Clock
Digital Clock without RTC
Components and supplies
3
Pushbutton Switch, Pushbutton
1
Jumper wires (generic)
1
Alphanumeric LCD, 16 x 2
1
Breadboard (generic)
1
Single Turn Potentiometer- 10k ohms
1
Resistor 330 ohm
1
Arduino Nano R3
Tools and machines
1
Scissor, Electrician
Apps and platforms
1
Arduino IDE
Project description
Code
Code
arduino
1// https://www.youtube.com/channel/UCaXI2PcsTlH5g0et67kdD6g // 2// Arduino Digital Clock // 3// By MOHD SOHAIL // 4 5#include <LiquidCrystal.h> 6 7LiquidCrystal lcd(2,3,4,5,6,7); 8int s,m,h,a,d,state,state1,state2,dg,cnt; 9 10// the 8 arrays that form each segment of the custom numbers 11byte bar1[8] = 12{ 13 B11100, 14 B11110, 15 B11110, 16 B11110, 17 B11110, 18 B11110, 19 B11110, 20 B11100 21}; 22byte bar2[8] = 23{ 24 B00111, 25 B01111, 26 B01111, 27 B01111, 28 B01111, 29 B01111, 30 B01111, 31 B00111 32}; 33byte bar3[8] = 34{ 35 B11111, 36 B11111, 37 B00000, 38 B00000, 39 B00000, 40 B00000, 41 B11111, 42 B11111 43}; 44byte bar4[8] = 45{ 46 B11110, 47 B11100, 48 B00000, 49 B00000, 50 B00000, 51 B00000, 52 B11000, 53 B11100 54}; 55byte bar5[8] = 56{ 57 B01111, 58 B00111, 59 B00000, 60 B00000, 61 B00000, 62 B00000, 63 B00011, 64 B00111 65}; 66byte bar6[8] = 67{ 68 B00000, 69 B00000, 70 B00000, 71 B00000, 72 B00000, 73 B00000, 74 B11111, 75 B11111 76}; 77byte bar7[8] = 78{ 79 B00000, 80 B00000, 81 B00000, 82 B00000, 83 B00000, 84 B00000, 85 B00111, 86 B01111 87}; 88byte bar8[8] = 89{ 90 B11111, 91 B11111, 92 B00000, 93 B00000, 94 B00000, 95 B00000, 96 B00000, 97 B00000 98}; 99 100 101 102void setup() 103{ 104 // assignes each segment a write number 105 lcd.createChar(1,bar1); 106 lcd.createChar(2,bar2); 107 lcd.createChar(3,bar3); 108 lcd.createChar(4,bar4); 109 lcd.createChar(5,bar5); 110 lcd.createChar(6,bar6); 111 lcd.createChar(7,bar7); 112 lcd.createChar(8,bar8); 113 state=1; 114 state1=1; 115 state2=1; 116 // sets the LCD's rows and colums: 117 lcd.begin(16, 2); 118 pinMode(8,INPUT_PULLUP); 119 pinMode(9,INPUT_PULLUP); 120 pinMode(10,INPUT_PULLUP); 121 s=0; 122 m=0; 123 h=0; 124a=0; 125} 126 127void custom0(int col) 128{ // uses segments to build the number 0 129 lcd.setCursor(col, 0); 130 lcd.write(2); 131 lcd.write(8); 132 lcd.write(1); 133 lcd.setCursor(col, 1); 134 lcd.write(2); 135 lcd.write(6); 136 lcd.write(1); 137} 138 139void custom1(int col) 140{ 141 lcd.setCursor(col,0); 142 lcd.write(32); 143 lcd.write(32); 144 lcd.write(1); 145 lcd.setCursor(col,1); 146 lcd.write(32); 147 lcd.write(32); 148 lcd.write(1); 149} 150 151void custom2(int col) 152{ 153 lcd.setCursor(col,0); 154 lcd.write(5); 155 lcd.write(3); 156 lcd.write(1); 157 lcd.setCursor(col, 1); 158 lcd.write(2); 159 lcd.write(6); 160 lcd.write(6); 161} 162 163void custom3(int col) 164{ 165 lcd.setCursor(col,0); 166 lcd.write(5); 167 lcd.write(3); 168 lcd.write(1); 169 lcd.setCursor(col, 1); 170 lcd.write(7); 171 lcd.write(6); 172 lcd.write(1); 173} 174 175void custom4(int col) 176{ 177 lcd.setCursor(col,0); 178 lcd.write(2); 179 lcd.write(6); 180 lcd.write(1); 181 lcd.setCursor(col, 1); 182 lcd.write(32); 183 lcd.write(32); 184 lcd.write(1); 185} 186 187void custom5(int col) 188{ 189 lcd.setCursor(col,0); 190 lcd.write(2); 191 lcd.write(3); 192 lcd.write(4); 193 lcd.setCursor(col, 1); 194 lcd.write(7); 195 lcd.write(6); 196 lcd.write(1); 197} 198 199void custom6(int col) 200{ 201 lcd.setCursor(col,0); 202 lcd.write(2); 203 lcd.write(3); 204 lcd.write(4); 205 lcd.setCursor(col, 1); 206 lcd.write(2); 207 lcd.write(6); 208 lcd.write(1); 209} 210 211void custom7(int col) 212{ 213 lcd.setCursor(col,0); 214 lcd.write(2); 215 lcd.write(8); 216 lcd.write(1); 217 lcd.setCursor(col, 1); 218 lcd.write(32); 219 lcd.write(32); 220 lcd.write(1); 221} 222 223void custom8(int col) 224{ 225 lcd.setCursor(col, 0); 226 lcd.write(2); 227 lcd.write(3); 228 lcd.write(1); 229 lcd.setCursor(col, 1); 230 lcd.write(2); 231 lcd.write(6); 232 lcd.write(1); 233} 234 235void custom9(int col) 236{ 237 lcd.setCursor(col, 0); 238 lcd.write(2); 239 lcd.write(3); 240 lcd.write(1); 241 lcd.setCursor(col, 1); 242 lcd.write(7); 243 lcd.write(6); 244 lcd.write(1); 245} 246 247void printNumber(int value, int col) { 248 if (value == 0) { 249 custom0(col); 250 } if (value == 1) { 251 custom1(col); 252 } if (value == 2) { 253 custom2(col); 254 } if (value == 3) { 255 custom3(col); 256 } if (value == 4) { 257 custom4(col); 258 } if (value == 5) { 259 custom5(col); 260 } if (value == 6) { 261 custom6(col); 262 } if (value == 7) { 263 custom7(col); 264 } if (value == 8) { 265 custom8(col); 266 } if (value == 9) { 267 custom9(col); 268 } 269} 270 271 272 273 274 275 276 277 278 279 280 281void loop() 282 283{ 284 if(!digitalRead(8)&state==1){ 285 cnt++; 286 state=0; 287 if(cnt>3){ 288 cnt=0; 289 } 290 }else if(digitalRead(8)&state==0){ 291 state=1; 292 } 293 294if(!digitalRead(9)&&state1==1){ 295 dg=1; 296 state1=0; 297 298 }else if(digitalRead(9)&state1==0){ 299 state1=1; 300 } 301 302if(!digitalRead(10)&&state2==1){ 303 dg=-1; 304 state2=0; 305 }else if(digitalRead(10)&state2==0){ 306 state2=1; 307 } 308 switch(cnt){ 309 case 1: 310 m=m+dg; 311 dg=0; if(m>59){ 312 m=59;} 313 if(m<0){ 314 m=0;} 315 break; 316 317 case 2: 318 h=h+dg; 319 dg=0;if(h>11){ 320 h=11;} 321 if(h<0){ 322 h=0;} 323 break; 324 case 3: 325 if(dg==1){ 326 a=1; 327 dg=0;} 328 if(dg==-1){ 329 a=0; 330 dg=0;} 331 break; 332 } 333 if(s>59){ 334 s=0; 335 m++; 336 337 if(m>59){ 338 m=0; 339 h++; 340 341 if(h>11){ 342 h=0; 343 a=!a; 344 } 345 } 346 } 347 d=h%10; 348 printNumber(d, 3); 349 d=h/10; 350 printNumber(d, 0); 351 352 d=m%10; 353 printNumber(d, 10); 354 d=m/10; 355 printNumber(d, 7); 356 lcd.setCursor(14, 0); 357 if(a){ 358 lcd.print("AM"); 359 }else{ 360 lcd.print("PM"); 361 } 362 if(cnt==0){ 363 s++; 364 lcd.setCursor(6, 0); 365 lcd.print(" "); 366 lcd.setCursor(6, 1); 367 lcd.print(" "); 368 delay(500); 369 lcd.setCursor(6, 0); 370 lcd.print("."); 371 lcd.setCursor(6, 1); 372 lcd.print("."); 373 delay(500); 374 } 375} 376
Downloadable files
Circuit Diagram
Circuit Diagram

Circuit Diagram
Circuit Diagram

Comments
Only logged in users can leave comments