Jingle Bells Song Using Buzzer! 🎄🔔🎅

Introduction

One of the most fun ways to learn about frequencies and timing in electronics is by making music. In this project, we are going to use an Arduino and a simple Piezo Buzzer to play the classic "Jingle Bells" holiday song. This project is excellent for beginners because it introduces the concept of PWM (Pulse Width Modulation) and array-based programming.




How a Piezo Buzzer Creates Sound

A Piezo buzzer works on the principle of the piezoelectric effect. Inside the plastic housing is a ceramic disk. When the Arduino sends an electrical signal to the buzzer, the disk vibrates. The faster it vibrates, the higher the "pitch" or "note" we hear.
In Arduino, we use the tone() function to control this vibration. For example, the note Middle C is created by vibrating the buzzer at 262 Hertz (Hz). By timing these vibrations correctly, we can create a melody.



Required Components

  • Arduino Uno, Nano, or Mega
  • Active or Passive Piezo Buzzer (Passive is better for melodies)
  • 100 Ohm Resistor (Optional, to lower the volume)
  • Jumper Wires and Breadboard



The Circuit Connections

The wiring for this project is the simplest of all Arduino projects. You only need two wires.

  • Positive Pin (+): Connect to Arduino Digital Pin 8.
  • Negative Pin (-): Connect to Arduino GND.





Detailed Code Explanation

  1. The #define Constants: We define the frequencies for each note. For example, NOTE_E4 is set to 330. This makes the code much easier to read than just using numbers.
  2. The melody[] Array: This list contains the sequence of notes for the song. You can see the "E, E, E" pattern at the start, which corresponds to the "Jin-gle bells" lyrics.

  3. The noteDurations[] Array: Music isn't just about notes; it's about timing. A value of 4 represents a quarter note, while 1 represents a whole note (a long sound).

  4. The tone() Function: This is the most important command. It takes three arguments: (pin, frequency, duration).

  5. The pauseBetweenNotes: Without this, the notes would blend together into one long noise. Multiplying by 1.30 ensures there is a tiny gap of silence between each beep, making it sound like music.

CODE

       /* MERRY CHRISTMAS GUYS !*/

int tonePin = 13; /// Busser port
void setup() {

}

void midi() {

    tone(tonePin, 293, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 391, 225.0);
    delay(250.0);
    tone(tonePin, 293, 450.0);
    delay(500.0);
    delay(250.0);
    tone(tonePin, 293, 225.0);
    delay(250.0);
    tone(tonePin, 293, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 391, 225.0);
    delay(250.0);
    tone(tonePin, 329, 450.0);
    delay(500.0);
    delay(250.0);
    tone(tonePin, 329, 225.0);
    delay(250.0);
    tone(tonePin, 329, 225.0);
    delay(250.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 587, 450.0);
    delay(500.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 659, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 493, 675.0);
    delay(750.0);
    tone(tonePin, 293, 225.0);
    delay(250.0);
    tone(tonePin, 293, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 391, 225.0);
    delay(250.0);
    tone(tonePin, 293, 450.0);
    delay(500.0);
    delay(250.0);
    tone(tonePin, 293, 225.0);
    delay(250.0);
    tone(tonePin, 293, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 391, 225.0);
    delay(250.0);
    tone(tonePin, 329, 450.0);
    delay(500.0);
    delay(250.0);
    tone(tonePin, 329, 225.0);
    delay(250.0);
    tone(tonePin, 329, 225.0);
    delay(250.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 659, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 391, 450.0);
    delay(500.0);
    tone(tonePin, 587, 450.0);
    delay(500.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 450.0);
    delay(500.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 450.0);
    delay(500.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 391, 337.5);
    delay(375.0);
    tone(tonePin, 440, 112.5);
    delay(125.0);
    tone(tonePin, 493, 450.0);
    delay(500.0);
    delay(500.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 523, 337.5);
    delay(375.0);
    tone(tonePin, 523, 112.5);
    delay(125.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 112.5);
    delay(125.0);
    tone(tonePin, 493, 112.5);
    delay(125.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 440, 450.0);
    delay(500.0);
    tone(tonePin, 587, 450.0);
    delay(500.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 450.0);
    delay(500.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 450.0);
    delay(500.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 391, 337.5);
    delay(375.0);
    tone(tonePin, 440, 112.5);
    delay(125.0);
    tone(tonePin, 493, 450.0);
    delay(500.0);
    delay(500.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 523, 337.5);
    delay(375.0);
    tone(tonePin, 523, 112.5);
    delay(125.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 225.0);
    delay(250.0);
    tone(tonePin, 493, 112.5);
    delay(125.0);
    tone(tonePin, 493, 112.5);
    delay(125.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 587, 225.0);
    delay(250.0);
    tone(tonePin, 523, 225.0);
    delay(250.0);
    tone(tonePin, 440, 225.0);
    delay(250.0);
    tone(tonePin, 391, 675.0);
    delay(750.0);
}

void loop() {
    // Play midi
    midi();
}

Troubleshooting: Common Buzzer Problems

1. The sound is very quiet or "clicking"

Buzzer Type: You might be using an "Active" buzzer. Active buzzers only play one constant beep. For melodies, you need a Passive buzzer.

Connection: Ensure the positive pin is in Pin 8 and the GND pin is secure.

2. The song plays too fast or too slow

The Math: The line int noteDuration = 1000 / noteDurations[thisNote]; controls the speed. If you want the song faster, change 1000 to 800. If you want it slower, change it to 1200.

3. Error: "NOTE_E4 was not declared"

Check the defines: Make sure you didn't delete the #define lines at the top of the code. These tell the Arduino what the notes mean.

Conclusion

Creating music with Arduino is a fantastic way to understand how software controls hardware. Once you master "Jingle Bells," you can search for "Arduino Music Pitch" tables online and program any song you like, from Star Wars to Happy Birthday!

Post a Comment

Post a Comment (0)

Previous Post Next Post