.st0{fill:#FFFFFF;}

Arduino

Arduino basics – How to use the passive buzzer 

 March 22, 2018

By  Peter

Join Our Mailing List

We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community.

One email per week, no spam, unsubscribe at any time.

A buzzer is a device that can generate simple tones, typically used to provide audible feedback to the user. Buzzers are used in alarm clocks, keypads, many household appliances and simple toys.

To show you how a buzzer works with the Arduino, let’s do a little experiment. If you have played with an LED following the instructions from the blog post “Arduino basics – how to use a potentiometer” (link to this post), then this experiment will look familiar.

What we’ll do here, is to control the tone of the sound emitted by a buzzer using the same potentiometer. We’ll just replace the LED with the buzzer.

Assembly

The schematic diagram below show the circuit we’ll make:

We will need:

  • An Arduino Uno,
  • A passive buzzer,
  • 7 jumper wires.

We’ll use digital pin 11 to generate Pulse Width Modulation (PWD) pulses that depend on the voltage measured at analog pin 0. This is the voltage controlled by the potentiometer.

As the potentiometer generates a higher voltage, the pulses in digital pin 11 have a longer duty cycle and trigger the buzzer to generate a louder, higher pitch sound. When the potentiometer generates a lower voltage, pin 11 generates a shorter duty cycle pulse which makes the buzzer generate a softer, lower pitch sound.

And here’s the assembled circuit:

Sketch

Copy the sketch to your Arduino IDE:

int potentiometerPin = 0;
int ledPin = 11;
int potentiometerVal = 0;
void setup()
{
	Serial.begin(9600); // setup serial
}
void loop()
{
	potentiometerVal = analogRead(potentiometerPin);
//I use the map function because PWM pins can only accept
//values from 0 to 255. Analog pins can output values from
//0 to 1023. With the map function, the range 0-1023 is
//converted to appropriate values from 0 to 255.
	int mappedVal = map(potentiometerVal,0,1023,0,255);
	Serial.print(potentiometerVal);
	Serial.print(" - ");
	Serial.println(mappedVal);
	analogWrite(ledPin,mappedVal);
	delay(10);
}

Tags

Arduino, Buzzer, Passive


You may also like

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

I’m thrilled to announce that my upcoming course, Introduction to Electronics, is just a few weeks away from being released on both Udemy and Tech Explorations. This course was designed with the absolute beginner in

Read More
New Course Coming soon: Introduction to Electronics

Robotics is one of the most engaging and effective ways to teach programming, problem-solving, and critical thinking. Today, we’re diving into the CrowBot Bolt, a programmable robot car explicitly designed for STEAM (Science, Technology, Engineering,

Read More
Exploring the CrowBot Bolt: A Hands-On Robotics Kit for STEAM Education