Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
AdelAshraf
Published © GPL3+

School alarm automation

In this project I am trying to automate the school alarm using Arduino, RTC clock module and a relay.

BeginnerFull instructions provided2 hours5,384
School alarm automation

Things used in this project

Story

Read more

Schematics

The schematics of the automated alarm

The detailed schematics for the project

Note that I use an older version of the RTC module which is ds1302

Code

Setting the time for the RTC module

Arduino
In this you will find the code to set the real time for the RTC module
#include <virtuabotixRTC.h>                                                                              
virtuabotixRTC myRTC(6, 7, 8);

void setup()  {      
  Serial.begin(9600);

// Set the current date, and time in the following format:
// seconds, minutes, hours, day of the week, day of the month, month, year note: the week starts with monday so monday = 1, etc.
  myRTC.setDS1302Time(00, 59, 23, 6, 10, 1, 2020); // upload the sketch with the time you are at then reupload this sketch without this line just after uploading the first sketch.
}

void loop()  {                                                                                            
// This allows for the update of variables for time or accessing the individual elements.                
  myRTC.updateTime();                                                                                     
// Start printing elements as individuals                                                                   
  Serial.print("Current Date / Time: ");                                                                  
  Serial.print(myRTC.dayofmonth);                                                                         
  Serial.print("/");                                                                                      
  Serial.print(myRTC.month);                                                                              
  Serial.print("/");                                                                                      
  Serial.print(myRTC.year);                                                                               
  Serial.print("  ");                                                                                     
  Serial.print(myRTC.hours);                                                                              
  Serial.print(":");                                                                                      
  Serial.print(myRTC.minutes);                                                                            
  Serial.print(":");                                                                                      
  Serial.println(myRTC.seconds);                                                                          
// Delay so the program doesn't print non-stop                                                            
  delay(1000);                                                                                           
}

School alarm automation code

Arduino
#include  <virtuabotixRTC.h>  // The RTC library 

//Wiring     CLK -> 6 , DAT -> 7, Reset -> 8

virtuabotixRTC myRTC(6, 7, 8); 
int relay = 9; // The signal pin of the relay connected to pin 9 in the Arduino
int led = 10; // Positive leg of the LED connected to pin 10 in the Arduino 

void setup() {
  Serial.begin(9600);
  pinMode(relay, OUTPUT);     
  pinMode(led, OUTPUT);                                                              
}

void loop() {
  myRTC.updateTime();                                                                                     
                                                                                                          
// Start printing elements as individuals                                                                   
  Serial.print("Current Date / Time: ");                                                                  
  Serial.print(myRTC.dayofmonth);                                                                         
  Serial.print("/");                                                                                     
  Serial.print(myRTC.month);                                                                            
  Serial.print("/");                                                                                      
  Serial.print(myRTC.year);                                                                               
  Serial.print("  ");                                                                                    
  Serial.print(myRTC.hours);                                                                             
  Serial.print(":");                                                                                     
  Serial.print(myRTC.minutes);                                                                           
  Serial.print(":");                                                                                     
  Serial.println(myRTC.seconds);                                                                                                                                                                              
// Delay so the program doesn't print non-stop                                                           
  delay(1000);
  myRTC.updateTime();
  
    if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 7 and myRTC.minutes == 45 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);    
    }
    
    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 8 and myRTC.minutes == 45 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);    
    }

    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 9 and myRTC.minutes == 30 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);    
    }


    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 10 and myRTC.minutes == 15 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);   
    }

    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 11 and myRTC.minutes == 00 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);  
    }


    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 11 and myRTC.minutes == 45 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);  
    }
    

    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 12 and myRTC.minutes == 30 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);  
    }
    

    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 13 and myRTC.minutes == 00 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);   
    }
    
    
    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 13 and myRTC.minutes == 30 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);  
    }

    else if (myRTC.dayofweek != 5 and myRTC.dayofweek != 6 and myRTC.hours == 14 and myRTC.minutes == 00 and myRTC.seconds == 00  ){
    digitalWrite(relay, HIGH); 
    digitalWrite(led, HIGH);  
    delay(20000);                      
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);
    }
    else{ 
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);
       }  
}

School alarm automation repo

You will find the codes for this project in this repo as well as the code for setting time for the RTC module and the link to the RTC library in the readme.

Credits

AdelAshraf
1 project • 5 followers
i love making things to help people, i love programming , robotics and electronics.
Contact

Comments

Please log in or sign up to comment.