Make an alarm sound using the passive buzzer 🔊

A "buzzer" is an electrical device that makes an alarm sound. It is usually used to indicate when someone has pressed a button or to give a warning sound. Buzzers come in different shapes and sizes.


In this tutorial, we will learn how to use a buzzer to make an alarm tone that works every minute as a clock alarm.


Overview


The buzzer is used in many applications to indicate the occurrence of a certain action and alert the user. For example, your computer may contain a buzzer to alert you when an error occurs.


We will use the Arduino to generate the alarm tone. The buzzer will be connected to one of the Arduino's pins. It is a very simple and easy circuit. 


Let’s see!

Getting the items


For this project you will need the following components, You can buy them form our store.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat Passive Buzzer - 5V
2 QAR
Sale Off
Voltaat Jumper Wires - Male to Female (40 Pack)
10 QAR

Wiring it up


To set up the passive buzzer in the correct way, follow the instructions below. The image demonstrates how to connect the wires between the passive buzzer and the Arduino. Once the passive buzzer and the Arduino are connected to each other, connect the Arduino to your computer using the USB cable.



Connections from the Arduino to the passive buzzer:

• Arduino GND pin → buzzer GND pin (- pin)

• Arduino pin 11 → buzzer VCC pin (+ pin)


Coding


This sketch's function is to produce an alarm tone every one minute as a clock alarm using the tone() function. This function takes three arguments: the first is the pin number to which the tone will be output; the second is the frequency of the tone in hertz; and the third is the duration in milliseconds.


In this sketch, we've used a value of 1000 for the frequency, which produces a pitch that's close to middle C on the piano.


/*
Voltaat learn (https://www.voltaat.com/pages/voltaat-learn)
Link for full tutorial: https://bit.ly/3CHRfmN

Make an alarm sound using the passive buzzer

This sketch's function is to produce an alarm tone every one minute as a clock alarm using the tone() function

Connections from the Arduino to the passive buzzer:
• Arduino GND pin → buzzer GND pin (- pin)
• Arduino pin 11 → buzzer VCC pin (+ pin)

*/


// Define the variable buzzer to Digital Output 11
const int buzzer =11;


// Commands inside void setup run once
void setup()
{

// buzzer is defined as an output
pinMode(buzzer,OUTPUT);

// Start the serial monitor at 9600 baud rate (9600 bits per second)
Serial.begin(9600);

}

// Commands inside void loop run forever
void loop()
{


// Generates a square wave of the specified frequency (1000) on a pin (buzzer)for a duration of 500 Millisecond to make a tone
tone(buzzer,1000,500);

//delay for one minute
delay(60000);

// print "Sensor Read= " to the serial monitor at the same line
Serial.println("One minute has passed, Alarm!");

// stop generating the tone
noTone(buzzer);

}

Testing it out




Now you must have correctly wired the passive buzzer to the Arduino as we explained in the wiring section, as well as uploaded the code to your Arduino board.


You may now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.



The serial monitor is a great tool that can facilitate communication between the computer and the Arduino. It can allow us to send and receive different commands as well as view information directly from the Arduino.


Now, as seen in the image below, the serial monitor displays the status of the buzzer whenever it is turned on. The state is displayed every one minute due to the delay we added in our code. You will also hear the tone that the buzzer makes every minute and lasts for half a second.


You should also make sure you have chosen the right baud rate (9600) as specified in the code.

You can do this by clicking on the drop-down menu at the bottom right corner of the output window.


Resources 


Arduino Code

Fritzing Wiring file

Related Tutorials


The ultrasonic sensor is a device that can measure distance by sending out sound waves and calculating how long it takes for them to bounce back.


A soil moisture sensor is a device that measures the amount of water in the soil. The sensor consists of two metal probes that can be inserted into the soil to measure the moisture levels.


In this tutorial, we will use the PIR sensor to send a message to your computer when someone enters your house.