SCHOOLBELL
SCHOOLBELL
h>
#include <RTClib.h>
// Pin definitions
#define BUZZER_PIN 9 // Connected to buzzer
#define RELAY_PIN 8 // Connected to relay module
// Bell types
#define NORMAL_BELL 1
#define PATTERN_BELL 2
#define HOURLY_BELL 3
void setup() {
Serial.begin(9600);
// Initialize pins
pinMode(BUZZER_PIN, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
// Initialize RTC
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// Uncomment the line below to set the RTC to the date & time when the
sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
void loop() {
DateTime now = rtc.now();
Serial.print(now.hour());
Serial.print(":");
if (now.minute() < 10) Serial.print("0");
Serial.print(now.minute());
Serial.print(":");
if (now.second() < 10) Serial.print("0");
Serial.println(now.second());
}
bellRung = true;
Serial.print("Bell ringing at: ");
Serial.print(now.hour());
Serial.print(":");
if (now.minute() < 10) Serial.print("0");
Serial.print(now.minute());
Serial.print(":");
if (now.second() < 10) Serial.print("0");
Serial.println(now.second());
}
return; // Exit the loop early once we've found a match
}
}
// Ring both buzzer and relay continuously for the specified duration
void ringNormalBell(uint16_t duration) {
// Activate both buzzer and relay
digitalWrite(RELAY_PIN, HIGH);
tone(BUZZER_PIN, 1000); // 1kHz tone
// Ring both buzzer and relay in on/off pattern for the specified
duration
void ringPatternBell(uint16_t duration) {
unsigned long startTime = millis();
bool isOn = false;
int patternInterval = 500; // 0.5 second intervals for on/off pattern
isOn = !isOn;
delay(patternInterval);
}