Passive Buzzer Module

The Passive Buzzer module is a basic but versatile component that can produce sound when connected to an Arduino. Unlike an active buzzer, a passive buzzer requires an external signal to produce sound. In this step-by-step guide, we’ll show you how to set up the Passive Buzzer module with an Arduino and create projects that generate different sounds and melodies.

Materials Needed:

  1. Arduino board (e.g., Arduino Uno, Arduino Nano)
  2. Passive Buzzer module
  3. Breadboard and jumper wires
  4. USB cable for Arduino
  5. Computer with the Arduino IDE installed (https://www.arduino.cc/en/software)

Step 1: Wiring

Connect the Passive Buzzer module to the Arduino board as follows:

  • Connect the positive terminal (+) of the Passive Buzzer to a digital pin on the Arduino (e.g., D3).
  • Connect the negative terminal (-) of the Passive Buzzer to the GND pin on the Arduino.

Step 2: Arduino Code

Open the Arduino IDE and create a new sketch. Then, enter the following code:

const int buzzerPin = 3; // Digital pin connected to the Passive Buzzer module

void setup() {
  pinMode(buzzerPin, OUTPUT); // Set the Buzzer pin as OUTPUT
}

void loop() {
  // Call the function to play different sounds or melodies
  playSound(); 
  delay(1000); // Wait for 1 second before playing the sound again
}

// Function to play a sound or melody
void playSound() {
  // Example: Playing a simple melody (Twinkle Twinkle Little Star)
  int melody[] = {  // Notes of the melody (pitches)
    262, 262, 392, 392, 440, 440, 392,
    349, 349, 330, 330, 294, 294, 262
  };
  
  int noteDuration[] = { // Duration of each note (milliseconds)
    200, 200, 200, 200, 200, 200, 400,
    200, 200, 200, 200, 200, 200, 400
  };

  for (int i = 0; i < 14; i++) {
    if (melody[i] == 0) {
      noTone(buzzerPin); // Turn off the buzzer if there's no note
    } else {
      tone(buzzerPin, melody[i], noteDuration[i]); // Play the note
    }
    delay(noteDuration[i] * 1.30); // Pause between notes to avoid overlapping
  }
  noTone(buzzerPin); // Ensure the buzzer is off at the end
}

Step 3: Uploading the code

Connect your Arduino board to the computer using the USB cable and select the appropriate board and port from the Arduino IDE. Then, click the “Upload” button to upload the code to the Arduino.

Step 4: Enjoy the Melody!

Once the code is uploaded successfully, the Passive Buzzer module will play the specified sound or melody (e.g., “Twinkle Twinkle Little Star”) repeatedly. You should hear the familiar tune coming from the buzzer.

Step 5: Experiment and Create

Now that you have the Passive Buzzer module working, you can experiment with different melodies, tones, and durations to create your own musical sequences. Try using different arrays of notes and note durations to produce custom tunes or even sound effects for your projects.

Congratulations! You’ve successfully set up and used the Passive Buzzer module with Arduino. This versatile module allows you to add sound and melodies to your projects, opening up a world of possibilities for creating musical instruments, sound notifications, and more. Have fun experimenting and incorporating the Passive Buzzer module into your Arduino projects to express sound creatively!

2 Comments
  1. Jules Fitzpatrick 6 months ago

    What is “noTone” ?

    • Author
      admin 3 weeks ago

      In the code, noTone() is an Arduino function that stops the generation of sound on a specified pin. It effectively silences the buzzer by turning off the square wave signal that the tone() function generates.

Leave a reply

Your email address will not be published. Required fields are marked *

*

or

Log in with your credentials

Forgot your details?