Buzzer not making a sound, followed tutorial exactly

Used a tutorial on arduniogetstarted, and it makes no sound. Followed it exactly. Do y'all think the problem is my parts, or the tutorial? Code:

#include "pitches.h"

const int BUTTON_PIN = 7; // Arduino pin connected to button's pin
const int BUZZER_PIN = 3; // Arduino pin connected to Buzzer's pin

// notes in the melody:
int melody[] = {
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5,
  NOTE_E5,
  NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
  NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5,
  NOTE_D5, NOTE_G5
};

// note durations: 4 = quarter note, 8 = eighth note, etc, also called tempo:
int noteDurations[] = {
  8, 8, 4,
  8, 8, 4,
  8, 8, 8, 8,
  2,
  8, 8, 8, 8,
  8, 8, 8, 16, 16,
  8, 8, 8, 8,
  4, 4
};

void setup() {
  Serial.begin(9600);                // initialize serial
  pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
}

void loop() {
  int buttonState = digitalRead(BUTTON_PIN); // read new state

  if (buttonState == LOW) { // button is pressed
    Serial.println("The button is being pressed");
    buzzer();
  }
}

void buzzer() {
  // iterate over the notes of the melody:
  int size = sizeof(noteDurations) / sizeof(int);

  for (int thisNote = 0; thisNote < size; thisNote++) {
    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(BUZZER_PIN, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(BUZZER_PIN);
  }
}

Schematic:

If you followed it exactly, and it doesn't work, then the tutorial is wrong. More likely you changed something. How about giving us a chance to look for differences? Post images of your hardware.

IMG_20220913_142125
Took picture with chromebook camera so kinda hard to line up

yeah, thanks for the effort but that doesn't work. Need to see the proto board up close. Can't you lift it up?

One thing. Your piezo looks like an active buzzer. Not a passive transducer. Big difference. Let's have a better look at that, too. Or a link to the identical device.

IMG_20220913_142633

IMG_20220913_143249

Thanks. Is there any (+) label on the pin side of the piezo?

Yeah.

Hi,
Have you connected the buzzer (beeper) directly to 5V to see if it works?

Tom... :smiley: :+1: :coffee: :australia:

Connect (+) to 5V, the other pin to ground. Cover your ears. This is an active buzzer, not the passive transducer (speaker) that you need.

Please check the button direction on breadboard and what is showed on serial monitor when button is pressed

Show the bottom of the buzzer. If it has a green PCB, then it is a passive buzzer (what you want). Otherwise, get one here.

This may be redundant but an active buzzer will make noise when you connect it to 5VDC but won't work properly, and it MAY not work at all, connected to an output pin.

A passive piezo transducer might make a little click when you connect 5V and another click when you disconnect it, but there will be no tone.

Do you see the 'button pressed" message on the serial monitor? Most of these buttons have 4 connections and they have to be wired correctly.

You can also make a simple little test program with tone(2000); and no check for a button push.

Yeah theres no green, only a bit of blue and grey.

Have a DMM? The passive will appear almost infinite ohms. Not the active one.

Nope, don't have a DMM

Have you not done the other tests that were suggested? :frowning:

Yeah, I have. According to tinkerer9's mine is a passive. Your connecting it to 5V and Ground made it have no sound, same with TomGeorge's

I don't think you can depend on PCB colour. Those can be chosen randomly by the manufacturer. When you powered it from 5V were you careful about the polarity? Can you describe how you performed that test?

I connected two male to female wires into 5V and Ground, connected them to the buzzer, and uploaded a buzzer melody code I did a while ago.