Projects / Sleep mask with wake light

Sleep mask with wake light

Beginner2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP3219.3 mA

    Test the LEDs

    Light both warm white at low level.

  2. ESP32

    Test the motor

    Buzz softly from code.

  3. ESP32

    Add the clock

    Print the time to serial.

  4. ESP32

    Add the fade

    Grow the light over 20 minutes.

  5. ESP32

    Add the pulses

    Buzz three times at the alarm.

  6. ESP32+

    Add the battery

    Charge and run from the cell.

  7. ESP32

    Sew the mask

    Make pockets and a soft cover for each part.

In short

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

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
RTC VCC and GNDXIAO 3V3 and GNDPower
RTC SDA and SCLXIAO D4 and D5I2C
LED 1 DINXIAO D1Data
LED 1 DOUTLED 2 DINChain
LED modules VCC and GNDXIAO 3V3 and GNDPower
XIAO D21 kΩ to BC547 baseMotor switch
BC547 collectorMotor minusSwitched return
BC547 emitterXIAO GNDGround
Motor plusXIAO 3V3Supply
1N4148Across the motor, stripe to 3V3Flyback protection
LiPoXIAO BAT+ and BAT− padsPower 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.

CheckExpected
20 minutes beforeLight begins very dim
At the wake timeLight steady and soft pulses
Five minutes laterEverything turns off
Power cycleClock 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 →

Ask Lark AI

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.