An accurate clock that keeps time even when the power is off.
Built and tested by Anju.A · Industrial Robotics Institute
Arduino IDE, RTClib library, Adafruit GFX library, Adafruit SSD1306 library
A digital clock that shows the time and date on a 0.96" OLED. A DS3231 Real-Time Clock module keeps accurate time with its own backup battery, so the clock is still correct after a power cut. The Arduino reads the RTC over I2C and updates the display every second.
| Component | Qty |
|---|---|
| Arduino Uno | 1 |
| RTC Module (DS3231 / DS1307) | 1 |
| OLED Display (SSD1306, 0.96", I2C) | 1 |
| RTC Backup Battery (CR2032) | 1 |
| Breadboard | 1 |
| Jumper Wires | As needed |
| USB Cable | 1 |
| From | Connect to |
|---|---|
| RTC VCC | 5V |
| RTC GND | GND |
| RTC SDA | A4 |
| RTC SCL | A5 |
| OLED VCC | 5V |
| OLED GND | GND |
| OLED SDA | A4 (shared) |
| OLED SCL | A5 (shared) |
Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the Arduino Uno.
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
RTC_DS3231 rtc;
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void print2(int v) { // show leading zero, e.g. 09
if (v < 10) display.print('0');
display.print(v);
}
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("RTC not found!");
while (1);
}
// Set time only once, then comment this line and upload again
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED not found!");
while (1);
}
display.clearDisplay();
}
void loop() {
DateTime now = rtc.now();
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
print2(now.hour()); display.print(":");
print2(now.minute()); display.print(":");
print2(now.second());
display.setTextSize(1);
display.setCursor(20, 40);
print2(now.day()); display.print("/");
print2(now.month()); display.print("/");
display.print(now.year());
display.display();
delay(1000);
}A digital clock that shows the time and date on a 0.96" OLED. A DS3231 Real-Time Clock module keeps accurate time with its own backup battery, so the clock is still correct after a power cut.
You need: Arduino Uno (1), RTC Module (DS3231 / DS1307) (1), OLED Display (SSD1306, 0.96", I2C) (1), RTC Backup Battery (CR2032) (1), Breadboard (1), Jumper Wires, USB Cable (1). Software: Arduino IDE, RTClib library, Adafruit GFX library, Adafruit SSD1306 library.
Yes. It is rated beginner and takes about 1–2 hours to build, using the Arduino Uno. The guide on this page explains every connection and step.
The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.
Yes. IRI sells a kit with the parts for this project (PRJ-141). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.