How do I add a buzzer to my arduino lcd timer?

Hello,
I am needing help with connecting a buzzer to my arduino controlled lcd keypad shield timer.

here is the code:

#include <LiquidCrystal.h>
#include "LCDKeypad.h"
#define HOURS 1
#define MINUTES 2
#define SECONDS 3// The LCD screen
LCDKeypad lcd;

unsigned int hours = 0;
unsigned int minutes = 0;
unsigned int seconds = 0;
unsigned int setting = 0;
unsigned int set = 0;

volatile byte pulseCount;

void setup() {

// Set up the LCD's number of columns and rows:

lcd.begin(16,2);
lcd.setCursor(5,0);
lcd.print("LEETs");
lcd.setCursor(4,1);
lcd.print("academy");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Coundown Timer");
lcd.setCursor(0,1);
lcd.print("Hours =");
pulseCount = 0;

}

void loop() {

if(set == 1)
stepDown();
// Print the time on the LCD
printTime();
// Listen for buttons for 1 second
buttonListen();

}

//-----------------TIMER METHODS------------
//-----------------BUTTONS-----------------------

void buttonListen() {

// Read the buttons five times in a second
for (int i = 0; i < 5; i++) {
// Read the buttons value
int button = lcd.button();
switch (button) {
// Right button was pushed

case KEYPAD_RIGHT:
setting++;
break;

// Left button was pushed
case KEYPAD_LEFT:
setting--;
break;

// Up button was pushed
case KEYPAD_UP:
{

set = 0;
switch (setting) {
case HOURS:
hours++;
break;
case MINUTES:
minutes++;
break;
case SECONDS:
seconds++;

}

}

break;

// Down button was pushed
case KEYPAD_DOWN:{
set = 0;
switch (setting) {

case HOURS:
hours--;
if (hours == -1) hours = 23;
break;
case MINUTES:
minutes--;
if (minutes == -1) minutes = 59;
break;
case SECONDS:
seconds--;
if (seconds == -1) seconds = 59;

}

}
break;
case KEYPAD_SELECT:
{
set = 1;
}

}

setting %= 4;
printSetting();
hours%=24;
minutes %= 60;
seconds %= 60;

printTime();

// Wait one fifth of a second to complete
while(millis() % 200 != 0);

}
}

// Print the current setting
void printSetting() {

lcd.setCursor(0,1);
switch (setting) {
case HOURS:
lcd.print("Hours ");
break;
case MINUTES:
lcd.print("Minutes");
break;
case SECONDS:
lcd.print("Seconds");
}
}

//-----------------STEP DOWN------------------

//if (seconds > 0)
void stepDown()
{
if (seconds > 0)
{

seconds -= 1;
}
else if (minutes > 0)
{

seconds = 59;
minutes -= 1;
}

else if (hours > 0)
{
minutes = 59;
hours -= 1;
}

}

// Print the time on the LCD
void printTime() {

// Set the cursor at the begining of the second row
lcd.setCursor(8,1);
char time[17];
sprintf(time, "%02i:%02i:%02i", hours, minutes, seconds);
lcd.print(time);

}

void pulseCounter()
{
pulseCount++;
}

Thank you for your help.
Natha

-Select an unused digital pin
-Configure the pin as OUTPUT in the setup()
-Use digitalWrite() to turn the buzzer on and off.
-Use wires to connect the buzzer to the output pin and ground.

Hello,
I have tried to change my code:

#include <LiquidCrystal.h>
#include “LCDKeypad.h”
#define HOURS 1
#define MINUTES 2
#define SECONDS 3// The LCD screen
LCDKeypad lcd;

unsigned int hours = 0;
unsigned int minutes = 0;
unsigned int seconds = 0;
unsigned int setting = 0;
unsigned int set = 0;

volatile byte pulseCount;

void setup() {

// Set up the LCD’s number of columns and rows:

pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
lcd.begin(16,2);
lcd.setCursor(5,0);
lcd.print(“Calv’s”);
lcd.setCursor(4,1);
lcd.print(“Alarm”);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Alarm Time”);
lcd.setCursor(0,1);
lcd.print(“Hours =”);
pulseCount = 0;

}

void loop() {

if(set == 1)
stepDown();
// Print the time on the LCD
printTime();
// Listen for buttons for 1 second
buttonListen();

}

//-----------------TIMER METHODS------------
//-----------------BUTTONS-----------------------

void buttonListen() {

// Read the buttons five times in a second
for (int i = 0; i < 5; i++) {
// Read the buttons value
int button = lcd.button();
switch (button) {
// Right button was pushed

case KEYPAD_RIGHT:
setting++;
break;

// Left button was pushed
case KEYPAD_LEFT:
setting–;
break;

// Up button was pushed
case KEYPAD_UP:
{

set = 0;
switch (setting) {
case HOURS:
hours++;
break;
case MINUTES:
minutes++;
break;
case SECONDS:
seconds++;

}

}

break;

// Down button was pushed
case KEYPAD_DOWN:{
set = 0;
switch (setting) {

case HOURS:
hours–;
if (hours == -1) hours = 23;
break;
case MINUTES:
minutes–;
if (minutes == -1) minutes = 59;
break;
case SECONDS:
seconds–;
if (seconds == -1) seconds = 59;

}

}
break;
case KEYPAD_SELECT:
{
set = 1;
}

}

setting %= 4;
printSetting();
hours%=24;
minutes %= 60;
seconds %= 60;

printTime();

// Wait one fifth of a second to complete
while(millis() % 200 != 0);

}
}

// Print the current setting
void printSetting() {

lcd.setCursor(0,1);
switch (setting) {
case HOURS:
lcd.print("Hours ");
break;
case MINUTES:
lcd.print(“Minutes”);
break;
case SECONDS:
lcd.print(“Seconds”);
}
}

//-----------------STEP DOWN------------------

//if (seconds > 0)
void stepDown()
{
if (seconds > 0)
{

seconds -= 1;
}
else if (minutes > 0)
{

seconds = 59;
minutes -= 1;
}

else if (hours > 0)
{
minutes = 59;
hours -= 1;
}

}

// Print the time on the LCD
void printTime() {

// Set the cursor at the begining of the second row
lcd.setCursor(8,1);
char time[17];
sprintf(time, “%02i:%02i:%02i”, hours, minutes, seconds);
lcd.print(time);

}

void pulseCounter()
{
pulseCount++;
}
if (ahours == hours && amins == mins && amins != 0)
{
digitalWrite(9, HIGH);
delay(200);
digitalWrite(9, LOW);
delay(200);
}

}

However, I get the following error:

Arduino: 1.8.5 (Windows Vista), Board: “Arduino/Genuino Uno”

AlarmClock.h:189: error: expected unqualified-id before ‘if’

if (ahours == hours && amins == mins && amins != 0)

^

AlarmClock.h:197: error: expected declaration before ‘}’ token

}

^

exit status 1
expected unqualified-id before ‘if’

All code has to be in a function. Your if and the following lines are outside of any function. And it's not clear to me where they should be...inside loop() perhaps?

Steve

first try to use the buzzer in a separate test sketch