Heart Clock DS1307 RTC

Views: 3993 Difficulty: 3 Status: Pipeline

Connecting the DS1307 real-time clock chip and our Heart Matrix you can show the time with love.

We turn our heart matrix LED display into a clock using an Arduino and the DS1307 real time clock chip. This tutorial will show you how to read the time from the DS1307 into an Arduino and send it out to the heart matrix. Don't worry if you don't have a heart matrix, you could use the code we provide to display the time on any kind of display you choose, or just to trigger other actions in your code. The DS1307 requires an oscillator, a 3.3 volt coin-cell lithium battery, and it communicates with the Arduino over the I2C protocol. The I2C protocol calls for 2.2K Ohm pull-up resistors on the SDA and SCL lines. We provide a schematic and EAGLE board file for an SMD version of this circuit. We use the DS1307 in a ton of projects see them all at the tag page: DS1307 . We also sell clock-shaped a breakout board for the DS1307. Or if you want to build it yourself, Adafruit has a nice through-hole soldering kit for this chip, as well as an awesome tutorial.

Heart Clock, Arduino and DS1307

The heart clock hooked up using the Adafruit breakout board for the DS1307 and an Arduino.

Heart Clock Video

Using the DS1307 breakout board from adafruit we turn the Heart Matrix into a Love Clock! You can too, check out the code below...

Arduino Code for Real time clock DS1307 chip and LED Heart Matrix

This code displays the time on our heart matrix LED Display using the DS1307 chip. Because we are using the RTC chip we can power down without needing to set the time again on startup. (Sorta what we expect from a clock nowadays, but it wasn't always that way!) The heart of the program is this code:
if (millis() - last_update > 1000){
    stime = "";
    cur_time =;
    stime += String(cur_time.hour()%12);
    stime += ":";
    stime += String(cur_time.minute());
    stime += ":";
    stime += String(cur_time.second());
    String ampm = " am  ";
    if (cur_time.hour() > 12) ampm = " pm  ";
    hm.set_message(stime+ampm );
We check if it has been longer than 1 second (= 1000 milliseconds) since the last update. If so, grab the time from the RTC chip and append it all into a big string called stime that we send out to the heart matrix. We do a little modulo 12 trickery so we don't have to see it in military time. (Currently the clock shows 0 instead of 12, can you fix that?!)
stime += String(cur_time.hour()%12);
To talk to the RTC chip we use the adafruit fork of jeelab's awesome library. You will also need the FrequencyTimer2 library and our Heart Matrix arduino library which you can download here, at the original Heart Matrix Tutorial.
/* LucidTronix Heart Matrix
 * LED Display and rtc clock based on ds1307 chip
 * For instructions, details and schematic, See:
 * Uses the RTClib.h library from adafruit
#include <Wire.h>
#include "RTClib.h"
#include <FrequencyTimer2.h>
#include <HeartMatrix.h>

// dataPin is on 5, Latch is on 6, and clock is on 7
HeartMatrix hm = HeartMatrix(5,6,7);
void displayer2(){  

int mode = 0;
int num_modes = 4;
int cur_sec = 0;
int cur_min = 0;
int millisecond_six = 0;
unsigned int last_sec = 0;

unsigned int last_press = 0;


DateTime cur_time, alarm_time;

char* stringy = "nothinghere";
void setup(){

  Wire.begin(); // Start the I2C interface.

  if (! RTC.isrunning()) {
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
   // Set refresh rate (interrupt timeout period)
   // if things break try making this number bigger
    // Set interrupt routine to be called
   hm.set_message("Love you");
String stime = "";
unsigned int last_update = 0;
void loop(){
  if (millis() - last_update > 1000){
    stime = "";
    cur_time =;
    stime += String(cur_time.hour()%12);
    stime += ":";
    stime += String(cur_time.minute());
    stime += ":";
    stime += String(cur_time.second());
    String ampm = " am  ";
    if (cur_time.hour() > 12) ampm = " pm  ";
    hm.set_message(stime+ampm );


Title Description # Cost Link Picture
Heart Matrix Kit The heart matrix kit. Shift register based wearable heart-shaped LED display. 1 $17.95 Link Heart_matrix_baggy
Clock IC RTC DS1307 Serial 512K 8-SOIC I²C, 2-Wire Serial Leap Year, NVSRAM, Square Wave Output Value: 4.5 V ~ 5.5 V 1 $3.53 Link 8-soic_751
Two LED matrices give 70 LEDs to light up a necklace with messages....
Standalone programmable Heart-Shaped LED display....
Wearable digital compass displays the direction in green LEDs....
Rainbow flower necklace using the TLC5940....
Print bitmaps, cellular automata, drawings and text.....
RGB Flashlight, wearable sound art, rainbow lamp....
Light sensors guids this robot towards the light....
This PCB controls a camera and an SD card so you can make automatic time lapse videos. ...