Christmas Arduino Project: an OLED Gift Gadget That Plays Jingle Bells
This Christmas Arduino project is a small desk gadget you can build in an evening and give away. A 0.96 inch OLED screen shows a Christmas picture with snow falling over it. At the same time a tiny piezo buzzer plays the chorus of Jingle Bells. Press the button and the song starts again.
It makes a good Arduino Christmas gift for a friend, a grandparent or a teacher. It is also a fun build for a class or a club, because students get to see code, pictures and sound work together. The parts usually cost somewhere around $10 to $15 in total, and less if you already own an Arduino starter kit.
Quick answer. Wire a 128x64 SSD1306 OLED to an Arduino Uno or Nano (SDA to A4, SCL to A5), a passive buzzer to D8 and a button to D2. Install Adafruit SSD1306 and Adafruit GFX. Upload the sketch below. For a bigger picture, pick one from the free Christmas OLED gallery and paste its code into the marked spot.
Parts for this Arduino Christmas gift
Most of these come in a basic Arduino starter kit. Generic modules are cheap on Amazon and AliExpress. Adafruit and SparkFun sell versions with better labels and guides.
| Part | Notes |
|---|---|
| Arduino Nano or Uno (or an ESP32 dev board) | A Nano is small enough to hide behind the screen. An ESP32 has room for long animations. |
| 0.96 inch 128x64 OLED, SSD1306, I2C | The 4-pin version (GND, VCC, SCL, SDA). White, blue or two-color screens all work. |
| Passive piezo buzzer | Must be passive to play a tune. See the note below. |
| One push button | Any small tactile button. It restarts the song. |
| Jumper wires and a small breadboard | Or solder the parts for a gift that lasts. |
| USB cable, USB power bank or phone charger | Use a data cable for uploading. A charger or power bank runs it later. |
| Optional: 100 ohm resistor | In series with the buzzer to make it a little quieter. |
| Optional: 3D printed case or stand | Makes it look like a finished gift. |
Passive or active buzzer? They look almost the same, so check before you start. An active buzzer has a small circuit inside that makes one fixed beep whenever it gets power. It cannot play different notes. A passive buzzer has no circuit inside. The Arduino has to wiggle the pin at the note's frequency, and that is what lets it play a melody. A common clue: active buzzers often have a sticker on top and a sealed back, while passive ones often show a green circuit board underneath. The surest test is the sketch itself. If you hear only one flat tone, you have an active one.
Wiring: OLED, buzzer and button
The OLED uses I2C, so it needs only two data wires plus power. The buzzer needs one pin
and ground. The button needs one pin and ground, because the sketch turns on the Arduino's
built-in pull-up resistor with INPUT_PULLUP.
| Part and pin | Arduino Uno / Nano | ESP32 DevKit |
|---|---|---|
| OLED VCC | 5V or 3.3V (check your module) | 3V3 |
| OLED GND | GND | GND |
| OLED SDA | A4 | GPIO 21 |
| OLED SCL | A5 | GPIO 22 |
| Buzzer + | D8 (optional 100 ohm resistor in series) | GPIO 25 |
| Buzzer − | GND | GND |
| Button | One leg to D2, other leg to GND | GPIO 27 and GND |
- Unplug the board from USB before you connect anything.
- Read the labels on the OLED. Some modules start with VCC and some with GND.
- Most generic OLED modules accept 5V or 3.3V. If yours says 3.3V only, use the 3.3V pin.
- Find the + mark on the buzzer, or the longer leg. That side goes to D8.
- Put the button across the middle gap of the breadboard so its two sides are not shorted.
- Check VCC and GND one more time, then plug the USB cable back in.
New to these screens? The Arduino OLED display tutorial covers the OLED wiring in more detail.
Step 1: pick a Christmas picture for the OLED
The sketch below draws its own scene: three small trees, falling snow and the words "MERRY CHRISTMAS". That works with no extra steps. If you want a richer full-screen Christmas OLED animation or picture, use the free gallery:
- Open the Christmas OLED gallery. It has 59 designs: Santa, Christmas trees, snowmen, reindeer and "Merry Christmas" lettering.
- Click Open in editor & get code under the picture you like. It opens the OLED Animation Maker on the Christmas tab with that picture loaded.
- Choose your board and the Adafruit SSD1306 library.
- Click Get Code. You get a sketch with the picture stored as a
PROGMEMbyte array. - Copy only the array, the part that starts with
const unsigned charand ends with};. You will paste it into the gift sketch in Step 3.
One 128x64 black and white picture takes 1,024 bytes of flash (128 × 64 pixels ÷ 8 pixels per byte). An Uno or Nano has 32 KB of flash, so one picture plus the song fits easily.
Want the gift to say who it is for? The free Assemble Studio has a Christmas row with a Merry Christmas + Name button. Type a name, pick a style, and the words build up pixel by pixel on the screen. These build-up animations have many frames, so a long one may need an ESP32 instead of an Uno.
Step 2: Jingle Bells on an Arduino buzzer
Jingle Bells was written by James Lord Pierpont and published in 1857. That makes the melody public domain, so you can use it freely in your project. This post uses only the notes. There are no lyrics here.
Arduino plays notes with one function:
tone(pin, frequency, duration). The frequency is in hertz (Hz), the number of
times per second the pin flips between on and off. The duration is in milliseconds. Each
musical note has its own frequency. These are the ones the sketch defines:
| Note | Frequency (Hz) | Note | Frequency (Hz) |
|---|---|---|---|
| C4 (middle C) | 262 | G4 | 392 |
| D4 | 294 | A4 | 440 |
| E4 | 330 | B4 | 494 |
| F4 | 349 | C5 | 523 |
The Jingle Bells chorus in the key of C uses only five of them: C, D, E, F and G. That is why it is such a popular first song for a Jingle Bells Arduino buzzer project. Each note also needs a length. In the sketch, every length is counted in eighth notes: 1 is an eighth, 2 a quarter, 3 a dotted quarter, 4 a half and 8 a whole note. One tempo number sets how fast all of them play.
If you want other songs, the free Arduino Buzzer Song Generator has Christmas songs like Jingle Bells, We Wish You a Merry Christmas, Silent Night and Deck the Halls ready to export as Arduino code. The Arduino buzzer songs guide explains the note format in more depth.
Step 3: the complete Christmas gift sketch
In the Arduino IDE open Tools → Manage Libraries, search for Adafruit SSD1306 and install it. Say yes when it offers to install Adafruit GFX Library as well. Then paste this sketch, select your board and port, and click Upload.
// Christmas Arduino gift: OLED picture + Jingle Bells on a buzzer
// oledanimationmaker.com
// Board: Arduino Uno / Nano (also ESP32). Libraries: Adafruit SSD1306 + Adafruit GFX
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
#if defined(ESP32)
const int BUZZER_PIN = 25;
const int BUTTON_PIN = 27;
#else
const int BUZZER_PIN = 8;
const int BUTTON_PIN = 2;
#endif
// ---------- Notes (Hz) ----------
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523
// ---------- Jingle Bells chorus (public domain, J. L. Pierpont 1857) ----------
// Lengths are in eighth notes: 1 = eighth, 2 = quarter, 3 = dotted quarter,
// 4 = half, 8 = whole
const unsigned int melody[] = {
NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
NOTE_E4, NOTE_G4, NOTE_C4, NOTE_D4, NOTE_E4,
NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
NOTE_F4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4,
NOTE_D4, NOTE_G4,
// second time, with the ending
NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
NOTE_E4, NOTE_G4, NOTE_C4, NOTE_D4, NOTE_E4,
NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
NOTE_F4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
NOTE_G4, NOTE_G4, NOTE_F4, NOTE_D4,
NOTE_C4
};
const byte beats[] = {
2, 2, 4, 2, 2, 4,
2, 2, 3, 1, 8,
2, 2, 3, 1,
2, 2, 2, 1, 1,
2, 2, 2, 2,
4, 4,
2, 2, 4, 2, 2, 4,
2, 2, 3, 1, 8,
2, 2, 3, 1,
2, 2, 2, 1, 1,
2, 2, 2, 2,
8
};
const int NOTE_COUNT = sizeof(melody) / sizeof(melody[0]);
const int TEMPO_BPM = 160; // quarter notes per minute
const unsigned long EIGHTH_MS = 30000UL / TEMPO_BPM; // one eighth note in ms
const unsigned long NOTE_GAP_MS = 30; // short silence between notes
int noteIndex = 0;
bool playing = false;
unsigned long noteStart = 0;
unsigned long noteLength = 0;
// ---------- 16x16 Christmas tree (1 = white pixel) ----------
const unsigned char tree16[] PROGMEM = {
0x01, 0x80, // .......##....... star
0x03, 0xC0, // ......####......
0x01, 0x80, // .......##.......
0x03, 0xC0, // ......####......
0x07, 0xE0, // .....######.....
0x0F, 0xF0, // ....########....
0x07, 0xE0, // .....######.....
0x0F, 0xF0, // ....########....
0x1F, 0xF8, // ...##########...
0x3F, 0xFC, // ..############..
0x1F, 0xF8, // ...##########...
0x3F, 0xFC, // ..############..
0x7F, 0xFE, // .##############.
0xFF, 0xFF, // ################
0x03, 0xC0, // ......####...... trunk
0x03, 0xC0 // ......####......
};
// ---------- OPTIONAL: full-screen picture from the gallery ----------
// 1. Get a picture at oledanimationmaker.com/oled-animations/christmas/
// 2. Paste its 1,024-byte array below, rename it to "gallery" and remove the //
// 3. Change USE_GALLERY_PICTURE from 0 to 1
#define USE_GALLERY_PICTURE 0
#if USE_GALLERY_PICTURE
// const unsigned char gallery[] PROGMEM = { ... 1024 bytes ... };
#endif
// ---------- Falling snow ----------
const int FLAKES = 18;
int flakeX[FLAKES];
int flakeY[FLAKES];
const unsigned long FRAME_MS = 50; // 20 frames per second
unsigned long lastFrame = 0;
int lastButton = HIGH;
unsigned long lastPress = 0;
void startNote(int i) {
noteLength = beats[i] * EIGHTH_MS;
tone(BUZZER_PIN, melody[i], noteLength - NOTE_GAP_MS);
noteStart = millis();
}
void startSong() {
noteIndex = 0;
playing = true;
startNote(0);
}
// Called every loop: moves to the next note when the current one is done
void updateMusic() {
if (!playing) return;
if (millis() - noteStart >= noteLength) {
noteIndex++;
if (noteIndex >= NOTE_COUNT) {
playing = false;
noTone(BUZZER_PIN);
return;
}
startNote(noteIndex);
}
}
// Button to GND, so a press reads LOW. 200 ms ignores contact bounce.
void checkButton() {
int now = digitalRead(BUTTON_PIN);
if (now == LOW && lastButton == HIGH && millis() - lastPress > 200) {
lastPress = millis();
startSong();
}
lastButton = now;
}
void drawGreeting() {
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2); // 12 x 16 pixels per letter
display.setCursor(34, 2);
display.print("MERRY");
display.setCursor(10, 22);
display.print("CHRISTMAS");
// Trees hop by one pixel on every other note while the song plays
int hop = (playing && (noteIndex % 2 == 1)) ? 1 : 0;
display.drawBitmap(4, 46 - hop, tree16, 16, 16, SSD1306_WHITE);
display.drawBitmap(56, 46, tree16, 16, 16, SSD1306_WHITE);
display.drawBitmap(108, 46 - hop, tree16, 16, 16, SSD1306_WHITE);
display.drawFastHLine(0, 63, 128, SSD1306_WHITE); // snowy ground
}
void drawSnow() {
for (int i = 0; i < FLAKES; i++) {
flakeY[i] += 1 + (i % 2); // two falling speeds
if (flakeY[i] > 63) {
flakeY[i] = 0;
flakeX[i] = random(0, 128);
}
display.drawPixel(flakeX[i], flakeY[i], SSD1306_WHITE);
}
}
void drawFrame() {
display.clearDisplay();
#if USE_GALLERY_PICTURE
display.drawBitmap(0, 0, gallery, 128, 64, SSD1306_WHITE);
#else
drawGreeting();
#endif
drawSnow();
display.display();
}
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(BUZZER_PIN, OUTPUT);
// Most modules use address 0x3C. Change it to 0x3D if the screen stays dark.
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
while (true) {}
}
randomSeed(analogRead(A0));
for (int i = 0; i < FLAKES; i++) {
flakeX[i] = random(0, 128);
flakeY[i] = random(0, 64);
}
startSong();
}
void loop() {
checkButton();
updateMusic();
if (millis() - lastFrame >= FRAME_MS) {
lastFrame = millis();
drawFrame();
}
}
When it works, you see "MERRY CHRISTMAS" in two lines, three small trees along the bottom and snow drifting down. The song starts as soon as the board powers up. The outer trees hop a little in time with the notes. When the song ends the snow keeps falling, and a press of the button plays it again.
To use a gallery picture instead, paste its array where the comment says, rename the array
to gallery, delete the // at the start of that line and change
USE_GALLERY_PICTURE to 1. The line that draws it is
display.drawBitmap(0, 0, gallery, 128, 64, SSD1306_WHITE);, and the snow still
falls on top.
How the code works
- No long delays. A
delay(500)for each note would freeze the screen until the note ends. Instead,loop()runs again and again, andmillis()tells it how much time has passed. - Music.
updateMusic()checks whether the current note's time is up. If it is, it starts the next one withtone(). The tone stops 30 ms early, which leaves a short gap so repeated notes like E E E sound separate. - Tempo.
TEMPO_BPMis the speed. At 160, an eighth note is 187 ms and a whole note is about 1.5 seconds. - Picture.
drawBitmap()copies the tree bitmap from flash to the screen buffer. Each row of the tree is two bytes, and each 1 bit is a white pixel. The comments next to the bytes show the shape. - Snow. Each flake is an x and y position. Every frame it moves down one or two pixels. At the bottom it jumps back to the top at a random x.
- Button.
INPUT_PULLUPkeeps the pin HIGH until the button connects it to ground. The sketch reacts only to the moment it goes from HIGH to LOW, and ignores new presses for 200 ms to skip contact bounce.
If you want to go further with frames and the drawing loop, the SSD1306 animation tutorial walks through it step by step.
Make it a gift
- Power. Once the code is uploaded, any USB phone charger runs it. A small USB power bank makes it portable. Some power banks switch off when the load is very small. If yours turns off after a few seconds, use a wall charger instead.
- A stand or case. A simple 3D printed stand with a window for the screen makes it look finished. For a name plate on the front, the free Text to STL tool turns any name into a printable 3D file.
- Their name on the screen. Use Assemble Studio and its Merry Christmas + Name button, then upload that sketch instead. A board with more memory, such as an ESP32, is the safer choice for long animations.
- Wrapping. Pack it in a small box with tissue paper. Add a short card: "Plug me into any USB charger. Press the button for music." Tape the cable to the box so it does not get lost.
A 45-minute classroom version
This works well as a Christmas STEM project for middle and high school. Groups of two or three can share one kit.
| Time | Activity | What students learn |
|---|---|---|
| 5 min | Show the finished gadget. Explain passive and active buzzers. | How a speaker makes sound from a fast on-off signal |
| 10 min | Wire the OLED, buzzer and button | Power, ground, I2C and digital pins |
| 10 min | Upload the sketch and listen | Libraries, setup() and loop() |
| 15 min | Change the tempo, the number of snowflakes, or the text | Variables, arrays and millis() timing |
| 5 min | Share and clean up | Explaining what each change did |
A good stretch task: ask students to write a different short tune in the two arrays, keeping the same number of entries in each.
Troubleshooting
- The screen stays blank. Change
0x3Cto0x3Dand upload again. Check that SDA and SCL are not swapped. If the OLED is a 1.3 inch module, it may be an SH1106, which needs a different library. - The buzzer is silent. Check that the + side goes to D8 (GPIO 25 on an ESP32) and the other side to GND. Remove the resistor for a quick test. Try a different pin number in
BUZZER_PINto rule out a bad wire. - You hear one flat beep, not a tune. It is an active buzzer. Swap it for a passive one.
- The song is too fast or too slow. Change
TEMPO_BPM. 120 is relaxed and 200 is lively. If notes blur together, raiseNOTE_GAP_MSto 50. - The button does nothing. Make sure the two legs you use are on opposite sides of the breadboard gap. The button must connect to GND, not 5V.
- The gallery picture looks garbled. The bytes are in the wrong format. Export again with the Adafruit SSD1306 library selected, and copy one full 1,024-byte array. A different array size means a different screen size or more than one frame.
- "gallery was not declared in this scope". You set
USE_GALLERY_PICTUREto 1 but the array line is still commented out or has another name.
For more screen problems, the blank OLED checklist goes through every common cause.
Frequently asked questions
What is a good Christmas Arduino project for beginners?
A small OLED screen that shows a Christmas picture while a buzzer plays Jingle Bells is a good first project. It needs only a few wires, no soldering if your parts have header pins, and one sketch. It also makes a nice gift.
Do I need a passive or an active buzzer to play Jingle Bells?
Use a passive piezo buzzer. The tone() function sends it a different frequency for each note. An active buzzer has its own beeper inside and only makes one fixed tone, so it cannot play a melody.
Is Jingle Bells free to use in an Arduino project?
Yes. Jingle Bells was written by James Lord Pierpont and published in 1857, so the melody is in the public domain. The sketch here uses only the notes of the chorus, no lyrics.
Can the OLED animation keep moving while the song plays?
Yes. The sketch uses millis() instead of long delay() calls. It checks the clock in every loop, starts the next note when the current one is done, and draws a new frame of snow every 50 milliseconds.
Will a Christmas picture and the song fit on an Arduino Uno or Nano?
Yes. One 128x64 picture is 1,024 bytes of flash and the melody data is about 150 bytes, so both fit easily in the 32 KB of an Uno or Nano. Long Assemble Studio animations with many frames need an ESP32.
Can I build this Christmas gift with an ESP32?
Yes. Wire the OLED SDA to GPIO 21 and SCL to GPIO 22, the buzzer to GPIO 25 and the button to GPIO 27, and power the OLED from 3.3V. The sketch picks these pins on its own when you choose an ESP32 board.
A note on testing. The sketch compiles for an Arduino Uno, a Nano and an ESP32 with the Adafruit SSD1306 and GFX libraries, but I have not run this exact sketch on hardware yet. When you build it, please check: that the song sounds right at your chosen tempo, that the snow animation stays smooth while notes change, that the button restarts the song cleanly, and that a pasted gallery picture lines up with the screen. If something is off, the troubleshooting list above is the place to start.
Sources I checked for this guide: the Adafruit SSD1306 library, the Adafruit GFX graphics guide, the Arduino tone() reference and Jingle Bells on Wikipedia for the song's history.
Related guides
- 59 free Christmas OLED pictures
- ESP32 Christmas countdown on an OLED
- Arduino buzzer songs with code
- Arduino OLED display tutorial for beginners
- How to create SSD1306 OLED animations
- Diwali Arduino project: OLED diya animation
Free tools: OLED Animation Maker for SSD1306 and SH1106 animations, Assemble Studio for name and logo animations, the Shadow Box Lamp Generator for 3D-printed shadow lamps, Text to STL for 3D-printed names and keychains, and 3MF to Web to show 3D prints on any website. New: the Image to Byte Array converter, the OLED Robot Eyes generator and the Lithophane Maker. See all tools.