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.


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:


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(" - ");


Arduino, Buzzer, Passive

You may also like

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

Capacitors are fundamental components in electronic circuits, and understanding how they work is crucial for anyone looking to build and design their own circuits. In this segment, we’ll explore the various kinds of capacitors you

Read More
Introduction to Capacitors and RC Circuits

The Khadas VIM1S is a high-quality yet affordable single-board computer well suited to hobbyists’ needs. While it doesn’t have the power of its siblings, such as the Edge2, it strikes a fine balance between performance

Read More
Khadas VIM1S: Unbox, Set Up, and Review