Arduino Clock

CLICK TITLE FOR MORE INFORMATION

Related Posts Plugin for WordPress, Blogger...After a long time, let me introduce another project of mine, and that is the Arduino Clock. This time it comes in 2 version, the 12 hour version and the 24 hour version (Version 2). I've used :

Arduino Uno
to function my project. Below would be the sketch for both versions :



12 Hour Version V2

Updated on 19/10/2011



int sec;
int mint;
int hour;
int apm;
int time;




void setup(){
  Serial.begin(9600);
}


void loop(){
  time=millis()/1000;
  if(time++){
    sec++;
  }
  if(sec/60==1){
    mint++;
  }
  if(mint/60==1){
    hour++;
  }
  if(hour==12 && mint==60 && sec==60){
    apm++;
  }
  if(sec==60){
    sec=0;
  }
  if(sec==61){
    sec=0;
  }
  if(mint==60){
    mint=0;
  }
  if(mint==61){
    mint=0;
  }
  if(hour==13){
    hour=0;
  }
  if(apm==2){
    apm=0;
  }
  if(hour<10){
    Serial.print("0");
  }
  Serial.print(hour);
  Serial.print(":");
  if(mint<10){
    Serial.print("0");
  }
  Serial.print(mint);
  Serial.print(":");
  if(sec<10){
    Serial.print("0");
  }
  Serial.print(sec);
  if(apm==0){
    Serial.println(" AM");
  }
  if(apm==1){
    Serial.println(" PM");
  }
  delay(1000);
}



24 Hour Version V2
Updated on 19/10/2011


int sec;
int mint;
int hour;
int time;




void setup(){
  Serial.begin(9600);
}


void loop(){
  time=millis()/1000;
  if(time++){
    sec++;
  }
  if(sec/60==1){
    mint++;
  }
  if(mint/60==1){
    hour++;
  }
  if(sec==60){
    sec=0;
  }
  if(sec==61){
    sec=0;
    sec++;
  }
  if(mint==60){
    mint=0;
  }
  if(mint==61){
    mint=0;
    mint++;
  }
  if(hour==24){
    hour=0;
  }
  if(hour==25){
    hour=0;
    hour++;
  }
  if(hour<10){
    Serial.print("0");
  }
  Serial.print(hour);
  Serial.print(":");
  if(mint<10){
    Serial.print("0");
  }
  Serial.print(mint);
  Serial.print(":");
  if(sec<10){
    Serial.print("0");
  }
  Serial.println(sec);
  delay(1000);
}




Want to know how it works? View the video below! (Arduino Clock V1)


2 Responses so far.

  1. Anonymous says:

    hi weng fei!!

    it a great project!!i want to try it..is there any schematic diagram for this?thanks

  2. Weng Fei says:

    For the project above (Arduino Clock), I've just used an Arduino Uno to make it work. There is no other components needed, that's the easy thing. Just upload the sketch above and open the Serial Monitor on the Arduino IDE to get the time. Enjoy!

    **I've updated the sketch, Version 2.

    by Weng Fei

Leave a Reply

Popular Posts