I wanted to make a Valentine's present for my girlfriend by building a days counter since the day we got together. I've been trying to create a days counter that starts counting from a Unix timestamp but with no luck... I'm using an Arduino Leonardo, an RTC DS 3231 and a 7-segment serial display by Microbot for which I think I might not be using the correct library.

But I cannot get the display to print my output. It always prints out 0000. I think I might have messed up with the connections.

I have connected the VCC and GND from the RTC to the 3.3V and GND of the Arduino and the SDA and SCL to the SDA and SCL of the Arduino.

For the display I connected the VCC to the 5V, the GND to the GND and the RX to the digital output 5 (Is this correct?)

Here is the code:

#include <Time.h>
#include <TimeLib.h>
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "RTClib.h"

RTC_DS1307 rtc = RTC_DS1307();

Adafruit_7segment clockDisplay = Adafruit_7segment();

int hours = 0;
int minutes = 0;
int seconds = 0;

unsigned long previousMillis = 0;        // will store last millis event time 
unsigned long sensorpreviousMillis = 0;        // will store last millis event time 
unsigned long fiveMinuteInterval = 300000;           // interval at which to use event time (milliseconds)
unsigned long postDaysInterval = 7200000 ; //seconds in a day 86400000

#define DISPLAY_ADDRESS   0x70

unsigned long theDateWeGotTogether = 1441843200;  //in unixtime
unsigned long days ; 
int weeks ; 

void setup() {                

 bool setClockTime = !rtc.isrunning();
 if (setClockTime) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

void loop() {
//  DateTime now = rtc.now(); 

   days = ((now() - theDateWeGotTogether) / 86400); //86400 is the number of seconds in a day 
  unsigned long currentMillis = millis();
  time_t t = now();

  if(currentMillis - sensorpreviousMillis > fiveMinuteInterval) 
    // save the last time you performed event
    sensorpreviousMillis = currentMillis;   
    DateTime Zeit = rtc.now();

void ShowDaysReading()
  days = ((now() - theDateWeGotTogether) / 86400); //86400 number of seconds in a day
  weeks = ((now() - theDateWeGotTogether) / (86400 * 7) ); //86400 number of seconds in a day


I would be grateful if you could help me!

  • Where are you sending anything to pin 5? – gre_gor Feb 12 '18 at 4:42
  • Nowhere... I just think my libraries are wrong for this display. Do you know what libraries should I use? Thank you for helping me! – Νίκος Τιτομιχελάκης Feb 12 '18 at 5:07
  • 1
    For the moment I would focus on getting the display to work. Try getting it to display 4266 for example. Then work on the clock part. – Nick Gammon Feb 12 '18 at 6:20
  • 2
    With a girlfriend like yours, why wasting time with a clock? – user31481 Feb 12 '18 at 7:44
  • 1
    she said "rock" and he heard "clock" .... for benefit of non english speakers... "rock" is slang for "diamond" – jsotola Feb 12 '18 at 17:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.