Simple Arduino clock using TM1637 indicator and DS3231 timer

 This project shows how to assemble a digital clock using a 4-digit 7-segment display TM1637 and a DS3231 timer with Arduino. This display is great for displaying the time.


Simple Arduino clock using TM1637 indicator and DS3231 timer

The TM1637 module is a dedicated LED driver circuit (LED display) with a keyboard scan interface that is internally integrated with the microcontroller digital interface and LED driver circuit. This module is powered from 3.3 - 5.5 V and consumes a current of about 80 mA.


TM1637

The DS3231 is a low cost, highly accurate real time clock (RTC) with I2C interface with TCXO and built-in temperature compensation crystal. The device has an input for battery voltage, which counts down the time when the device is powered off. The presence of a resonator increases the long-term accuracy of the device and reduces the number of components on the production line. The DS3231 is sold in a 16-pin SO package and is available in commercial or industrial temperature ranges.


DS3231

The diagram for connecting the Arduino to the TM1637 and DS3231 to implement the clock is shown in the following figure.


Arduino wiring diagram to TM1637 and DS3231

The program code is quite simple and is presented below. Do not forget to only include the RTClib and TM1637 libraries.



#include "RTClib.h"
#include <TM1637Display.h>

#define CLK 8
#define DIO 9

RTC_DS3231 rtc;
TM1637Display display = TM1637Display(CLK, DIO);

void setup() {
  Serial.begin(9600);
  delay(3000);

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  display.setBrightness(5);
  display.clear();
}

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

  int displaytime = (now.hour() * 100) + now.minute();

  Serial.println(displaytime);

  display.showNumberDecEx(displaytime, 0b11100000, true);

  delay(1000);

  display.showNumberDec(displaytime, true);

  delay(1000);
}
Previous Post Next Post

Contact Form