• An alarm clock that actually gets you out of bed in the morning

QC

An alarm clock that actually gets you out of bed in the morning

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

Devices and components

Arduino Nano all

Clock module

HC-SR501

Buzzer

Software and tools

Arduino IDE

Project description

Assembly

the negative pin of the buzzer -> GND

the positive buzzer pin --> D11

button pin -> GND

the other pin of the button --> D9

motion sensor VCC --> 5V

motion sensor output --> D7

motion sensor GND --> GND

clock module GND --> GND

clock module VCC --> 5V

SDA clock module --> SDA (pin 20 for the Mega2560)

SCL clock module --> SCL (pin 21 for the Mega2560)

Code

clock.setDateTime(__DATE__, __TIME__);

//--------------------------------------

int set_hour = 6;

int set_minute = 55;

//--------------------------------------

if(abs(dt.minute - minute) >= 1){ //set the time period where you must //be in

Sensor adjustment

Now we make it compact

Clock Library

arduino

This is a zip file for the DS3231 library. You need to download it and add it to your libraries as follows:

open Arduino -> go to "Sketch" -> "Include Library" -> "Add .ZIP Library" -> go to zip file and click ok

1inary file (no preview

Alarm clock Arduino code

arduino

1#include <Wire.h>
2#include <DS3231.h>
3
4DS3231 clock;
5RTCDateTime dt;
6
7int button = 9;
8int pirPin = 7; // Input for HC-S501
9int pirValue; // Place to store read PIR Value
10
11//--------------------------------------
12int set_hour = 7;
13int set_minute = 0;
14//--------------------------------------
15
16void setup() {
17 clock.begin();
18 pinMode(button, INPUT_PULLUP);
19 pinMode(LED_BUILTIN, OUTPUT);
20 //clock.setDateTime(__DATE__, __TIME__); // !!AFTER THE FIRST UPLOAD YOU HAVE TO COMMENT OUT THIS LINE. OTHERWISE YOU WILL GET A WRONG TIME!!
21 pinMode(pirPin, INPUT);
22}
23
24
25
26void alarm(int minute){
27 bool button_pressed = false;
28 bool awake = false;
29 bool movement = false;
30
31 while(!button_pressed){ //the alarm is on as long the button isn't pressed
32 for(int i = 0; i < 4; i++){
33 tone(11, 523, 100);
34 delay(100);
35 tone(11, 784, 50);
36
37 for(int i = 0; i < 20; i++){
38 if(digitalRead(button) == LOW){
39 button_pressed = true;
40 awake = true;
41 dt = clock.getDateTime();
42 minute = dt.minute;
43 }
44 delay(65);
45 }
46 }
47 }
48
49 dt = clock.getDateTime();
50 minute = dt.minute;
51
52 while(awake){
53 movement = false;
54 dt = clock.getDateTime();
55 for(int i = 0; i < 30; i++){
56 if(digitalRead(pirPin)){movement = true;}
57 }
58 digitalWrite(LED_BUILTIN, movement);
59 if(!pirValue){
60 delay(5000);
61 for(int i = 0; i < 40; i++){
62 if(digitalRead(pirPin)){movement = true;}
63 }
64 if(!movement){
65 alarm(minute); //if no motion is detected for too long the alarm resets
66 }
67 }
68
69 if(abs(dt.minute - minute) >= 1){ //set the time period where you must be in front of the sensor
70 tone(11, 698, 50);
71 delay(100);
72 tone(11, 698, 50);
73 digitalWrite(LED_BUILTIN, 0);
74 awake = false;
75 }
76
77 delay(100);
78 }
79
80}
81
82void loop() {
83 dt = clock.getDateTime();
84 if(set_minute == dt.minute && set_hour == dt.hour){
85 alarm(set_minute);
86 }
87
88 delay(10000);
89}
90

Clock Library

arduino

This is a zip file for the DS3231 library. You need to download it and add it to your libraries as follows:

open Arduino -> go to "Sketch" -> "Include Library" -> "Add .ZIP Library" -> go to zip file and click ok

1inary file (no preview

Downloadable files

Patterns of awakening

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

Patterns of awakening

Schematics with Arduino Nano (all)

Schematics with Arduino Nano (all)

Patterns of awakening

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

Patterns of awakening




Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.

SendData

Điều khiển trạng thái qua Firebase Trạng thái hiện tại: Đang tải... ĐỔI TRẠNG THÁI