Devices & Components
Arduino Nano Every
Clock module
HC-SR501
Buzzer
Software & Tools
Arduino IDE
Project description
Code
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
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 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
1inary file (no preview
Downloadable files
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.
Alarm Clock schematics

Schematics with Arduino Nano (every)
Schematics with Arduino Nano (every)

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.
Alarm Clock schematics

Schematics with Arduino Nano (every)
Schematics with Arduino Nano (every)

Comments
Only logged in users can leave comments