
Desk clock with alarm and temperature
Build a desk clock with Arduino
An Arduino Nano clock with a precise DS3231 real-time clock, a crisp OLED face, room temperature from a DHT22 and a morning alarm. It keeps time even when unplugged, thanks to a coin cell.
Every required part
Rs 3,154
Parts list
13 items
- Every required part in stock
- Wiring and code included
- Cash on delivery
From our reel · 17 Jan 2027Parts list
Everything you need for the desk clock with alarm and temperature
Required parts are ticked. Untick anything you already have; the total updates as you go.
Main parts
- Rs 660RequiredArduino Nano V3
Its pins may need soldering; pick the pre-soldered one if you cannot solder.
1Rs 660 each - Rs 550RequiredDS3231 i2C Precision Clock RTC with AT24C32 Memory
Temperature-compensated: drifts only about a minute a year.
1Rs 550 each - Rs 35RequiredCR2032 3V Coin Cell Battery
Keeps the time while the clock is unplugged. Skip if your DS3231 arrives with one fitted.
1Rs 35 each
Wiring & mounting
- Rs 199RequiredArduino Nano USB Programming Cable
Uploads the code, then powers the clock from a phone charger.
1Rs 199 each - Rs 150Required10cm Pin To Pin Jumper Wire Dupont Line 40 Pin Male To Male Arduino Jumper Wires1Rs 150 each
- Rs 150Required10cm Pin To Hole Jumper Wire Dupont Line 40 Pin Male To Female Arduino Jumper Wires
For the DS3231 and OLED pins.
1Rs 150 each - Rs 110Optional115mm x 90mm x 53mm ABS Electronics Enclosures Box Project Box
Cut a window for the screen and holes for the buttons.
1Rs 110 each
You also need (most homes have these)
- Phone charger (USB, 5 V)Powers the clock.
12 items
Rs 3,154
From our reel
Watch it come together in 12 steps
How it works
What each part does
The DS3231 is a dedicated clock chip with its own temperature-compensated crystal, far more accurate than the Arduino's own timer. Its coin cell keeps it ticking when the power is off.
Every loop, the Nano asks the DS3231 for the time over I2C, reads the DHT22, and draws the time, temperature and alarm status on the OLED. The OLED shares the same two I2C wires.
When the clock reaches the alarm time, the buzzer beeps for 30 seconds; the alarm button turns it on or off.
Wiring
Connect it pin by pin
| From | To | Note |
|---|---|---|
| DS3231 VCC | → Nano 3V33.3 V stops the module charging the CR2032 | |
| DS3231 GND | → Nano GND | |
| DS3231 SDA / SCL | → Nano A4 / A5 | |
| OLED VCC / GND | → Nano 5V / GND | |
| OLED SDA / SCL | → Nano A4 / A5Shared with the DS3231 | |
| DHT22 pin 1 / pin 4 | → Nano 5V / GND | |
| DHT22 pin 2 (DATA) | → Nano D510 kΩ from DATA to 5V | |
| Buzzer + | → Nano D8 | |
| Buttons (hour, minute, alarm) | → Nano D2, D3, D4Other leg of each button to GND |
The code
Ready-to-upload Arduino code
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
RTC_DS3231 rtc;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
DHT dht(5, DHT22);
const int BTN_HOUR = 2, BTN_MIN = 3, BTN_ALARM = 4, BUZZER = 8;
const int ALARM_H = 6, ALARM_M = 30; // alarm time, 24-hour clock
bool alarmOn = true;
bool pressed(int pin) {
if (digitalRead(pin) == LOW) {
delay(30); // debounce
while (digitalRead(pin) == LOW) delay(10);
return true;
}
return false;
}
void setup() {
pinMode(BTN_HOUR, INPUT_PULLUP);
pinMode(BTN_MIN, INPUT_PULLUP);
pinMode(BTN_ALARM, INPUT_PULLUP);
pinMode(BUZZER, OUTPUT);
rtc.begin();
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // time from your computer
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
dht.begin();
}
void loop() {
DateTime now = rtc.now();
if (pressed(BTN_HOUR)) rtc.adjust(now + TimeSpan(0, 1, 0, 0));
if (pressed(BTN_MIN)) rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), (now.minute() + 1) % 60, 0));
if (pressed(BTN_ALARM)) alarmOn = !alarmOn;
now = rtc.now();
bool ringing = alarmOn && now.hour() == ALARM_H && now.minute() == ALARM_M && now.second() < 30;
digitalWrite(BUZZER, ringing && (millis() / 250) % 2);
char line[16];
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(3);
oled.setCursor(19, 8);
snprintf(line, sizeof line, "%02d:%02d", now.hour(), now.minute());
oled.print(line);
oled.setTextSize(1);
oled.setCursor(0, 50);
float t = dht.readTemperature();
if (!isnan(t)) {
oled.print(t, 1);
oled.print(" C ");
}
if (alarmOn) {
snprintf(line, sizeof line, "Alarm %02d:%02d", ALARM_H, ALARM_M);
oled.print(line);
} else {
oled.print("Alarm off");
}
oled.display();
delay(100);
}Step by step
Build it
- 1
Build it on the breadboard
Put the Nano across the centre gap, then the three buttons and the buzzer. Connect the DS3231 and OLED with jumpers to A4 (SDA) and A5 (SCL).
- 2
Fit the coin cell
Put the CR2032 in the DS3231's holder, flat side up. Power the DS3231 from 3V3, not 5V.
- 3
Install the libraries and upload
Install the five libraries from the Library Manager and upload. On first start the clock takes the time from your computer.
- 4
Set your alarm
Change ALARM_H and ALARM_M to your wake-up time (24-hour) and upload again. Use the hour and minute buttons to fine-tune the clock any time.
- 5
Put it in a case
Cut a window for the OLED and holes for the buttons in the box, and run it from a phone charger.
Tips & troubleshooting
- A blank OLED usually means a wrong address: most are 0x3C, a few are 0x3D.
- If the time resets to the upload time after unplugging, the coin cell is flat or missing.
- The temperature reads a little high if the DHT22 sits right next to the Nano: give it a few centimetres of space.
Stuck on wiring or code?
Send us a photo of your build on WhatsApp. We are makers too, and we will help you get it working.
FAQ
Questions people ask
Why power the DS3231 from 3.3 V?+
Many DS3231 boards have a small charging circuit meant for rechargeable LIR2032 cells. At 3.3 V it cannot push current into an ordinary CR2032, so the coin cell stays safe.
Can it show the date too?+
Yes: now.day(), now.month() and now.year() are ready to print on the bottom line.
Can I use a bigger display?+
A 1.3" OLED works with small code changes (it often uses the SH1106 driver), or a 16×2 LCD for a retro look.
Read next
- Arduino Kya Hai? Arduino Meaning in Urdu, Kaunsa Board Lein aur Pehla ProjectArduino kya hai, is se kya ban sakta hai, Uno, Nano ya Mega mein se kaunsa lein, shuru ke parts aur pehla LED blink project: aasaan Roman Urdu mein, Pakistan ki live qeematon ke sath.
- Breadboard Price in Pakistan: Which Size to Buy and How It WorksBreadboard prices in Pakistan for every size, from the 170-point mini to 830 and 1660-point boards, which one fits your project, how the holes are connected inside, and the mistakes behind loose connections.
More projects to build
All projects































