กลับไปหน้ารวมไฟล์
clock-with-sh1106-oled-display-ds1302-rtc-module-d3e7e8-en.md

Sorryforthequalityofmyphotos,Ijustdoitbadly. :)

What did I use to make the project?

  • Arduino UNO board clone (you can use the original one, I'mtoopoor).
  • DS1302 RTC clock module (Waveshare 9709)
  • A button (it can be any button bro)
  • 1, 3" OLED screen (SH1106 driver)
  • 830-pin breadboard
  • Connection cables

How did I put it together?

Step zero:

Yes.

Put some good music on.

Step one:

I used a bent paperclip to hold an Arduino.

Put an Arduino somewhere close to the project to attach cables.

Really,puttingitinanotherroomisnotagoodidea.

Step two:

Yes.

Put a button on a board like that.

Step three:

Clok

Skreen

Install the OLED and the RTC.

Step four:

All devices put together.

Connect it, more or less like that. Here is the pinout:

OLED:

GND - Arduino GND

VCC - Arduino 5V

SCL - Arduino Analog Connector 5 (A5)

SDA - Arduino Analog Connector 4 (A4)

Button:

Left - Arduino GND

Right - Arduino Digital Connector 5 (5 or D5)

RTC:

VCC - Arduino 5V

GND - Arduino GND

I/O - Arduino Digital Connector 4 (4 or D4)

SCLK - Arduino Digital Connector 3 (3 or D3)

CE - Arduino Digital Connector 2 (2 or D2)

Step five:

Install necessary libraries:

Wire.h (should be installed/found in arduino library manager)

https://github.com/chrisfryer78/ArduinoRTClibrary

Adafruit GFX (should be found in arduino library manager)

https://github.com/wonho-maker/Adafruit_SH1106

Step six:

Write a script.

My example:

// include necessary libraries.
#include
#include
#include
#include
// configure clock - virtuabotixRTC clock(SCLK_PIN, I/O_PIN, CE_PIN)
virtuabotixRTC clock(3, 4, 2);
// Configure display
Adafruit_SH1106 display(-1);
int state = 1;
void setup() {
pinMode(5, INPUT_PULLUP);
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);
drawUI();
display.display();
}
void loop() {
// clock sleep/turn off mode
if (digitalRead(5) == LOW) {
if (state == 0) {
delay(500);
drawUI();
state = 1;
}else{
delay(500);
display.drawRect(4, 7, 120, 50, WHITE);
display.fillRect(5, 8, 118, 48, BLACK);
display.setTextSize(1);
display.setCursor(6, 12);
display.println("Clock will turn");
display.println(" off in a moment.");
display.println("");
display.println(" To turn back on,");
display.println(" press the button.");
display.display();
delay(3000);
display.clearDisplay();
display.display();
state = 0;
}
}
if (state == 1) {
// Update time every second
clock.updateTime();
drawUI();
display.setTextColor(WHITE);
display.setTextSize(3);
display.setCursor(1, 19);
if (clock.hours < 10) {
display.print("0");
}
display.print(clock.hours);
display.print(":");
if (clock.minutes < 10) {
display.print("0");
}
display.print(clock.minutes);
display.setTextSize(2);
display.print(":");
if (clock.seconds < 10) {
display.print("0");
}
display.print(clock.seconds);
display.setTextSize(1);
display.setCursor(26, 48);
if (clock.dayofweek == 1) {
display.print("Monday,");
}
if (clock.dayofweek == 2) {
display.print("Tuesday,");
}
if (clock.dayofweek == 3) {
display.print("Wednesday,");
}
if (clock.dayofweek == 4) {
display.print("Thursday,");
}
if (clock.dayofweek == 5) {
display.print("Friday,");
}
if (clock.dayofweek == 6) {
display.print("Saturday,");
}
if (clock.dayofweek == 7) {
display.print("Sunday,");
}
display.setCursor(26, 56);
if (clock.dayofmonth < 10) {
display.print("0");
}
display.print(clock.dayofmonth);
display.print(".");
if (clock.month < 10) {
display.print("0");
}
display.print(clock.month);
display.print(".");
display.print(clock.year);
display.display();
delay(999);
}
}
void drawUI() {
// draw the GUI
display.clearDisplay();
display.setTextSize(1);
display.setCursor(2, 2);
display.println(" Adam's Clock Sleep");
display.drawLine(0, 11, 128, 11, WHITE);
display.drawLine(94, 0, 94, 10, WHITE);
display.drawLine(26, 44, 102, 44, WHITE);
}

Step seven:

Install the program to your Arduino and have fun!

EXPANDED TECHNICAL DETAILS

High-Contrast Micro-Horological Hub

This project combines the ultra-sharp SH1106 1.3" OLED with a DS1302 RTC to create a sleek and modern desk clock with graphical capabilities.

  • Graphical Frame-Buffer Orchestration: The Arduino manages the SH1106 display using the U8g2 library. This allows for rendering not just numbers, but beautiful analog clock faces and smooth graphical animations.
  • Battery-Backed Temporal Memory: The DS1302 module includes a coin-cell battery; the Arduino (management core) reads the correct time upon startup even if the main power was disconnected for months.

Aesthetics

  • Animated "Transition" Effects: Includes software routines for "Fading" or "Scrolling" between the Time, Date, and Temperature views, providing a premium, high-fidelity user experience.

ข้อมูล Frontmatter ดั้งเดิม

title: "Clock with SH1106 OLED display & DS1302 RTC module"
description: "A short, simple project about a clock made with an Organic LED display and DS1302 RTC clock module, for ex. to use in full-screen game..."
author: "lucasio99"
category: ""
tags:
  - "clocks"
views: 4376
likes: 0
price: 1120
difficulty: "Easy"
components:
  - "1x JustPi - Connection cables 65x"
  - "1x Breadboard (generic)"
  - "1x Arduino UNO"
  - "1x Tact Switch 6x6mm/4,3mm DIP 5x"
  - "1x Waveshare 9709 - DS1302 RTC clock"
  - "1x 128x64 OLED I2C display"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles:
  - "https://projects.arduinocontent.cc/d189dc3f-da6d-4035-b042-1ceb2c5258bc.ino"
  - "https://projects.arduinocontent.cc/d189dc3f-da6d-4035-b042-1ceb2c5258bc.ino"
  - "https://projects.arduinocontent.cc/2ba00518-6aac-4ce8-a251-b57c22a3d768.ino"
documentationLinks: []
passwordHash: "08292bd266848dce0c6a22d4a8c2cfefd0b0efdb68f205d497c53c755538c249"
encryptedPayload: "U2FsdGVkX1+a+WxngtphGWfxsdDnjD+beTgYZ0j1fniaHy5Yq7dvTdnaVcFhS/lnrn3AZ6ifsV4KfCLrHdqdEo8diPniTCrJHH2vfR/2VTk="
seoDescription: "DIY Clock project using SH1106 OLED display and DS1302 RTC module. Perfect for full-screen game applications."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/clock-with-sh1106-oled-display-ds1302-rtc-module-d3e7e8_cover.jpg"
lang: "en"