I needed to check the accuracy of the internal clock of Arduino for another project, so I wrote this code. Only Time and LiquidCrystal libraries are included. Not that fancy but the accuracy turned out to be fine. Error<1 min for a day. With addition of a few buttons, you can set the time. Yet I am not sure if powering the board with USB or 9V battery would change the accuracy or not. I would appreciate any comments on that.
Cheers,
Bb
#include <Time.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//set the current time here
int s=30;
int h=0;
int m=5;
void setup(){
lcd.begin (16,2);
delay(500);
lcd.clear();
lcd.print("Current Time:");
lcd.setCursor(0,1);
}
void clc(){
lcd.clear();
lcd.home();
lcd.print("Current Time:");
lcd.setCursor(0,1);
}
void loop(){
lcd.setCursor(0,1);
while(millis()%1000 != 0);
s +=1;
if(s==60){ s=0; m +=1;}
if(m==60){ m=0; h +=1;clc();}
if(h==24){h=1;}
lcd.print(int(h/10));
lcd.print(h%10);
lcd.print(":");
lcd.print(int(m/10));
lcd.print(m%10);
lcd.print(":");
lcd.print(int(s/10));
lcd.print(s%10);
}