Clock with Arduino

Clock with Arduino © GPL3+

Arduino clock, easy to assemble, you can set the date and time by the Serial monitor

  • 3,985 views
  • 2 comments
  • 10 respects

Components and supplies

Apps and online services

About this project

Arduino clock, easy to set up, you can set the date and time by the Serial monitor, this projects uses few components only jumpers, Arduino, and display Nokia 5110/3110, and ready

// pin 3 - Serial clock out (SCLK)

// pin 4 - Serial date out (DIN)

// pin 5 - date/Command select (D/C)

// pin 6 - LCD chip select (CS/CE)

// pin 7 - LCD reset (RST)

//Programa : Teste display Nokia 5110 usando biblioteca Adafruit 
//Autor : VINICIUS LOPES 
#include <Adafruit_GFX.h> 
#include <Adafruit_PCD8544.h> 
// pin 3 - Serial clock out (SCLK) 
// pin 4 - Serial date out (DIN) 
// pin 5 - date/Command select (D/C) 
// pin 6 - LCD chip select (CS/CE) 
// pin 7 - LCD reset (RST) 
Adafruit_PCD8544 display = Adafruit_PCD8544(3,4,5,6,7); 
int second,minute, hour, day, mounth,year;  
unsigned long UtlTime;  
void setup()  
pinMode(2,OUTPUT); 
UtlTime=0;   {    
minute=0;    
hour=0;    
day=0;    
mounth=0;    
year=0;    
Serial.begin(9600);    
 display.begin(); 
 display.setContrast(50); // Adjust the display contrast 
 display.clearDisplay();   //Apaga o buffer e o display 
 display.setTextSize(1);  //Seta o tamanho do texto 
 display.setTextColor(BLACK); //Seta a cor do texto       
display.print(" date e hour ");    
display.setCursor(0,10);    
display.print(" com Arduino");    
display.display(); 
delay (5000);  
//Configura o minute    
display.clearDisplay();    
display.setCursor(0,0);    
display.print("minute: "); 
display.display(); 
Serial.print("\nin between minute:");   
while(minute==0)   {      
if (Serial.available() > 0)      
{        
minute= Serial.parseInt();      
}    
}    
display.print(minute);    
display.display(); 
delay(1000);  
//Configura a hour    
display.clearDisplay();    
display.setCursor(0,0);    
display.print("hour: ");    
display.display(); 
Serial.print("\nin between hour:");  
while(hour==0)    
{      
if (Serial.available() > 0)      
{        
hour= Serial.parseInt();      
}    
}    
display.print(hour);    
display.display(); 
delay(1000);     
//Configura o day    
display.clearDisplay();    
display.setCursor(0,0);    
display.print("day: "); 
display.display();    
Serial.print("\nin between day:");    
while(day==0)    
{      
if (Serial.available() > 0)      
{        
day= Serial.parseInt();      
}    
}    
display.print(day);    
display.display(); 
delay(1000);     
//Configura o mês    
display.clearDisplay();    
display.setCursor(0,0);    
display.print("mounth: ");  
display.display();   
Serial.print("\nin between mounth:");   
while(mounth==0)    
{      
if (Serial.available() > 0)      
{        
mounth= Serial.parseInt();      
}    
}    
display.print(mounth);   
display.display(); 
delay(1000);     
//Configura o year    
display.clearDisplay();    
display.setCursor(0,0);    
display.print("year: ");    
display.display(); 
Serial.print("\nin between year:");    
while(year==0)    
{      
if (Serial.available() > 0)      
{        
year= Serial.parseInt();      
}    
}    
display.print(year);    
display.display();    
delay(1000); 
display.clearDisplay();  
}  
void loop()  
{    
if(millis()-UtlTime<0)    
{      
UtlTime=millis();    
}    
else    
{      
second=int((millis()-UtlTime)/1000);    
}    
if(second>59)    
{      
second=0;      
minute++;      
UtlTime=millis();      
if(minute>59)      
{        
hour++;        
minute=0;        
if(hour>23)        
{          
day++;          
hour=0;          
if(mounth==1||mounth==3||mounth==5||mounth==7||mounth==8||mounth==10||mounth==12)          
{            
if(day>31)            
{              
day=1;              
mounth++;              
if(mounth>12)              
{                
year++;                
mounth=1;              
}            
}          
}          
else if(mounth==2)          
{            
if(year%400==0)            
{              
if(day>29)              
{                
day=1;                
mounth++;              
}            
}            
else if((year%4==0)&&(year%100!=0))            
{              
if(day>29)              
{               
day=1;                
mounth++;              
}            
}            
else            
{              
if(day>28)              
{                
day=1;                
mounth++;              
}            
}          
}          
else          
{            
if(day>30)            
{              
day=1;              
mounth++;            
}          
}        
}      
}    
}     
display.clearDisplay();  
delay(1000);  
Serial.print(day);    
Serial.print("/");    
Serial.print(mounth);    
Serial.print("/");    
Serial.print(year);    
Serial.println();       
display.setCursor(0,0);    
display.print("date ");    
display.print(day);    
display.print("/");    
display.print(mounth);    
display.print("/");    
display.print(year); 
display.display(); 
Serial.print(hour);    
Serial.print(":");    
Serial.print(minute);    
Serial.print(":");    
Serial.print(second);    
Serial.print("\n");    
Serial.println();       
display.setCursor(0,10);    
display.print("hour ");    
display.print(hour);    
display.print(":");    
display.print(minute);    
display.print(":");    
display.print(second);  
display.display(); 
char tecla; 
tecla = Serial.read(); 
if(tecla=='1'){ 
digitalWrite(2,LOW); 
} 
if(tecla=='2'){ 
 digitalWrite(2, HIGH); 
} 
} 

Code

codeC/C++
// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial date out (DIN)
// pin 5 - date/Command select (D/C)
// pin 6 - LCD chip select (CS/CE)
// pin 7 - LCD reset (RST)
//Programa : Teste display Nokia 5110 usando biblioteca Adafruit
//Autor : VINICIUS LOPES

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial date out (DIN)
// pin 5 - date/Command select (D/C)
// pin 6 - LCD chip select (CS/CE)
// pin 7 - LCD reset (RST)

Adafruit_PCD8544 display = Adafruit_PCD8544(3,4,5,6,7);

int second,minute, hour, day, mounth,year; 
unsigned long UtlTime; 

void setup() 
pinMode(2,OUTPUT);
UtlTime=0;   {   

minute=0;   
hour=0;   
day=0;   
mounth=0;   
year=0;   
Serial.begin(9600);   
  display.begin();
  display.setContrast(50); // Adjust the display contrast
  display.clearDisplay();   //Apaga o buffer e o display
  display.setTextSize(1);  //Seta o tamanho do texto
  display.setTextColor(BLACK); //Seta a cor do texto      

   
display.print(" date e hour ");   
display.setCursor(0,10);   
display.print(" com Arduino");   
display.display();
delay (5000); 


//Configura o minute   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("minute: ");
display.display();
Serial.print("\nin between minute:");  
while(minute==0)   {     
if (Serial.available() > 0)     
{       
minute= Serial.parseInt();     
}   
}   
display.print(minute);   
display.display();
delay(1000); 

//Configura a hour   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("hour: ");   
display.display();
Serial.print("\nin between hour:"); 
while(hour==0)   
{     
if (Serial.available() > 0)     
{       
hour= Serial.parseInt();     
}   
}   
display.print(hour);   
display.display();
delay(1000);    

//Configura o day   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("day: ");
display.display();   
Serial.print("\nin between day:");   
while(day==0)   
{     
if (Serial.available() > 0)     
{       
day= Serial.parseInt();     
}   
}   
display.print(day);   
display.display();
delay(1000);    

//Configura o mês   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("mounth: "); 
display.display();  
Serial.print("\nin between mounth:");  
while(mounth==0)   
{     
if (Serial.available() > 0)     
{       
mounth= Serial.parseInt();     
}   
}   
display.print(mounth);  
 display.display();
delay(1000);    

//Configura o year   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("year: ");   
display.display();
Serial.print("\nin between year:");   
while(year==0)   
{     
if (Serial.available() > 0)     
{       
year= Serial.parseInt();     
}   
}   
display.print(year);   

display.display();   
delay(1000);
display.clearDisplay(); 

} 

void loop() 
{   

if(millis()-UtlTime<0)   
{     
UtlTime=millis();   
}   
else   
{     
second=int((millis()-UtlTime)/1000);   
}   
if(second>59)   
{     
second=0;     
minute++;     
UtlTime=millis();     
if(minute>59)     
{       
hour++;       
minute=0;       
if(hour>23)       
{         
day++;         
hour=0;         
if(mounth==1||mounth==3||mounth==5||mounth==7||mounth==8||mounth==10||mounth==12)         
{           
if(day>31)           
{             
day=1;             
mounth++;             
if(mounth>12)             
{               
year++;               
mounth=1;             
}           
}         
}         
else if(mounth==2)         
{           
if(year%400==0)           
{             
if(day>29)             
{               
day=1;               
mounth++;             
}           
}           
else if((year%4==0)&&(year%100!=0))           
{             
if(day>29)             
{              
day=1;               
mounth++;             
}           
}           
else           
{             
if(day>28)             
{               
day=1;               
mounth++;             
}           
}         
}         
else         
{           
if(day>30)           
{             
day=1;             
mounth++;           
}         
}       
}     
}   
}    

display.clearDisplay(); 
delay(1000); 
Serial.print(day);   
Serial.print("/");   
Serial.print(mounth);   
Serial.print("/");   
Serial.print(year);   
Serial.println();      

display.setCursor(0,0);   
display.print("date ");   
display.print(day);   
display.print("/");   
display.print(mounth);   
display.print("/");   
display.print(year);

 
display.display();
Serial.print(hour);   
Serial.print(":");   
Serial.print(minute);   
Serial.print(":");   
Serial.print(second);   
Serial.print("\n");   
Serial.println();      

display.setCursor(0,10);   
display.print("hour ");   
display.print(hour);   
display.print(":");   
display.print(minute);   
display.print(":");   
display.print(second); 
display.display();
char tecla;
tecla = Serial.read();
if(tecla=='1'){
digitalWrite(2,LOW);
}
if(tecla=='2'){
  digitalWrite(2, HIGH);
}

}

Schematics

hardware
// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial date out (DIN)
// pin 5 - date/Command select (D/C)
// pin 6 - LCD chip select (CS/CE)
// pin 7 - LCD reset (RST)
Images dxnfxxb1zi

Comments

Similar projects you might like

Weather Clock

Project showcase by Tittiamo

  • 7,666 views
  • 7 comments
  • 22 respects

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 96,159 views
  • 23 comments
  • 80 respects

Alarm Clock

by Tittiamo

  • 46,976 views
  • 59 comments
  • 47 respects

Adjusting Dual Clock using DS3231 on 1.8" ST7735 Display

Project showcase by FLORICA Tudor-Nicusor

  • 3,966 views
  • 2 comments
  • 11 respects

Clock Set Date Time

Project tutorial by Tittiamo

  • 34,226 views
  • 27 comments
  • 43 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 12,678 views
  • 11 comments
  • 50 respects
Add projectSign up / Login