Digital alarm clock

Hello, I need some help with my school project. I found a schematic here LCD Digital Alarm Clock Arduino – Microcontroller Based Projects . I did everything fine but when alarm is supposed to turn on piezo buzzer doesn't do anything. Is problem in code or did I use wrong buzzer which works on 5V.

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Posting images: https://forum.arduino.cc/index.php?topic=519037.0

Always show us your ‘current’ complete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int TimeHours10s =  0;
int TimeHours1s =  0;
int TimeMinutes10s =  0;
int TimeMinutes1s =  0;
int TimeSeconds10s =  0;
int TimeSeconds1s =  0;
int AlarmHours10s =  0;
int AlarmHours1s =  0;
int AlarmMinutes10s =  0;
int AlarmMinutes1s =  0;
int AlarmSeconds10s =  0;
int AlarmSeconds1s =  0;

int AlarmSet = 6;
int TimeSet = 7;
int Min = 8;
int Hour = 9;
int Buzzer =10;

void setup() 
{
 
  //pinMode(Triger, OUTPUT);  
  pinMode(AlarmSet,INPUT_PULLUP);  //Bit_6
  pinMode(TimeSet, INPUT_PULLUP);  //Bit_7
  pinMode(Hour, INPUT_PULLUP);  //Bit_8
  pinMode(Min, INPUT_PULLUP);  //Bit_9
  pinMode(Buzzer, OUTPUT);  //Bit_10
  
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
}

void loop() 
{
CalculateTime();  
ShowTime();
ShowAlarm();
delay(500);
CompareAlarmTime();

if(digitalRead(AlarmSet)== LOW && digitalRead(Min)== LOW)
{
  AlarmMinutes1s++;
  delay(500);
  CalculateAlarm();
}
if(digitalRead(AlarmSet)== LOW && digitalRead(Hour)== LOW)
{
  AlarmHours1s++;
  delay(500);
  CalculateAlarm();
}

if(digitalRead(TimeSet)== LOW && digitalRead(Min)== LOW)
{
  TimeMinutes1s++;
  delay(500);
  CalculateTime();
}
if(digitalRead(TimeSet)== LOW && digitalRead(Hour)== LOW)
{
  TimeHours1s++;
  delay(500);
  CalculateTime();
}

delay(500);
}

 void ShowTime()
  {

  lcd.display();
  lcd.setCursor(0, 0); // top left
  lcd.print("Time  ");//
  if(TimeHours10s == 0)
  lcd.print(" ");//
  else
  lcd.print(TimeHours10s);//
  lcd.print(TimeHours1s);//
  lcd.print(":");//
  lcd.print(TimeMinutes10s);//
  lcd.print(TimeMinutes1s);//
  lcd.print(":");//
  lcd.print(TimeSeconds10s);//
  lcd.print(TimeSeconds1s);//
  lcd.setCursor(0, 0); // top left
  }

   void ShowAlarm()
  {
  //lcd.display();
  lcd.setCursor(0, 1); // bottom left
  lcd.print("Alarm ");//
  if(AlarmHours10s == 0)
  lcd.print(" ");//
  else
  lcd.print(AlarmHours10s);//
  lcd.print(AlarmHours1s);//
  lcd.print(":");//
  lcd.print(AlarmMinutes10s);//
  lcd.print(AlarmMinutes1s);//
  lcd.print(":");//
  lcd.print(AlarmSeconds10s);//
  lcd.print(AlarmSeconds1s);//
  lcd.setCursor(0, 1); // bottom left
  }

void CalculateTime()
{
 TimeSeconds1s++;
  if(TimeSeconds1s == 10)
  {
  TimeSeconds1s = 0;
  TimeSeconds10s++;
  }
  if(TimeSeconds10s == 6)
  {
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeMinutes1s++;
  }
  if(TimeMinutes1s == 10)
  {
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeMinutes10s++;
  }
  if(TimeMinutes10s == 6)
  {
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeHours1s++;
  }
  if(TimeHours1s == 10) 
  {
  TimeHours1s=0;
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeHours10s++;
  }
  if(TimeHours10s == 2 && TimeHours1s == 4) 
  {
  TimeHours10s=0; 
  TimeHours1s=0;
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
 
  } 
}

  void CalculateAlarm()
{
 //AlarmSeconds1s++;
  if(AlarmSeconds1s == 10)
  {
  AlarmSeconds1s = 0;
  AlarmSeconds10s++;
  }
  if(AlarmSeconds10s == 6)
  {
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmMinutes1s++;
  }
  if(AlarmMinutes1s == 10)
  {
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmMinutes10s++;
  }
  if(AlarmMinutes10s == 6)
  {
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmHours1s++;
  }
  if(AlarmHours1s == 10) 
  {
  AlarmHours1s=0;
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmHours10s++;
  }
  if(AlarmHours10s == 2 && AlarmHours1s == 4) 
  {
  AlarmHours10s=0; 
  AlarmHours1s=0;
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  } 
}
 void CompareAlarmTime()
 {
  if(TimeHours10s == AlarmHours10s && TimeHours1s == AlarmHours1s && TimeMinutes10s == AlarmMinutes10s && TimeMinutes1s == AlarmMinutes1s )
  {
   digitalWrite(Buzzer, HIGH); 
   delay(100);
   digitalWrite(Buzzer, LOW); 
   delay(100);
  }
 }

