Built-in project · Arduino Uno R3

Sleigh-bell doorbell on an Arduino Uno

Press the doorbell and a servo shakes a strap of real sleigh bells in time while a speaker plays the chorus of Jingle Bells. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

Build it as the Christmas Lights Kit: the parts in numbered bags and a booklet that checks every step. Free.

Sleigh-bell doorbell · Arduino Uno R3live0.000 s 0.00x
Press Run, then press the doorbell
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Sleigh-bell doorbell: press the doorbell and a servo shakes a strap of real
// sleigh bells while a speaker plays the chorus of Jingle Bells.
//
//   doorbell   pin 2 -> button -> GND   (INPUT_PULLUP, so pressed reads LOW)
//   speaker    pin 8 -> 100 ohms -> 8 ohm speaker -> GND
//   servo      PWM -> pin 9, VCC -> 5 V, GND -> GND
//              tie a short strap of sleigh bells to the horn
//
// The servo swings the bells one way on every note and back on the next, so
// they ring in time with the tune. Real bells sound better than any speaker,
// and the tune makes it obvious it is the doorbell and not a passing sleigh.
//
// The speaker is 8 ohms, which is nearly a short across a pin, so it goes
// through 100 ohms, as in the Arduino's own melody example. For a louder bell,
// drive the speaker from a small amplifier module instead.
//
// While it plays, more presses are ignored, and it rests for a moment after,
// so a visitor leaning on the button gets one chorus, not five.
//
// On the porch: an outdoor button and its wire can pick up noise, so keep the
// run short or add a 100 nF capacitor across the button. Give the servo its
// own 5 V supply with the grounds joined.
//
// Things to try. Press the doorbell. Change TEMPO_MS for a faster jingle.
// Write in the verse as a second tune and play it on every other press.

#include <Servo.h>

const int BUTTON_PIN = 2;
const int SPEAKER_PIN = 8;
const int BELLS_PIN = 9;
const int TEMPO_MS = 180;   // one beat

const int E5 = 659, F5 = 698, G5 = 784, C5 = 523, D5 = 587;

// "Jingle bells, jingle bells, jingle all the way..." as notes and beats.
const int TUNE[] = {E5, E5, E5, E5, E5, E5, E5, G5, C5, D5, E5,
                    F5, F5, F5, F5, F5, E5, E5, E5, E5, D5, D5, E5, D5, G5};
const uint8_t BEATS[] = {1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4,
                         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
const int NOTES = sizeof(TUNE) / sizeof(TUNE[0]);

Servo bells;
unsigned int rings = 0;

void jingle() {
  rings++;
  Serial.print("Ding dong, ring ");
  Serial.println(rings);
  bool left = true;
  for (int i = 0; i < NOTES; i++) {
    int ms = BEATS[i] * TEMPO_MS;
    tone(SPEAKER_PIN, TUNE[i], ms - 30);   // a short gap keeps repeated notes apart
    bells.write(left ? 60 : 120);          // shake the bells on every note
    left = !left;
    delay(ms);
  }
  noTone(SPEAKER_PIN);
  bells.write(90);
  Serial.println("Jingle done");
}

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  bells.attach(BELLS_PIN);
  bells.write(90);
  Serial.println("Sleigh-bell doorbell ready");
}

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    jingle();
    delay(1500);   // rest, so one long press is one chorus
  }
}

Parts list

6 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

6 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 9; Hobby servo pin PWM
  • Arduino Uno R3 pin 8; Resistor, 100 Ω pin 1
  • Arduino Uno R3 pin 2; Pushbutton pin 1a
  • Arduino Uno R3 pin 5V; Hobby servo pin VCC
  • Ground: Arduino Uno R3 pin GND; Pushbutton pin 2a; Speaker, 8 ohm pin 2; Hobby servo pin GND
  • Resistor, 100 Ω pin 2; Speaker, 8 ohm pin 1

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.