Projects / Sunrise wake-up lamp

Sunrise wake-up lamp

Beginner2 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Wire the clock

    SDA to A4, SCL to A5, power from 5V and GND.

  2. NANO14.6 mA

    Wire the LEDs

    Two on D9 and two on D10, each with its own 220 ohm.

  3. NANO564 lux

    Wire the sensor

    LDR to 5V, junction to A0, 10k to GND.

  4. NANO

    Wire the button

    D2 to GND.

  5. NANODS323115:17

    Install RTClib

    From the Library Manager.

  6. NANO

    Test fast

    Set DEMO true and upload.

  7. NANO

    Watch the fade

    Glow rises over about 20 seconds.

  8. NANO

    Set the real wake time

    DEMO false, set WAKE_H and WAKE_M.

In short

How do you build a sunrise wake-up lamp?

A small LED lamp fades up slowly at a set time, and a light sensor holds it lower in a bright room. You need Arduino Nano, DS3231 RTC module, LED 5 mm white × 4, Resistor 220 Ω × 4, LDR Photoresistor, Resistor 10 kΩ, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
9

Parts list

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

Wiring

FromToWhy
RTC VCC and GNDNano 5V and GNDPower
RTC SDANano A4I2C data
RTC SCLNano A5I2C clock
Nano D9Two 220 ohm resistors, each to a white LED anodeFirst pair of LEDs
Nano D10Two 220 ohm resistors, each to a white LED anodeSecond pair of LEDs
All four LED cathodesNano GNDCommon ground
LDR one legNano 5VTop of the light divider
LDR other leg and 10k resistorNano A0, 10k other end to GNDBright light gives a higher reading
ButtonNano D2 to GNDCancel today's wake-up

Code

A sunrise lamp wakes you with light that rises slowly instead of a sudden alarm. Here a DS3231 real time clock keeps the time and a Nano raises four white LEDs from off to full over 20 minutes starting at the wake time, then holds them for another 30 minutes. Two points make the fade look natural. The first is gamma: your eye sees brightness roughly as a power of the light, so the sketch raises the fade fraction to the power of 2.2 before setting the PWM, and the lamp seems to grow evenly instead of jumping on at the start. The second is the light sensor. A photoresistor in a divider with a 10 kilohm resistor gives a higher reading when the room is bright, and if the reading goes above a threshold the lamp is capped at 30 percent, so it does not shine at full power in a room that already has daylight. A button cancels today's wake-up. To test quickly, set DEMO to true and the fade runs in 20 seconds. Install RTClib by Adafruit. The LEDs here are small indicator parts, so the lamp is a soft glow rather than a reading light, and each LED has its own 220 ohm resistor and each pin drives only two LEDs to stay inside the pin current limit. Do not use it as a clinical light therapy device.

Runs on a virtual Arduino Nano 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).

#include <Wire.h>
#include <RTClib.h>                         // "RTClib" by Adafruit

RTC_DS3231 rtc;
const int LED_A = 9, LED_B = 10, LDR = A0, BTN = 2;

const int WAKE_H = 7, WAKE_M = 0;           // wake time
const int FADE_MIN = 20;                    // minutes to fade from off to full
const int STAY_MIN = 30;                    // minutes to stay on after full
const int ROOM_BRIGHT = 600;                // LDR reading above this means a bright room
const bool DEMO = false;                    // true: fade over 20 seconds, to test quickly
int cancelledDay = -1;

void setup() {
  pinMode(LED_A, OUTPUT); pinMode(LED_B, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);
  Serial.begin(9600);
  if (!rtc.begin()) { Serial.println("No RTC found"); while (1); }
  if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));   // sets the clock to the upload time
}

void loop() {
  DateTime now = rtc.now();
  if (digitalRead(BTN) == LOW) cancelledDay = now.day();

  float m;                                   // minutes since the wake time
  if (DEMO) {
    m = (millis() / 1000UL) % 60;            // one second stands for one minute
  } else {
    m = (now.hour() * 60 + now.minute()) - (WAKE_H * 60 + WAKE_M);
    if (m < 0) m += 1440;
  }

  float frac = 0;
  if (cancelledDay != now.day() && m < FADE_MIN + STAY_MIN) {
    frac = (m >= FADE_MIN) ? 1.0 : m / FADE_MIN;
  }

  int room = analogRead(LDR);
  float cap = (room > ROOM_BRIGHT) ? 0.3 : 1.0;      // dim the lamp when it is already bright
  float level = pow(frac * cap, 2.2);                 // gamma, so the fade looks smooth
  int duty = (int)(level * 255);
  analogWrite(LED_A, duty);
  analogWrite(LED_B, duty);

  static unsigned long last = 0;
  if (millis() - last > 10000) {
    last = millis();
    Serial.print(now.hour()); Serial.print(":"); Serial.print(now.minute());
    Serial.print("  room "); Serial.print(room);
    Serial.print("  duty "); Serial.println(duty);
  }
  delay(100);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

No RTC found

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Before the wake timeLEDs off
Fade periodSmooth rise with no steps
Cover the LDRLamp can reach full power
Shine a light on the LDRLamp capped lower
Press the buttonLamp stays off for the rest of the day

If it does not work

No RTC found

Check SDA, SCL and power on the clock module.

Wrong time

Upload once so the clock is set, then check the coin cell.

Fade looks like steps

Check the gamma line and the PWM pins.

Lamp always dim

Check the LDR divider, the room reading may be above the threshold.

Pin or LEDs warm

Check each LED has its own 220 ohm.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the sunrise wake-up lamp?

Arduino Nano, DS3231 RTC module, LED 5 mm white × 4, Resistor 220 Ω × 4, LDR Photoresistor, Resistor 10 kΩ, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.

How long does the sunrise wake-up lamp take to build?

About 120 minutes for a beginner maker, in 8 steps.

How do I know the sunrise wake-up lamp works?

Before the wake time: LEDs off. Fade period: Smooth rise with no steps. Cover the LDR: Lamp can reach full power.

No RTC found: what should I check?

Check SDA, SCL and power on the clock module.

Wrong time: what should I check?

Upload once so the clock is set, then check the coin cell.

Fade looks like steps: what should I check?

Check the gamma line and the PWM pins.

Lamp always dim: what should I check?

Check the LDR divider, the room reading may be above the threshold.