Electorials Electronics
Published © GPL3+

Project 016: Arduino Christmas Piezo Buzzer Project

A Christmas-themed project for 2018's festive season, featuring a piezo buzzer playing the tune of "Jingle Bells" and an Arduino.

BeginnerProtip12 minutes23,422
Project 016: Arduino Christmas Piezo Buzzer Project

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
You could use any other Arduino board as well. The Maker Uno is used in this example.
×1
Adafruit Piezo Buzzer
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
2 Male to Male Jumper Wires.
×2
Breadboard (generic)
Breadboard (generic)
×1
USB-A to B Cable
USB-A to B Cable
Depends on the Arduino.
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Schematics

Code

Arduino Christmas Piezo Buzzer Project Code

C/C++
int buzzerPin = 8;
int tempo = 200;
char notes[] = "eeeeeeegcde fffffeeeeddedg";
int duration[] = {1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};

void playTheTone(char note, int duration) {
  char notesName[] = { 'c', 'd', 'e', 'f', 'g' };
  int tones[] = { 261, 293, 329, 349, 392 };

  for (int i = 0; i <= sizeof(tones); i++) {
    if (note == notesName[i]) {
      tone(buzzerPin, tones[i], duration);
    }
  }
}

void setup() {
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  for (int i = 0; i <= sizeof(notes)-1; i++) {
    if (notes[i] == ' ') {
      delay(duration[i] * tempo);
    } else {
      playTheTone(notes[i], duration[i] * tempo);
    }
    delay((tempo*2)*duration[i]);
  }
}

Credits

Electorials Electronics
85 projects • 66 followers
I'm an electronic hobbyist interested in anything, from Arduino to drones. I plan to educate people with the content on my website.
Contact

Comments

Please log in or sign up to comment.