Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsThis builds on the OLED internet clock with an alarm. The ESP32 gets the Indian time from NTP, shows it on the OLED, and compares it with an alarm time you set in the code. At that minute the buzzer beeps. Touching the snooze wire, which uses the ESP32's touch input, silences it for five minutes, and holding it for two seconds turns the alarm off for the day. No buttons are needed.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
A USB charger on the bedside table. Keep the alarm powered; it cannot ring when unplugged.
alarm_clock.inoVerify & upload in Electrolark#include <WiFi.h>
#include <time.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
const char* WIFI_NAME = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";
const int ALARM_HOUR = 6, ALARM_MIN = 30;
const int BUZZ = 25, TOUCH = 4, THRESHOLD = 30;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
bool ringing = false, doneToday = false;
unsigned long snoozeUntil = 0, touchStart = 0;
void setup() {
pinMode(BUZZ, OUTPUT);
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(WHITE);
WiFi.begin(WIFI_NAME, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(300);
configTime(5 * 3600 + 1800, 0, "pool.ntp.org"); // India UTC+5:30
}
void loop() {
struct tm t;
if (!getLocalTime(&t)) return;
bool isAlarmMinute = (t.tm_hour == ALARM_HOUR && t.tm_min == ALARM_MIN);
if (!isAlarmMinute && t.tm_min != ALARM_MIN) doneToday = false;
if (isAlarmMinute && !doneToday && !ringing && millis() > snoozeUntil) ringing = true;
if (millis() > snoozeUntil && snoozeUntil != 0 && !doneToday && !ringing) ringing = true; // snooze ended
bool touched = touchRead(TOUCH) < THRESHOLD;
if (touched && touchStart == 0) touchStart = millis();
if (!touched && touchStart != 0) {
if (ringing && millis() - touchStart < 2000) { ringing = false; snoozeUntil = millis() + 5UL * 60 * 1000; }
touchStart = 0;
}
if (touched && ringing && millis() - touchStart > 2000) { ringing = false; doneToday = true; snoozeUntil = 0; }
digitalWrite(BUZZ, ringing && (millis() / 300) % 2 ? HIGH : LOW); // pulse the buzzer
char hm[8]; strftime(hm, sizeof(hm), "%H:%M", &t);
oled.clearDisplay();
oled.setTextSize(4); oled.setCursor(4, 6); oled.print(hm);
oled.setTextSize(1); oled.setCursor(0, 50); oled.printf("alarm %02d:%02d %s", ALARM_HOUR, ALARM_MIN, ringing ? "RING" : "");
oled.display();
delay(50);
}
Check the time on the OLED and that the alarm time is in 24-hour form. The board must be powered at the alarm time.
Print the touchRead value and set THRESHOLD between the untouched and touched numbers.
Hold the snooze wire for two seconds to turn the alarm off for the day.
No. When power returns it will get the time again, but it cannot ring while off. Add a battery bank for backup.
Yes. Compare the time with an array of alarm times.
Yes. Replace the buzzer pulse with the tone function and a note table.
5 parts: ESP32-WROOM-32 38-Pin Development Board, 0.96" OLED Display 128x64, Buzzer Module 3.3–5V, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (alarm_clock.ino).
About ₹622 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Comparing the current time with an alarm time; Using touch input as a snooze; Beeping a buzzer without blocking the clock.
Ideas that reuse this build: ESP32 OLED internet clock. They are listed under Take it further on this page.
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Press to roll: the pips tumble and slow down before landing on a number.
Wait for the light, hit the button: how many milliseconds can you beat?
A bright 4-digit clock that keeps time through power cuts.
Learning project. Check every circuit and the datasheet of each part before you power it up.