PLS HELP. how to decrease the volume of buzzer

I am a beginner.

The idea is when the ultrasonic sensor detects an obstacle, as the obstacles become closer the sensor the volume increases.
The code is working and my problem is 1. the sound of the piezo buzzer is very loud, i tried using earphone the sound was still the same , so how can i decrease the sound of the buzzer??
and 2. aside from that i saw codes for melody of the arduino but i don't know how to combine it with this codes.
I've been searching in the internet for how many days but i don't know what i should i do to fix this
I am using ( Us 100 Ultrasonic sensor, Piezo Buzzer (5v)/earphone , 220ohm resistor, and Gizduino v4.0 (clone of arduino uno)
I really need your help,
Thanks in advance!

#define trigPin 6
#define echoPin 7
#define buzzer 3

int sound = 10;
void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);
void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW); 
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance <= 200) {
    tone(buzzer, 1000, 20);
 sound = 10;
  else {
  if (distance < 150) {
      tone(buzzer, 728, 20);
sound = 8;
  else {
  if (distance < 125) {
      tone(buzzer, 600, 20);
      sound = 7;
  else {
  if (distance < 100) {
    tone(buzzer, 525, 20);
    sound = 5;
  else {
  if (distance < 75) {
    tone(buzzer, 400, 20);
    sound = 3;
  else {
  if (distance < 50) {
    tone(buzzer, 300, 20);
    sound = 2;
  else {
  if (distance > 200 || distance <= 0){
    Serial.println("Out of range");
  else {
    Serial.println(" cm");
    tone(buzzer, sound);

Hi, if the buzzer is the type with a hole in the front, try putting a piece of sticky tape over the hole.

Works for me.

Tom... :slight_smile:

yes, i have it in my buzzer but the volume of the sound still the same,

Thanks tom :slight_smile:

i realy need to decrease the volume of the buzzer to finish this project -_-

please help.

Hi, measure the resistance of the buzzer, then place a resistor the same value as the buzzer in series with it, see how much this drops the volume.
The more resistance to quieter the buzzer should be.
If the buzzer does not work with half the value try a value lower in resisitance.

Tom... :slight_smile:

Thanks for the idea and sorry for late reply ,
i'll try it and post for the update . :slight_smile:

Hi, measure the resistance of the buzzer, then place a resistor the same value as the buzzer in series with it.

That is going to be very difficult to measure!

The resistance is essentially infinite!

It's a piezo disc.

Start with a - oh, let's say - 10k resistor. Work up or down from there, higher resistance to soften it further.

And I was going to suggest "Blu-tac" rather than sticky tape over the hole in the piezo casing.

I'm not sure if this was the original intention but changing the pitch (tone) of the sound is vastly more useful than (trying to) change the volume in making a perceptible and estimable difference. Also that the piezo will resonate at certain frequencies and become much louder.

Hello Paul, thanks for your reply :slight_smile:

i tried to put resistors(3 pieces of 10k and 3 pieces of 1k ohms) in my breadboard to decrease the volume of the buzzer and volume of the buzzer change a little bit , so i am thinking to put more resistors to decrease the volume .. hmm so what do think..?
i really want to decrease the volume, because i am planning to change my piezo disc buzzer to earphone for my project,

the tone code i also tried to change the frequency but the sound of the buzzer is still the same, it does change the pitch of my buzzer but doesn't decrease the volume ,

Forget the 1k (unless you use a 10k in series with a 1k in parallel - 10 times division), go for 100k and step up by three to five times each try.

With an earphone, you will use totally different resistors (as the earphone is only about 30 ohms anyway).

No, the volume will not change as you change the pitch - until you find the resonant frequency at which point it will get much louder!

But different pitches can be recognised as a good indicator of proximity or whatever else you wish to indicate, whereas trying to indicate by different volumes will be nowhere near as successful.

Great Idea!
Yeah, you're right ,
thanks Paul ! :slight_smile:

i will post a comment here after i buy resistors that has higher value and put it to my project .

THANKS A LOT guys . :))) Great help!

The easiest way is to control the volume of a piezo is to use a potentiometer.

Connect one of the outer pins to your arduino drive pin, the other outer pin to ground.
The piezo is attached to the potentiometer's middle pin and ground.

You now have complete volume control from 0% to 100%

The easiest way is to control the volume of a piezo is to use a potentiometer.

The question was "buzzer", not "piezo".
Two different things.

A buzzer is a mechanical device, much like the claxon of a car.
It makes a single tone when connected to a DC voltage (+ printed on it).
Used in e.g. in barcode scanners, checkout till etc.
Not so easy to reduce the volume. Try a lower voltage, or series resistor.
Not good to make them work with a tone or PWM.

A piezo (disc) does not work with straight DC.
It needs a tone/sound/AC to work.
Commonly used in musical gift cards and toys.
Easy to control the volume with a resistor or pot.

"piezo buzzer" is confusing. It could be both.

If the visible impression of your project allows, just wrap it in soft plastic foam until you reach the audible point you wanted to achieve (and then hide it in a box .. Which will even further decrease the loudness).

You are controlling the buzzer with the tone library, so simply experiment with the frequency until it moves nearly out of your hearing range. Naturally, it could still be a misery for those with better (maybe younger ) ears. :slight_smile:

1 Like

I stumbled across this thread while looking for a way to control the volume of a speaker in software. I know it's an old thread, but I figured I would post what I tested in hardware. This is just a regular speaker that was harvested out of an old 35" CRT type TV.

I had a few 1K resistors on hand, so I figured I would give them a try to start on my breadboard. The tests were done with the resistance in series. A single 1K resistor decreased the volume so much that I could not even hear the speaker, so with my hardware, 1K was too much. Putting two 1K resistors in parallel (equiv 500 ohms) with each other (but in series with the speaker) resulted in me being able to hear the speaker, but just barely, so 500 ohms was still a bit too much. Adding a third 1K resistor in parallel to the other two resistors made it just about right my hardware, so 333 ohms worked for me.

A different speaker or using a buzzer or a piezo could give different result.

Interestingly, if I requested 30 Hz from the tone() function, it was a noticeably higher frequency than 31 Hz -- sounded closer to 2000 Hz than to 30 Hz.

See for the minimum frequency of the tone the library can handle.

Edit broken link: