Clocks
Banana clock
A tiny clock in a banana-shaped case. It sets itself from the internet, shows the date when you press it, and beeps on the hour.
- Medium
- about 45 min
- ESP32-C3
- 8 parts
- 8 wires
- 71 lines of code
- Uses Wi-Fi
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
The whole clock runs on a board the size of a thumbnail. The long thin screen is why the case can be long and thin too.
What you learn
Getting the time with NTP, formatting it, and doing something once when the hour changes.
How it works
input
Button
decides
ESP32-C3 · Wi-Fi
output
OLED 0.91 in
Buzzer
Powered with 5 V through the board's USB-C port.
It joins your home Wi-Fi. You type the network name and password into the sketch before uploading; they stay on the board.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 8 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 8
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
banana-clock.ino
// Banana clock
// A tiny clock that sets itself from the internet. Press the button for the
// date; it beeps on the hour.
#include <WiFi.h>
#include <time.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const long UTC_OFFSET_S = 7 * 3600; // Vietnam: UTC+7
const int PIN_BUTTON_A = 3;
const int PIN_OLED_SDA = 6;
const int PIN_OLED_SCL = 7;
const int PIN_BUZZER_POS = 10;
Adafruit_SSD1306 oled(128, 32, &Wire, -1);
int lastHour = -1;
unsigned long showDateUntil = 0;
void setup() {
pinMode(PIN_BUTTON_A, INPUT_PULLUP);
pinMode(PIN_BUZZER_POS, OUTPUT);
Wire.begin(PIN_OLED_SDA, PIN_OLED_SCL);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(SSD1306_WHITE);
oled.clearDisplay();
oled.setTextSize(2);
oled.setCursor(0, 8);
oled.print("Wi-Fi...");
oled.display();
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long start = millis();
while (WiFi.status() != WL_CONNECTED && millis() - start < 20000) delay(250);
configTime(UTC_OFFSET_S, 0, "pool.ntp.org", "time.google.com");
}
void loop() {
if (digitalRead(PIN_BUTTON_A) == LOW) showDateUntil = millis() + 3000;
struct tm now;
oled.clearDisplay();
if (!getLocalTime(&now, 200)) {
oled.setTextSize(2);
oled.setCursor(0, 8);
oled.print("No time");
} else if (millis() < showDateUntil) {
char text[12];
strftime(text, sizeof(text), "%d/%m/%Y", &now);
oled.setTextSize(2);
oled.setCursor(4, 8);
oled.print(text);
} else {
char text[9];
// the colon blinks once a second
snprintf(text, sizeof(text), now.tm_sec % 2 ? "%02d:%02d" : "%02d %02d", now.tm_hour, now.tm_min);
oled.setTextSize(4);
oled.setCursor(4, 2);
oled.print(text);
if (now.tm_hour != lastHour) {
if (lastHour != -1) tone(PIN_BUZZER_POS, 1320, 150);
lastHour = now.tm_hour;
}
}
oled.display();
delay(100);
}
Libraries
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit SSD1306: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Before uploading, type your Wi-Fi name and password into WIFI_SSID and WIFI_PASS at the top of the sketch.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32C3 Dev Module (USB CDC On Boot: Enabled), then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.