Built-in project · Arduino Uno R3

A button doorbell with a lamp, no code, on an Arduino Uno

A push button, an active buzzer and an LED with its 220 ohm resistor wired to the Uno’s 5 V: hold the button and the buzzer sounds while the LED lights. The circuit the lesson solders on a perfboard. 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 About 15 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $31. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Parallel paths in a circuit
  • One switch controlling two parts
  • Why the LED needs a series resistor
  • Using the board as a power supply
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Board: Arduino Uno R3
  • Parts: 6

How it works

The 5V pin feeds one side of the button. The other side splits in two paths, side by side. One path goes to the buzzer and on to GND. The other goes through the 220 ohm resistor and the LED to GND.

Hold the button and both paths get power, so the buzzer sounds and the LED lights. Let go and both stop. The Uno is only a 5 V supply, and the sketch just prints a hello line.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
LED, red pin CArduino Uno R3 pin GND
Buzzer pin 2Arduino Uno R3 pin GND
Pushbutton pin 1aArduino Uno R3 pin 5V
Resistor, 220 Ω pin 1Pushbutton pin 2a
Buzzer pin 1Pushbutton pin 2a
LED, red pin AResistor, 220 Ω pin 2

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 with a lamp: a circuit with no code in it.
//
//   5V -> push button -> the buzzer's + leg; the buzzer's - leg -> GND
//   the button's far side also -> 220 ohm -> LED -> GND
//
// The button feeds both the buzzer and the LED, side by side, so a press
// sounds the one and lights the other. The lesson solders these parts onto a
// perfboard and powers them from a battery; the circuit is the same.
//
// Hold the button on the canvas.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: hold the button to ring");
}

void loop() {
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Starts the serial port at 9600 baud and prints one message. No pins are configured, because the button switches the parts directly.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: hold the button to ring");
}

loop sketch.ino

It is empty on purpose. The circuit does everything, so the processor has no work to do.

void loop() {
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The buzzer is silent. This project
    The buzzer has a plus and a minus leg. Pin 1 goes to the button side, and pin 2 goes to GND.
  • The LED does not light. This project
    Check its direction. The anode (A) connects to the resistor, and the cathode (C) goes to GND.
  • The input reads random HIGH and LOW when the button is not pressed. Pushbutton
    A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW.
  • The button seems always pressed, or never changes. Pushbutton
    A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected.
  • The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
    Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • The LED does not light, or it lights once and then dies. LED
    LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin.
  • A blue or white LED stays dark on 3.3 V. LED
    Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.

Change it and keep it

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