⭐ Beginner ⏱️ 10 minutes

Doorbell

You make your own doorbell. Press the button and the buzzer says "ding-dong"!

First you log in for a moment. Then your project is ready right away.

🧰 What do you need?

1× Arduino UNO
1× Push button
1× Active buzzer
🔌
USB cable + Jumper wires

🗺️ Wiring diagram

Follow the wires from the Arduino to each part. You can choose the wire colors yourself.

From To
Arduino UNO · D2 Push button · 1
Push button · 2 Arduino UNO · GND
Arduino UNO · D8 Active buzzer · S
Arduino UNO · 5V Active buzzer · +
Arduino UNO · GND Active buzzer · -

🛠️ This is how you build it

  1. Put the pushbutton across the gap of the breadboard: one leg to pin 2, and a leg on the other side to GND.
  2. Connect the buzzer: S to pin 8, + to 5V and − to GND.

💻 The code

// Doorbell
// Press the button and the buzzer plays a happy "ding-dong".

const int BUTTON_PIN = 2;    // Pushbutton on pin 2 (other side to GND)
const int BUZZER_PIN = 8;  // Active buzzer: S on pin 8

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP); // Released = HIGH, pressed = LOW
  pinMode(BUZZER_PIN, OUTPUT);
}

// Let the buzzer beep for a while
void beep(int howLong) {
  digitalWrite(BUZZER_PIN, HIGH);
  delay(howLong);
  digitalWrite(BUZZER_PIN, LOW);
}

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {  // Someone presses the bell!
    beep(300);      // "Ding"
    delay(150);
    beep(600);      // "Dong"
    delay(1000);    // Wait a bit, so the bell does not keep ringing
  }
}

🧠 What does the code do?

  • The button is on pin 2 and the buzzer is on pin 8.
  • The function beep() turns the buzzer on for a moment and then off again.
  • When the button is pressed, we play a short beep and a long beep.

🎯 Try this…

  • Play a happy little tune of five beeps
  • Also make an LED blink when someone rings the bell
  • Count how many times the bell has rung and show it in the serial monitor

🚀 Build this project with Codey: open codey.online/starter-kits/uno/projects/doorbell and click MAKE THIS. Then the code and the wiring diagram are ready right away.

First you log in for a moment. Then your project is ready right away.
⬇️ Download this page as a PDF 📚 Download the complete tutorial (PDF)

Codey Online is a product of OTRONIC

Build your Arduino or ESP32 project with AI

Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.

Start for free