Creating a Days Counter with Arduino Leonardo and an RTC 3231

Hello, I’ve been trying to create a days counter that starts counting from a unix timestamp. I’m using an arduino Leonardo, an RTC DS 3231 and a 7-segment serial display(microbot).

But I cannot get the display to print ny output. 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 =; 
   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 =;

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


Thanks everyone in advance!


I had the prototype code that said he connected the 7-segment screen to digital port No.5. Can you explain what part of the code is wrong and what sgould I use to properly program the 7-segment display? Thank you for your time. (I'm new to all this and I really want to built this project)


Yes sorry! This is the display I have:

Microbot 7-segment Serial Display