I am trying to make an alarm clock using a 16x2 LCD screen, a 10k potentiometer, a passive buzzer, and a DS3231 RTC. When I turn on the circuit, everything works fine, except the buzzer. I quickly threw together a fritzing. Any help would be appreciated!
#include <DS3231.h>
#include <LiquidCrystal.h>
#include <Wire.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
DS3231 rtc(SDA,SCL);
Time t;
int Hor;
int Min;
int Sec;
const int buzzerPin = 8;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Wire.begin();
rtc.begin();
lcd.begin(16,2);
pinMode(buzzerPin, OUTPUT);
lcd.setCursor(0,0);
lcd.print("Alarm on");
delay(1000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
serialDate();
t=rtc.getTime();
Hor = t.hour;
Min = t.min;
Sec = t.sec;
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
lcd.setCursor(0,1);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());
if( Hor == 11 && (Min == 32 || Min == 33)){ //Comparing the current time with the Alarm time
buzz(3000);
buzz(3000);
lcd.clear();
lcd.print("Alarm ON");
lcd.setCursor(0,1);
lcd.print("Alarming");
buzz(3000);
buzz(3000);
}
delay(1000);
}
void buzz(int pitch){
tone(buzzerPin,pitch);
delay(40);
noTone(buzzerPin);
delay(40);
}
void printDate(){
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}
void serialDate(){
Serial.print("Date: ");
Serial.print(rtc.getDateStr());
Serial.println("Time: ");
Serial.print(rtc.getTimeStr());
delay(1000);
}