I know it’s a little bit messy but it’s all connected right.

Give us a link to the buzzer, it may be the wrong kind.

What is the resistance of the buzzer?

Write a simple sketch that toggles the pin with the buzzer, to see if things work.

Try:
if(TimeHours10s == AlarmHours10s && TimeHours1s == AlarmHours1s && TimeMinutes10s == AlarmMinutes10s && TimeMinutes1s == AlarmMinutes1s )
{
Serial.print("Buzzzzz"); // set up Serial.begin(9600) in setup()
digitalWrite(Buzzer, HIGH);
delay(100);

Make sure it's really a Buzzer, and not a piezoelectric speaker which are often, incorrectly, referred to as "buzzers" [a buzzer is a device that buzzes when voltage is applied -- a piezo speaker is just that, a speaker, which requires a signal to cause it to make sound].

If it turns out to be a speaker, then using the tone() function will likely cause it to make a sound. Try around 1kHz to 5kHz -- and get ready to plug your ears! If it's too loud, try adding a resistor in series -- something like 100Ω or so -- but experimentation will likely be necessary.

If you have a datasheet for the "buzzer", look up things like resonant frequency, and maximum voltage. Then, set the tone() function to that resonant frequency, and make sure you don't apply a voltage that will exceed it's max [unlikely at 5v :wink: ]

This is link of buzzer I got FV 5x(10pcs 5v Active Buzzer Magnetic Long Continous Beep Tone Alarm Ringer F6 for sale online | eBay . I found datasheet and it's the first electromagnetic buzzer ( SD1209T5-A1) https://datasheet.lcsc.com/szlcsc/SD1209TT-A1_C91083.pdf .I tried your suggestions and none of them worked :confused:. Should I buy a piezo speaker or electromagnetic buzzer of lower operating voltage?

Looks like that buzzer has a resistance of 90 Ω.
Too low to be drive by an output pin directly.

Suggest you drive it with a transistor or buy a piezoelectric speaker.
Place a snubbing diode across the buzzer, cathode to Vcc.

How did the Serial.print test work?

Serial.print test didn't work,LCD just displayed letters and numbers normal and buzzer did nothing. If I buy piezoelectric speak 3V would it work or do I need 5V one.

If the serial monitor showed nothing, you also have a problem with the code.

Something like this would work.
https://www.jameco.com/z/AZ-1440E-P-LF-Kobitone-Audio-Company-Buzzer-Piezo-5-Vp-p-80-dB-4-kHz-5-mA-Pin-Contacts_2098523.html

However you can drive your buzzer with a transistor cct.

Well I bought this piezo speaker http://html.alldatasheet.com/html-pdf/592719/MALLORY/PB-12N23P-03Q/300/1/PB-12N23P-03Q.html and it still didn’t work.

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int TimeHours10s =  0;
int TimeHours1s =  0;
int TimeMinutes10s =  0;
int TimeMinutes1s =  0;
int TimeSeconds10s =  0;
int TimeSeconds1s =  0;
int AlarmHours10s =  0;
int AlarmHours1s =  0;
int AlarmMinutes10s =  0;
int AlarmMinutes1s =  0;
int AlarmSeconds10s =  0;
int AlarmSeconds1s =  0;
int AlarmSet = 6;
int TimeSet = 7;
int Min = 8;
int Hour = 9;
int Buzzer =10;

void setup() 
{ 
  pinMode(AlarmSet,INPUT_PULLUP);  
  pinMode(TimeSet, INPUT_PULLUP); 
  pinMode(Hour, INPUT_PULLUP);
  pinMode(Min, INPUT_PULLUP);  
  pinMode(Buzzer, OUTPUT);  

  lcd.begin(16, 2);
}

void loop() 
{
CalculateTime();  
ShowTime();
ShowAlarm();
delay(500);

if(digitalRead(AlarmSet)== LOW && digitalRead(Min)== LOW)
{
  AlarmMinutes1s++;
  delay(500);
  CalculateAlarm();
}
if(digitalRead(AlarmSet)== LOW && digitalRead(Hour)== LOW)
{
  AlarmHours1s++;
  delay(500);
  CalculateAlarm();
}
if(digitalRead(TimeSet)== LOW && digitalRead(Min)== LOW)
{
  TimeMinutes1s++;
  delay(500);
  CalculateTime();
}
if(digitalRead(TimeSet)== LOW && digitalRead(Hour)== LOW)
{
  TimeHours1s++;
  delay(500);
  CalculateTime();
}

delay(500);
}

 void ShowTime()
  {
  lcd.display();
  lcd.setCursor(0, 0); 
  lcd.print("Time  ");
  lcd.print(TimeHours10s);
  lcd.print(TimeHours1s);
  lcd.print(":");
  lcd.print(TimeMinutes10s);
  lcd.print(TimeMinutes1s);
  lcd.print(":");
  lcd.print(TimeSeconds10s);
  lcd.print(TimeSeconds1s);
  lcd.setCursor(0, 0);
  }

   void ShowAlarm()
  {
  lcd.display();
  lcd.setCursor(0, 1); 
  lcd.print("Alarm ");
  lcd.print(AlarmHours10s);
  lcd.print(AlarmHours1s);
  lcd.print(":");
  lcd.print(AlarmMinutes10s);
  lcd.print(AlarmMinutes1s);
  lcd.print(":");
  lcd.print(AlarmSeconds10s);
  lcd.print(AlarmSeconds1s);
  lcd.setCursor(0, 1); 
  }

void CalculateTime()
{
 TimeSeconds1s++;
  if(TimeSeconds1s == 10)
  {
  TimeSeconds1s = 0;
  TimeSeconds10s++;
  }
  if(TimeSeconds10s == 6)
  {
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeMinutes1s++;
  }
  if(TimeMinutes1s == 10)
  {
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeMinutes10s++;
  }
  if(TimeMinutes10s == 6)
  {
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeHours1s++;
  }
  if(TimeHours1s == 10) 
  {
  TimeHours1s=0;
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeHours10s++;
  }
  if(TimeHours10s == 2 && TimeHours1s == 4) 
  {
  TimeHours10s=0; 
  TimeHours1s=0;
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
 
  } 
}
  void CalculateAlarm()
{
  if(AlarmMinutes1s == 10)
  {
  AlarmMinutes1s = 0;
  AlarmMinutes10s++;
  }
  if(AlarmMinutes10s == 6)
  {
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmHours1s++;
  }
  if(AlarmHours1s == 10) 
  {
  AlarmHours1s=0;
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmHours10s++;
  }
  if(AlarmHours10s == 2 && AlarmHours1s == 4) 
  {
  AlarmHours10s=0; 
  AlarmHours1s=0;
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  } 
  if(TimeHours10s == AlarmHours10s && TimeHours1s == AlarmHours1s && TimeMinutes10s == AlarmMinutes10s && TimeMinutes1s == AlarmMinutes1s )
  {
   tone(Buzzer, 2300); 
  delay(10000);        
  noTone(Buzzer);    
  delay(1000); 
  }
 }

I changed little part of code and it still didn’t work.Can you check code and tell me if something is wrong?

As mentioned in post #9, "If the serial monitor showed nothing, you also have a problem with the code."

  • Check your buzzer's functionality by writing a very simple, couple line sketch.

  • To more easily chase your problem, change this line of code to one item:
    if(TimeHours10s == AlarmHours10s && TimeHours1s == AlarmHours1s && TimeMinutes10s == AlarmMinutes10s && TimeMinutes1s == AlarmMinutes1s )

  • To prove variables are what they should be, you can add some diagnostic lines of code at strategic locations, Serial.println(AlarmMinutes1s); .

Does either "buzzer" work if you apply power to it manually -- i.e. if you apply 5V to it, does it buzz [I suggest you place a 100Ω resistor in series with the positive lead, if you hear a click, then it's a *speaker*, not a *buzzer*. If you don't hear a click, then try it without the resistor, etc.]? If not, then either it needs a greater voltage to properly function, or less resistance in series, or it's not a buzzer, but a speaker, or it's bad. Try a simple sketch that uses the tone() function to apply a tone to the piezo.

If it does sound when you apply voltage directly [probably with that series resistor ;)], then the Arduino pin may not be able to supply enough current. You will need to drive it with a transistor. But, I can't imagine a piezo device would need more than 40mA.

Here's a few great tutorials:

ReverseEMF:
Does either "buzzer" work if you apply power to it manually -- i.e. if you apply 5V to it, does it buzz [I suggest you place a 100Ω resistor in series with the positive lead, if you hear a click, then it's a *speaker*, not a *buzzer*. If you don't hear a click, then try it without the resistor, etc.]? If not, then either it needs a greater voltage to properly function, or less resistance in series, or it's not a buzzer, but a speaker, or it's bad. Try a simple sketch that uses the tone() function to apply a tone to the piezo.

If it does sound when you apply voltage directly [probably with that series resistor ;)], then the Arduino pin may not be able to supply enough current. You will need to drive it with a transistor. But, I can't imagine a piezo device would need more than 40mA.

Here's a few great tutorials:

The site linked you linked (instructables) has infection web site links on it !

larryd:
The site linked you linked (instructables) has infection web site links on it !

Really? I don't see that. How did you determine that?

I went to Instructabels, tried a link on the page, window opened and said link is trying to go to a questionable web site, trying to download a virus on you PC …
I am using an iPad.

Instructables is a very bad place and has a bad history from members on this forum.

Best to just avoid it if at all possible.

larryd:
I went to Instructabels, tried a link on the page, window opened and said link is trying to go to a questionable web site, trying to download a virus on you PC …
I am using an iPad.

Instructables is a very bad place and has a bad history from members on this forum.

Best to just avoid it if at all possible.

OK, I removed the link.