Clocks are a rite of passage for hardware hackers, and with this video you can start working on your DIY Clock merit badge using the Arduino platform to build a basic Arduino clock. This project builds on the Arduino Fortune Teller project and teaches programming concepts like timing and actively updating a display, so you can use it as a springboard for many more complicated projects!
PARTS/TOOLS:
https://www.newark.com/arduino/a000066/dev-board-atmega328-arduino-uno/dp/78T1601
https://www.newark.com/mikroelektronika/mikroe-55/display-board-lcd-2x16/dp/61W9875
https://www.newark.com/mcm/21-18938/breadboard-with-binding-posts630/dp/79X3923
https://www.newark.com/multicomp-pro/mccfr0w4j0221a50/carbon-film-resistor-220-ohm-250mw/dp/58K5029
https://www.newark.com/multicomp-pro/mccfr0w4j0103a50/carbon-film-resistor-10kohm-250mw/dp/58K5002
https://www.newark.com/adafruit/759/wire-gauge-28awg/dp/88W2571
https://www.newark.com/bourns/pdb181-k420k-103b/rotary-potentiometer-10kohm-17mm/dp/04B9684
THE CIRCUIT:
THE SKETCH:
//Projet ColorTyme
//Phase 1: Simple LCD Clock
//CC-BY-SA Matthew Eargle
//AirborneSurfer.com
//element14 Presents
#include "LiquidCrystal.h"
// Define LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// initial Time display is 00:00:00 (24hr clock)
int h=00;
int m=00;
int s=00;
// Time Set Buttons
int button1;
int button2;
int hs=8;// pin 8 for Hours Setting
int ms=9;// pin 9 for Minutes Setting
// Digital LCD Constrast setting
int cs=6;// pin 5 for contrast PWM
static int contrast=100;// default contrast
//Define current time as zero
static uint32_t last_time, now = 0;
void setup()
{
lcd.begin(16,2);
pinMode(hs,INPUT_PULLUP);
pinMode(ms,INPUT_PULLUP);
now=millis(); // read RTC initial value
analogWrite(cs,contrast);
}
void loop()
{
// Update LCD Display
// Print TIME in Hour, Min, Sec
lcd.setCursor(0,0);
lcd.print("Time ");
if(h<10)lcd.print("0");// always 2 digits
lcd.print(h);
lcd.print(":");
if(m<10)lcd.print("0");
lcd.print(m);
lcd.print(":");
if(s<10)lcd.print("0");
lcd.print(s);
lcd.setCursor(0,1);// for Line 2
lcd.print("SURF STD TIME");
while ((now-last_time) < 1000 ) // wait1000ms
{
now=millis();
}
last_time=now; // prepare for next loop
s=s+1; //increment sec. counting
/*-------Time setting-------*/
button1=digitalRead(hs);
if(button1==0)
{
s=0;
h=h+1;
}
button2=digitalRead(ms);
if(button2==0){
s=0;
m=m+1;
}
analogWrite(cs,contrast); // update contrast
/* ---- manage seconds, minutes, hours am/pm overflow ----*/
if(s==60){
s=0;
m=m+1;
}
if(m==60)
{
m=0;
h=h+1;
}
if (h==25)
{
h=0;
}
}



Top Comments