The Automatic School Bell System is designed to automate the ringing of a school bell at predetermined times throughout the school day. The system consists of an Arduino UNO microcontroller, a buzzer, a DS3231 Real-Time Clock (RTC) module, a relay module, and a power supply. The Arduino UNO is programmed to trigger the relay, which in turn activates the buzzer at the start of each school period. The DS3231 RTC module is used to keep track of the current time, ensuring the bell rings at the correct intervals.
/*
* Automatic School Bell System
* This code controls a school bell that rings at the start of each period.
* There are 6 periods in total: 3 in the morning (9:00-12:00) and 3 in the
* afternoon (12:45-15:45). The bell rings at the start of each period.
*/
const int bellPin = 8; // Pin connected to the bell
void setup() {
pinMode(bellPin, OUTPUT); // Set bell pin as output
digitalWrite(bellPin, LOW); // Ensure bell is off initially
}
void loop() {
unsigned long currentMillis = millis();
unsigned long periodStartTimes[] = {
9 * 60 * 60 * 1000, // 9:00 AM
10 * 60 * 60 * 1000, // 10:00 AM
11 * 60 * 60 * 1000, // 11:00 AM
12 * 60 * 60 * 1000 + 45 * 60 * 1000, // 12:45 PM
13 * 60 * 60 * 1000 + 45 * 60 * 1000, // 1:45 PM
14 * 60 * 60 * 1000 + 45 * 60 * 1000 // 2:45 PM
};
for (int i = 0; i < 6; i++) {
if (currentMillis >= periodStartTimes[i] &&
currentMillis < periodStartTimes[i] + 1000) {
ringBell();
}
}
}
void ringBell() {
digitalWrite(bellPin, HIGH); // Turn bell on
delay(5000); // Ring bell for 5 seconds
digitalWrite(bellPin, LOW); // Turn bell off
}
Note: The code provided assumes that the Arduino's internal clock is set correctly and that the millis()
function returns the number of milliseconds since the Arduino started running the current program. The ringBell()
function activates the bell for 5 seconds at the start of each period.