In our school there is a man who rings the starting and ending of periods and he do that 9 times a day, so I thought why don't we automate this process so it will be more accurate and don't need any human interaction and that what we are trying to do today.
First an image for the components:This project is pretty easy but it will be very useful as we said earlier.
Second let's start combining this components to get our device:1- Connect the 5v of the Arduino to the positive rail of the breadboard and the GND of the Arduino to the negative rail of the bread board.
2- Connect the clock module as follows:
- VCC to +ve rail.
- GND to -ve rail.
- CLK to pin 6.
- DAT to pin 7.
- RST to pin 8.
3- Connect the relay module as follows:
- VCC to +ve rail.
- GND to -ve rail.
- in1(signal pin) to pin 9.
4- Connect the positive side of the led to the 220 ohm resistor on a rail on the breadboard also take a jumper wire and connect the positive side which is connected with the resistor to pin 10 in the Arduino.
5- Connect the buzzer to the relay or any other alarm like the school bell as you will see in the schematic.
First: you have to download the RTC library from the following git repo:
https://github.com/chrisfryer78/ArduinoRTClibrary.git
Second: we will set the time to our local time using the following code:
#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);
Remember to upload the code with your local time then remove this line: myRTC.setDS1302Time(00, 59, 23, 6, 10, 1, 2020);
then upload it once again immediately after uploading the first code.
Third: Our main code after setting the time to our local time, this code is pretty dumb but it will do the job so change the time in the if conditions as your school schedule is, this is my school schedule periods and you can find this in the foloing code:
#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);
}
}
and finally this is a photo of the completed project:
Thanks!
Comments
Please log in or sign up to comment.