Build it step by step
0 of 7 doneTest the LEDs
Light both warm white at low level.
Test the motor
Buzz softly from code.
Add the clock
Print the time to serial.
Add the fade
Grow the light over 20 minutes.
Add the pulses
Buzz three times at the alarm.
Add the battery
Charge and run from the cell.
Sew the mask
Make pockets and a soft cover for each part.
How do you build a sleep mask with wake light?
A mask with soft LEDs wakes you with gradual light and a gentle buzz. You need Seeed XIAO ESP32C3, WS2812B single LED module (8 mm / breakout) × 2, Vibration motor (coin type), DS3231 RTC module, Li-Po battery 3.7 V 500 mAh, BC547 NPN transistor, Resistor 1 kΩ and Signal Diode 1N4148. It takes 7 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 8
Wiring
| From | To | Why |
|---|---|---|
| RTC VCC and GND | XIAO 3V3 and GND | Power |
| RTC SDA and SCL | XIAO D4 and D5 | I2C |
| LED 1 DIN | XIAO D1 | Data |
| LED 1 DOUT | LED 2 DIN | Chain |
| LED modules VCC and GND | XIAO 3V3 and GND | Power |
| XIAO D2 | 1 kΩ to BC547 base | Motor switch |
| BC547 collector | Motor minus | Switched return |
| BC547 emitter | XIAO GND | Ground |
| Motor plus | XIAO 3V3 | Supply |
| 1N4148 | Across the motor, stripe to 3V3 | Flyback protection |
| LiPo | XIAO BAT+ and BAT− pads | Power and charging |
Code
The light starts 20 minutes before your wake time and grows slowly through warm colours, then a few soft pulses of the coin motor wake you. The motor runs at about a third of its power through a transistor, with a diode across it to absorb the spike. Fit the mask comfortably with a thin foam spacer so that no board presses on the face, and cover all electronics with soft fabric. A lithium cell sits near the face, so use a protected LiPo, secure it in a sewn pocket, never wear or sleep with it while it is charging, and stop using it if it swells or warms. This is a comfort gadget, not a medical device, and it is not a substitute for advice about sleep problems. Set the time in the sketch; the clock keeps time through a coin cell on the RTC. Arduino IDE with the ESP32 boards package, board "XIAO_ESP32C3".
Runs on a virtual Seeed XIAO ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Sleep mask with wake light. Libraries: RTClib, Adafruit NeoPixel. Board: XIAO ESP32C3.
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_NeoPixel.h>
RTC_DS3231 rtc;
Adafruit_NeoPixel leds(2, D1, NEO_GRB + NEO_KHZ800);
const int MOTOR = D2;
const int ALARM_HOUR = 6, ALARM_MIN = 30; // set your wake time
const int FADE_MINUTES = 20; // light grows for 20 minutes before the alarm
bool buzzed = false;
void setup() {
pinMode(MOTOR, OUTPUT); digitalWrite(MOTOR, LOW);
Wire.begin(D4, D5);
rtc.begin();
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
leds.begin(); leds.clear(); leds.show();
}
void loop() {
DateTime now = rtc.now();
int nowMin = now.hour() * 60 + now.minute();
int alarmMin = ALARM_HOUR * 60 + ALARM_MIN;
int into = nowMin - (alarmMin - FADE_MINUTES); // minutes since the fade began
if (into >= 0 && into < FADE_MINUTES) { // fade up warm light
float level = (float)into / FADE_MINUTES;
byte v = (byte)(level * level * 120);
for (int i = 0; i < 2; i++) leds.setPixelColor(i, leds.Color(v, v * 0.4, v * 0.1));
leds.show(); buzzed = false;
} else if (nowMin >= alarmMin && nowMin < alarmMin + 5) { // at the alarm, steady light and soft pulses
for (int i = 0; i < 2; i++) leds.setPixelColor(i, leds.Color(120, 50, 12));
leds.show();
if (!buzzed || now.second() % 20 == 0) {
for (int k = 0; k < 3; k++) { analogWrite(MOTOR, 90); delay(250); analogWrite(MOTOR, 0); delay(250); }
buzzed = true;
}
} else {
leds.clear(); leds.show(); analogWrite(MOTOR, 0);
}
delay(1000);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| 20 minutes before | Light begins very dim |
| At the wake time | Light steady and soft pulses |
| Five minutes later | Everything turns off |
| Power cycle | Clock keeps time |
If it does not work
Time wrong
Replace the RTC coin cell and reset the time.
Motor too strong
Lower the analogWrite value.
LEDs flicker
Check the data pin and the ground.
Battery warm
Stop and check for a short.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the sleep mask with wake light?
Seeed XIAO ESP32C3, WS2812B single LED module (8 mm / breakout) × 2, Vibration motor (coin type), DS3231 RTC module, Li-Po battery 3.7 V 500 mAh, BC547 NPN transistor, Resistor 1 kΩ and Signal Diode 1N4148.
How long does the sleep mask with wake light take to build?
About 120 minutes for a beginner maker, in 7 steps.
How do I know the sleep mask with wake light works?
20 minutes before: Light begins very dim. At the wake time: Light steady and soft pulses. Five minutes later: Everything turns off.
Time wrong: what should I check?
Replace the RTC coin cell and reset the time.
Motor too strong: what should I check?
Lower the analogWrite value.
LEDs flicker: what should I check?
Check the data pin and the ground.
Battery warm: what should I check?
Stop and check for a short.
