Arduino Light Alarm Module

Last updated: January 15, 2024

I build an alarm that turns on the Light for my room when its time to wake up

Simple build, but helps alot on winter mornings in the northern hemisphere where 6am is dark and makes it harder to wake up

Components:

-Aruino UNO -Relay module -Lamp -RTC Module

Electrical connections

Connect Every ground and 5V to a power supply, I used a female usb-c jack and connected black to black(or blue for display ground), alongside the white display wire and the white from the display. Green data from display with yellow data from camera. Blue signal high with 5v stream.

The camera also has two blue/white RX/TX connections for the button control (you can customize image settings with this, I put it on the side)

3D Printed

Final Assembly

3D Printed

Code

#include <Wire.h>
#include <RTClib.h>

RTC_DS1307 rtc;

int relayPin = 9;
bool wakeupRunning = false;
unsigned long wakeupStart = 0;
unsigned long lastFlash = 0;
bool lightOn = false;
int phase = 0;

void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);
  
  Wire.begin();
  rtc.begin();
  
  rtc.adjust(DateTime(2025, 6, 13, 1, 0, 0));
}

void loop() {
  DateTime now = rtc.now();
  
  if (now.hour() == 6 && now.minute() == 30 && !wakeupRunning) {
    wakeupRunning = true;
    wakeupStart = millis();
    phase = 1;
    lightOn = false;
    lastFlash = millis();
    digitalWrite(relayPin, LOW);
  }
  
  if (wakeupRunning) {
    unsigned long elapsed = millis() - wakeupStart;
    
    if (phase == 1) {
      if (elapsed < 120000) {
        if (millis() - lastFlash >= 500) {
          lightOn = !lightOn;
          digitalWrite(relayPin, lightOn ? HIGH : LOW);
          lastFlash = millis();
        }
      } else {
        phase = 2;
        digitalWrite(relayPin, HIGH);
      }
    }
    else if (phase == 2) {
      if (elapsed >= 1020000) {
        digitalWrite(relayPin, LOW);
        wakeupRunning = false;
        phase = 0;
      }
    }
  }
  
  delay(1000);
}

Change the current time on line 18 and you are set. comment it out again when flashing for a second time

Arduino