galoebn
Published © GPL3+

Alarm clock that really gets you out of bed in the morning

I created an alarm clock using a motion detection sensor so that you're not able to just hit the snooze button and go back to sleep.

IntermediateFull instructions provided10 hours9,024
Alarm clock that really gets you out of bed in the morning

Things used in this project

Hardware components

Arduino Nano Every
Arduino Nano Every
I will be using the Nano Every for the final assembly. But you can use pretty much any other Arduino as well (in the beginning I use a Mega2560).
×1
Clock module
×1
HC-SR501
This is the motion sensor
×1
Buzzer
Buzzer
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Alarm Clock schematics

I forgot to draw a connection to VCC and GND on the breadboard. So you just need to connect 5V on the Arduino to the positive rail and GND on the Arduino to the negative rail.

Schematics with Arduino Nano (every)

Code

Alarm Clock Arduino Code

Arduino
#include <Wire.h>
#include <DS3231.h>

DS3231 clock;
RTCDateTime dt;

int button = 9;
int pirPin = 7; // Input for HC-S501
int pirValue; // Place to store read PIR Value

//--------------------------------------
int set_hour = 7;
int set_minute = 0;
//--------------------------------------

void setup() {
  clock.begin();
  pinMode(button, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  //clock.setDateTime(__DATE__, __TIME__); // !!AFTER THE FIRST UPLOAD YOU HAVE TO COMMENT OUT THIS LINE. OTHERWISE YOU WILL GET A WRONG TIME!!
  pinMode(pirPin, INPUT);
}



void alarm(int minute){
  bool button_pressed = false;
  bool awake = false;
  bool movement = false;
  
  while(!button_pressed){     //the alarm is on as long the button isn't pressed
    for(int i = 0; i < 4; i++){
      tone(11, 523, 100);
      delay(100);
      tone(11, 784, 50);

      for(int i = 0; i < 20; i++){
        if(digitalRead(button) == LOW){
        button_pressed = true;
        awake = true;
        dt = clock.getDateTime();
        minute = dt.minute;
        }
        delay(65);
      }
    }
  }

  dt = clock.getDateTime();
  minute = dt.minute;

  while(awake){
    movement = false;
    dt = clock.getDateTime();
    for(int i = 0; i < 30; i++){
      if(digitalRead(pirPin)){movement = true;}
    }
    digitalWrite(LED_BUILTIN, movement);
    if(!pirValue){
      delay(5000);
      for(int i = 0; i < 40; i++){
        if(digitalRead(pirPin)){movement = true;}
      }
      if(!movement){
        alarm(minute); //if no motion is detected for too long the alarm resets
      }
    }

    if(abs(dt.minute - minute) >= 1){ //set the time period where you must be in front of the sensor
      tone(11, 698, 50);
      delay(100);
      tone(11, 698, 50);
      digitalWrite(LED_BUILTIN, 0);
      awake = false;
    }

    delay(100);
  }

}
 
void loop() {  
  dt = clock.getDateTime();
  if(set_minute == dt.minute && set_hour == dt.hour){
    alarm(set_minute);
  }

  delay(10000);
}

Clock Library

Arduino
This is a zip file for the DS3231 library. You have to download this and add it to your libraries as follows:
open Arduino --> go to "Sketch" -> "Include Library " -> "Add .ZIP Library" --> go to the zip file and click ok
No preview (download only).

Credits

galoebn

galoebn

9 projects • 3 followers

Comments