Built-in project · Arduino Uno R3

Doorbell: button on pin 2, buzzer on pin 8, on an Arduino Uno

Press the button on pin 2, held low by a 10k pull-down, and the buzzer on pin 8 plays a two-note ding-dong. The whole build, an Arduino Uno and 3 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.

Doorbell: button on pin 2, buzzer on pin 8 · Arduino Uno R3live0.000 s 0.00x
Press the button
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
// A doorbell: press the button and the buzzer plays ding-dong.
//
//   one side of the button -> 5V, the other -> pin 2 and 10k to GND
//   buzzer + -> pin 8, buzzer - -> GND
//
// The button reads HIGH while it is pressed, thanks to the 10k pull-down.
// tone() swings pin 8 at a frequency, and the buzzer turns that into a note:
// a high one, then a lower one.

const int BUTTON = 2;
const int BUZZER = 8;

void setup() {
  pinMode(BUTTON, INPUT);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: doorbell. Press the button on pin 2.");
}

void loop() {
  if (digitalRead(BUTTON) == HIGH) {
    Serial.println("ding");
    tone(BUZZER, 659, 300);
    delay(350);
    Serial.println("dong");
    tone(BUZZER, 523, 500);
    delay(800);
  }
}

Parts list

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

How it is wired

5 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.

  • Ground: Arduino Uno R3 pin GND; Resistor, 10k Ω pin 1; Piezo speaker pin 2
  • Arduino Uno R3 pin 8; Piezo speaker pin 1
  • Arduino Uno R3 pin 2; Pushbutton pin 2a
  • Arduino Uno R3 pin 5V; Pushbutton pin 1a
  • Pushbutton pin 2b; Resistor, 10k Ω pin 2

Change it and keep it

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