Buzzer producing quiet whirring noise instead of buzzing

I am trying to use the ezBuzzer library to play a melody using a buzzer module, but instead there’s just a very very faint whirring noise. I have triple checked that VCC connects to 5V (I have also tried 3V), that GND connects to ground and that IO connects to D8. At one point it worked fine but I no longer have access to the code I used to see what’s different.

Here’s the relevant code:

#include <ezBuzzer.h>

ezBuzzer buzzer(8);
int knife[] = {
  NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, 0, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1 
};
int knifeLength[] = {
  24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 20
};
int noteLength;

void setup() {
  noteLength = sizeof(knifeLength) / sizeof(int);
}

void loop() {
  if (buzzer.getState() == BUZZER_IDLE) {
    Serial.print("how alarming");
    Serial.print(buzzer.getState());
    buzzer.playMelody(knife, knifeLength, noteLength);
  }
}

The full script is much longer, but it’s possible that the issue is somewhere there so I have made it collapsible

Full script
// Controller for Buttons, Buzzer and I2C

#include <Wire.h>
#include <ezBuzzer.h>

// Buttons
#define Button1 2
#define Button2 4
#define Button3 6

int button1State = 0;
int button2State = 0;
int button3State = 0;

bool button1Trigger = false;
bool button2Trigger = false;
bool button3Trigger = false;

#define Button4 0
#define Button5 2
#define Button6 6

int button4State = 0;
int button5State = 0;
int button6State = 0;

bool button4Trigger = false;
bool button5Trigger = false;
bool button6Trigger = false;

// Buzzer sounds
ezBuzzer buzzer(8);
int knife[] = {
  NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, 0, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1 
};
int knifeLength[] = {
  24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 20
};
int noteLength;

void setup() {
  // Set up buttons
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
  pinMode(Button3, INPUT);
  pinMode(Button4, INPUT);
  pinMode(Button5, INPUT);
  pinMode(Button6, INPUT);

// Does this
  noteLength = sizeof(knifeLength) / sizeof(int);
// Start I2C
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  // Read buttons
  button1State = digitalRead(Button1);
  button2State = digitalRead(Button2);
  button3State = digitalRead(Button3);
  button4State = analogRead(Button4);
  button5State = analogRead(Button5);
  button6State = analogRead(Button6);

  // Serial.print(button1Trigger, "\n");
  // button 1 data sender
  if (button1State == 1 and not button1Trigger) {
    Wire.beginTransmission(9);
    Wire.write(10);
    Wire.endTransmission();
    button1Trigger = true;
  } else if (button1State == 0 and button1Trigger) {
    Wire.beginTransmission(9);
    Wire.write(1);
    Wire.endTransmission();
    button1Trigger = false;
  }
  // button 2 data sender
  if (button2State == 1 and not button2Trigger) {
    Wire.beginTransmission(9);
    Wire.write(20);
    Wire.endTransmission();
    button2Trigger = true;
  } else if (button2State == 0 and button2Trigger) {
    Wire.beginTransmission(9);
    Wire.write(2);
    Wire.endTransmission();
    button2Trigger = false;
  }
  // button 3 data sender
  if (button3State == 1 and not button3Trigger) {
    Wire.beginTransmission(11);
    Wire.write(30);
    Wire.endTransmission();
    button3Trigger = true;
  } else if (button3State == 0 and button3Trigger) {
    Wire.beginTransmission(11);
    Wire.write(3);
    Wire.endTransmission();
    button3Trigger = false;
  }
  // button 4 data sender
  if (button4State >= 30 and not button4Trigger) {
    Wire.beginTransmission(11);
    Wire.write(40);
    Wire.endTransmission();
    button4Trigger = true;
  } else if (button1State <= 30 and button4Trigger) {
    Wire.beginTransmission(11);
    Wire.write(4);
    Wire.endTransmission();
    button4Trigger = false;
  }

  // if (button5State >= 30 and button6State <= 30 and buzzer.getState() == BUZZER_IDLE) {
  if (buzzer.getState() == BUZZER_IDLE) {
    Serial.print("how alarming");
    Serial.print(buzzer.getState());
    buzzer.playMelody(knife, knifeLength, noteLength);
  }
}

I am using an Arduino Nano if that helps.

There are different types of buzzers, and some are not designed to play melodies.

Please post a link to the buzzer product page or data sheet, and a pic of a hand-drawn wiring diagram, with all pins, parts and connections clearly labeled.

1 Like

If your buzzer has a + sign molded onto the cover, it is an active buzzer with electronics inside that only make a single tone when powered.

1 Like

Hi, @samuraidestroy

If you connect your buzzer to 5V and gnd, does it make a noise?

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

It’s not an active buzzer and as I said it worked in the past with different code

Does my explanation of the wiring in the post not do the job? Anyway I can’t make a diagram of all of the parts in the project, including the ones that have nothing to do with the buzzer since I’m using the Grove Shield for Arduino Nano to connect my other components.

Nope, it only makes noise when VCC, GND and IO are connected to the Arduino

Then undo whatever you did to break it.

Unless you provide the requested information, don't expect much help from this forum.

Post a link to product description as requested.

I can’t find it, it was just some random pack of buzzer modules I found on amazon.

Did you set pin 8 to OUTPUT?

It isn’t necessary on account of the

ezBuzzer buzzer(8);

Where are the notes defined?

They’re predefined by the ezBuzzer library

Normally, passive buzzers have only 2 terminals.

I remember a previous question on the forum about a buzzer module with 3 pins. I think this turned out to be an active buzzer and it was not possible to play a melody using it.

Please post a photo of the front and back of the module.

I said before that I got this exact buzzer to play a melody in the past, but the code I used then is now lost

It says active low so I'm going to guess that's a PNP transistor driver so maybe it would make sense to try a simple sketch using tone() to see if you can get anything out of it at all. Don't know if <5mA GPIO current is okay for a Nano Matter.

I don't know how you did that.

But other articles describe this as a "passive" buzzer and recommend using tone()

The buzzer is "passive" with a transistor driver, presumably to protect the port pin.

The schematic is on line:

It should work fine with the Arduino tone() function.

On the other hand, the ezBuzzer library does not claim to support the Nano Matter.

Try the tone() function by itself, and see if that makes the buzzer buzz.

Whoops, that was a mistake on my part, I meant to just say Nano but since I was recently working with Nano Matters I accidentally typed Matter alongside it

So exactly what sort of nano do you have? Is it a clone or a genuine Arduino product?

If it is a clone then what sort of clone? Does it have a big chip on the back? Can you see the markings on this chip?

I added a

buzzer.beep(5);

to my loop() and nothing changed

It is a clone, the PCB is black and on the underside it says TENSTAR ROBOT

The board looks entirely the same as a normal Nano aside from PCB colour