A smart desk companion built on ESP32 — adaptive lighting, alarms, a Pomodoro timer, a countdown timer, and a stopwatch, all on a single OLED display with 4-button navigation.
FocusDesk is a firmware project for an ESP32-based desk lamp/productivity device. It syncs real time over WiFi (NTP), adapts warm/cool LED lighting throughout the day, wakes you up with a sunrise-style alarm ramp, and helps you stay focused with built-in Pomodoro and timer tools — all driven by a compact SSD1306 OLED UI and four physical buttons.
- Dual-channel adaptive lighting — independently mixes warm and cool LED channels based on a brightness + color-temperature model, with an automatic time-of-day lighting schedule (
autoMode) or full manual control. - Sunrise alarm — 20 minutes before your alarm time, the warm LED channel ramps up gradually to simulate a natural sunrise wake-up.
- NTP-synced clock — connects to WiFi on boot and syncs real time from
pool.ntp.org, with graceful fallback (--:--) if WiFi/NTP is unavailable. - Pomodoro timer — configurable duration (in 60s/1min increments), pause/resume, and a live-animated "growing tree" progress visual on the OLED.
- Countdown timer — set custom minute/second durations, pause/resume/reset.
- Stopwatch — start/pause/reset with centisecond precision.
- Alarm clock — set hour/minute, enable/disable, with a repeating buzzer alert.
- System info screen — firmware version, uptime, alarm status, Pomodoro duration, and NTP sync status at a glance.
- Single-buzzer audio feedback — button clicks, alarm/timer ringing patterns, and boot chime, all through one PWM-driven piezo buzzer.
- 4-button menu navigation — Menu / Select / Up / Down drive a simple stateful UI across 7 screens (Home, Alarm, Pomodoro, Timer, Stopwatch, Lighting Hub, System).
| Component | Notes |
|---|---|
| ESP32 dev board | Core microcontroller, WiFi-capable |
| SSD1306 OLED display (128×64, I²C) | Wired to SDA=21, SCL=22 |
| 2× LED channel (warm white + cool white) | PWM-driven via ledc, pins 16 and 18 |
| Piezo buzzer | PWM tone driven, pin 14 |
| 4× push buttons | Menu, Select, Up, Down — pins 32, 33, 25, 26 (active-low, internal pull-ups) |
Note: LED and buzzer pins are ESP32 GPIOs used with
ledcAttach/ledcWrite, so any ESP32 board withledcPWM support should work with minor pin remapping.
Adafruit_GFXAdafruit_SSD1306Wire.h(I²C)WiFi.h(ESP32 core)time.h(NTP /configTime)
flowchart TB
subgraph Inputs
BTN[4x Push Buttons<br/>Menu / Select / Up / Down]
WIFI[WiFi + NTP Server]
end
subgraph ESP32["ESP32 Firmware"]
LOOP[Main Loop]
BTNH[handleButtons]
ALARM[checkAlarm]
TASKS[updateTasks<br/>Pomodoro / Timer / Stopwatch]
AUTO[Auto Lighting Schedule]
RAMP[Sunrise Ramp Logic]
DRAW[Screen Draw Functions]
end
subgraph Outputs
OLED[SSD1306 OLED 128x64]
LEDW[Warm LED - PWM]
LEDC[Cool LED - PWM]
BUZZ[Piezo Buzzer - PWM Tone]
end
BTN --> BTNH
WIFI --> ALARM
LOOP --> BTNH
LOOP --> ALARM
LOOP --> TASKS
LOOP --> AUTO
LOOP --> RAMP
LOOP --> DRAW
BTNH --> DRAW
ALARM --> BUZZ
TASKS --> BUZZ
AUTO --> LEDW
AUTO --> LEDC
RAMP --> LEDW
DRAW --> OLED
BTNH -.beep.-> BUZZ
stateDiagram-v2
[*] --> Home
Home --> Alarm: MENU
Alarm --> Pomodoro: MENU
Pomodoro --> Timer: MENU
Timer --> Stopwatch: MENU
Stopwatch --> Lighting: MENU
Lighting --> System: MENU
System --> Home: MENU
state "Screen (view mode)" as View
state "Screen (settings mode)" as Settings
View --> Settings: SELECT (screenState > 0)
Settings --> View: MENU
Settings --> Settings: UP/DOWN adjusts value<br/>SELECT steps field
note right of Home
Home screen has no settings page
MENU always cycles forward
end note
flowchart LR
A[Loop tick] --> B{Alarm enabled<br/>and time synced?}
B -- No --> Z[Skip]
B -- Yes --> C{20 min or less<br/>until alarm?}
C -- No --> Z
C -- Yes --> D[Map remaining minutes<br/>to brightness 0-255]
D --> E[Ramp Warm LED up<br/>Cool LED off]
E --> F{Time == Alarm time?}
F -- Yes --> G[alarmRinging = true]
G --> H[Buzzer pulses at 1200Hz<br/>every 300ms]
H --> I{Any button pressed<br/>or 60s elapsed?}
I -- Yes --> J[Silence alarm]
F -- No --> Z
flowchart TD
S[Idle / Configured] -->|SELECT| R[Running]
R -->|SELECT pause| S
R -->|Time reaches 0| DONE[Ringing]
DONE -->|Any button pressed| S
DONE -->|60s timeout| S
S -->|UP/DOWN adjust duration| S
style R fill:#e0f7e9,stroke:#2e7d32
style DONE fill:#fde0e0,stroke:#c62828
- Install the ESP32 board package in the Arduino IDE (or PlatformIO).
- Install the
Adafruit_GFXandAdafruit_SSD1306libraries via the Library Manager. - Open the sketch and update your WiFi credentials:
#define WIFI_SSID "YOUR_SSID" #define WIFI_PASSWORD "YOUR_PASSWORD"
- Adjust
GMT_OFFSET_SECif you're outside IST (default is UTC+5:30). - Wire up the OLED, LEDs, buzzer, and buttons per the pin table above.
- Flash to your ESP32 and open the Serial Monitor (115200 baud) to confirm boot and WiFi/NTP status.
- Menu button — cycle through screens (Home → Alarm → Pomodoro → Timer → Stopwatch → Lighting → System), or back out of a settings sub-page.
- Select button — enter a screen's settings page, and step through/confirm fields (e.g. start/pause Pomodoro, confirm timer duration, toggle lamp).
- Up / Down buttons — adjust the selected value (brightness, alarm time, timer duration, etc.).
- Any button press silences an active alarm, Pomodoro, or timer alert.
While the current firmware drives everything locally through the OLED and physical buttons, the project was also designed with Blynk IoT in mind as a fallback / remote-control layer. In scenarios where local button access isn't convenient — or for remote monitoring and control of the lamp, alarm, and timers from a phone — Blynk IoT provides a ready-made mobile dashboard and cloud bridge for the ESP32, without requiring a custom backend or app to be built from scratch.
This makes FocusDesk extensible toward a full IoT setup: the on-device UI remains the primary, offline-first interface, while Blynk can be layered on top for remote access when WiFi/cloud connectivity is available.
Single-file Arduino sketch (.ino) organized into clearly separated sections:
- Pin & constant definitions
- Global state (lighting, alarm, Pomodoro, timer, stopwatch)
- Buzzer helpers
- Lamp output (PWM mixing)
- Time helpers (NTP-backed)
setup()— display init, WiFi/NTP connect, peripheral init- Alarm-check logic
- Button handling (menu state machine)
- Background task updates (Pomodoro/timer/stopwatch ticking, ring management)
- Per-screen draw functions
loop()— orchestrates everything each frame
- Persist settings (alarm time, brightness, Pomodoro duration) to non-volatile storage (
Preferences/EEPROM) so they survive reboots. - Debounce buttons in hardware or software beyond the current
delay()-based approach. - Full Blynk IoT integration for remote scheduling and live sensor/state sync.
- Ambient light sensor input to refine
autoModebeyond a fixed time-of-day table.
This project is open for personal, academic, and portfolio use. Add a license of your choice (MIT recommended) before publishing publicly.