Piezo Buzzer w/ Potentiometer

So my problem is that for a project I am working on I want to be able to control the “loudness” of my Piezo Buzzer with a potentiometer. I tried doing this both in the code and trying to route the potentiometer through the GND line for the piezo. I am using the pitches.h library for my notes to play music. I am using a Mega 2560 board for this.

Note: All of my code has been taken and modified from the SIK Guidebook (SparkFun Inventors Kit)
Note 2: Please use very simple terms I am very new to this.
Note 3: If you need any extra information then feel free to ask.

Piezo_Element.ino (776 Bytes)

pitches.h (1.95 KB)

Is it a buzzer or a speaker?

A small Buzzer.

A buzzer makes a sound when voltage is applied to it all by itself. A speaker makes a sound by sending pulses to it and these can be varied for different tones. Confirm this is a buzzer the or a speaker.

What is the resistance of the piezo?

A buzzer with 8ohm Resistance

I just edited the code to incorporate the Serial.print function so I can start to debug in some places (still figuring it out). I am also getting ready to add a Servo motor to the Code.


#include "pitches.h"
const int buzzerPin = 12;
const int songLength = 10;
int note[] = {NOTE_D2, NOTE_E2, NOTE_FS2, NOTE_G2, NOTE_A2, ' ', NOTE_B2, NOTE_C3, NOTE_D3, ' '};
int beat[] = {4, 4, 4, 4, 4, 8, 4, 4, 4, 8};
int tempo = 150;

//int sensorPin = 0;

void setup()
  pinMode(buzzerPin, OUTPUT);

void loop()
  int i, duration;
  for (i = 0; i < songLength; i++)
    duration = beat[i] * tempo;
    if (note[i] == ' ')
      tone(buzzerPin, note[i], duration);
    delay(tempo / 10);

//void loop_2()
//int sensorValue;
//sensorValue = analogRead(sensorPin);
//digitalWrite(buzzerPin, HIGH);
//digitalWrite(buzzerPin, LOW);


void loop_3() {

Is there a plus sign + on one of the piezo pins?

Place a 120 ohm resistor in series with the piezo. Power the two with 5 volts. Does the piezo make any sound with just 5 volts applied?

Next place the piezo with series resitor on a digital output and use tone(pin, 3400) on the pin. Do you hear the tone?

Series Resistor?


I don't have anything less than a 560 ohm resistor. I will have to be visiting the store soon I guess.

Or put two in parallel, 280 ohm. 4 in parallel, 140 ohm. Or just order a bunch of values from dipmicro.com