viniciuslindoss
Published © GPL3+

Clock with Arduino

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

BeginnerProtip10,009
Clock with Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Adafruit display nokia 5110
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

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)

Code

code

C/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);
}

}

Credits

viniciuslindoss

viniciuslindoss

0 projects • 13 followers

Comments