Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Piezo Buzzer - Generating Sound with Arduino

The Importance and Utility of Piezo Buzzers

Piezo buzzers are small electronic devices that can generate sound using the piezoelectric effect. These buzzers are commonly used in various electronic projects and applications, such as alarms, notifications, musical instruments, and interactive systems. Understanding how to use and control piezo buzzers with Arduino can greatly enhance the capabilities of your projects and allow you to create engaging and interactive experiences.

Project: Creating a Simple Melody Player

In this example project, we will create a simple melody player using an Arduino and a piezo buzzer. The objective is to play a sequence of musical notes and demonstrate how to control the pitch and duration of each note.

List of Components:

Examples:

Example 1: Playing a Single Note

int buzzerPin = 9; // Connect the piezo buzzer to digital pin 9

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

void loop() {
  tone(buzzerPin, 440); // Play a 440Hz tone on the buzzer for 1 second
  delay(1000); // Pause for 1 second before playing the next note
  noTone(buzzerPin); // Stop the buzzer
  delay(1000); // Pause for 1 second before playing the next note
}

Example 2: Playing a Melody

int buzzerPin = 9; // Connect the piezo buzzer to digital pin 9

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

void loop() {
  int melody[] = {262, 294, 330, 349, 392, 440, 494}; // Define the melody notes
  int duration = 500; // Define the duration of each note in milliseconds

  for (int i = 0; i < 7; i++) {
    tone(buzzerPin, melody[i], duration); // Play each note in the melody
    delay(duration); // Pause for the duration of the note
    noTone(buzzerPin); // Stop the buzzer
    delay(100); // Pause between each note
  }
}

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.