Home Time Related Projects Arduino clock

Arduino clock

by shedboy71

Arduino Clock

In this example we will create a simple clock example using a DS1307 breakout, a keypad/LCD shield and an Arduino Uno

The DS1307 real-time clock is a low-power, full binary-coded decimal clock/calendar. Address and data are transferred over the I²C bus.The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply, this backup supply is usually in the form of a lithium ion battery.

Here is a picture of my setup, as you can see the DS1307 breakout is connected to the LCD and keypad shield, in this example you can see the time displayed on the LCD.

arduino clock arduino clock

Layout

Here is how you wire up the DS1307 to your Arduino

VCC and GND connect to 5v and GND
SCL connects to A5
SDA connects to A4

Lets look at a schematic and layout

arduino-and-ds1307_schem keypad-ds1307_bb

Code

You will need to download and copy the RTCLib into your ARduino libraries folder

https://github.com/getmicros/Arduino-Libraries/blob/master/RTClib-master.zip

 

[codesyntax lang=”cpp”]

#include <Wire.h>
#include “RTClib.h”
#include <LiquidCrystal.h>

RTC_DS1307 rtc;
// Connections: Sainsmart LCD/Keypad shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{
//Serial.begin(9600);
Wire.begin();
rtc.begin();

//setup the LCD
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(“Time”);
//debug the rtc
if (! rtc.isrunning())
{
//Serial.println(“RTC is NOT running!”);
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(__DATE__, __TIME__));
}
}

void loop()
{
DateTime now = rtc.now();
lcd.setCursor(0,1);
lcd.print(now.hour(), DEC);
lcd.setCursor(2,1);
lcd.print(“:”);
lcd.setCursor(3,1);
lcd.print(now.minute(), DEC);
lcd.setCursor(5,1);
lcd.print(“:”);
lcd.setCursor(6,1);
lcd.print(now.second(), DEC);
delay(1000);
}

[/codesyntax]

 

 

Links

LCD and Keypad Shield on Amazon US
ds1307 breakout on Amazon US
LCD and keypad shield on Amazon UK
ds1307 breakout on Amazon UK

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More