Part

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

See every part
  • 4 pins
  • 1 setting
  • In 110 projects
  • In 81 lessons
Drawn live by the editor's own code, at the size you see it.
At a glance

The Pushbutton in brief

What it is, and every setting the properties panel gives it.

The real part has two pairs of legs, and each pair is always one piece of metal: pins 1a and 1b are permanently joined, and so are 2a and 2b, whether the button is held or not. Pressing it is what bridges the two pairs together. That matters on a breadboard because wiring across the gap the wrong way is a genuine, common mistake, and the model carries the straps rather than pretending the part is a simple two-pin switch. It also bounces. A real tactile switch’s dome does not land once; it chatters for a few milliseconds before it settles, on both the press and the release, and this part reproduces that by default rather than closing its contact cleanly. That single detail is the whole reason a naive sketch counts one press as two or three, and it is the reason every debouncing tutorial on this site can show the problem happening rather than only describing it.

Family
Inputs
Pins
4
bounce
typical (or none, worst)
none, typical (1 to 5 ms, the small tactile switch most kits ship, the default) or worst (10 to 20 ms, a tired microswitch or a long-levered limit switch).
Pins

4 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
1a
One pair, always shorted together.
1b
One pair, always shorted together.
2a
The other pair, always shorted together.
2b
The other pair, always shorted together.
How to use it

How to use a push button with an Arduino

The simplest wiring needs no resistor: one side of the button to a digital pin, the other to GND, and pinMode(pin, INPUT_PULLUP) in setup(). The pin then reads HIGH when the button is up and LOW while it is pressed, which is backwards from what most people expect the first time. For an LED that is lit only while the button is held, digitalWrite(13, digitalRead(2) == LOW) in loop() is the whole sketch.

The four legs are two pairs. 1a and 1b are one piece of metal and 2a and 2b are another, always joined, and pressing the button bridges the two pairs. Wire one leg from each pair, 1a to the pin and 2a to GND as here. Two legs from the same pair are always connected, so the pin reads LOW whether the button is pressed or not.

To turn an LED on with one press and off with the next, the sketch watches for the moment the pin changes from HIGH to LOW, not the level, and flips the LED then. A real button bounces for a few milliseconds when it closes, and so does this one, so the sketch also ignores changes for 25 milliseconds after each one. The circuit here is that toggle, running.

Part pin
Board pin
One side (1a)
Pin 2
The other side (2a)
GND
LED, through 220 ohm
Pin 13

The same wiring works on every board here; the ESP32-C3 button example uses GPIO 9 and the Pico’s uses GP15.

Arduino Uno: a debounced togglelive0.000 s 0.00x
Hold the button
This is the simulator itself, running here. Click anything to open it in the editor.
Read the full tutorial
LED on and off with each press, from the toggle example
const int BUTTON_PIN = 2;
const int LAMP_PIN = 13;
const unsigned long DEBOUNCE_MS = 25;

int lastReading = HIGH;
unsigned long lastChange = 0;
bool lampOn = false;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(LAMP_PIN, OUTPUT);
}

void loop() {
  int reading = digitalRead(BUTTON_PIN);
  unsigned long now = millis();

  if (reading != lastReading && now - lastChange >= DEBOUNCE_MS) {
    lastChange = now;
    lastReading = reading;
    if (reading == LOW) {
      lampOn = !lampOn;
      digitalWrite(LAMP_PIN, lampOn ? HIGH : LOW);
    }
  }
}
How it is modeled

What is true about the Pushbutton, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

A tactile switch is a springy dome slapping a fixed contact: it does not close once, it closes, rebounds, closes again, and settles after a few milliseconds of chatter, on the release as well as the press, because the dome rebounds both ways. That is why a button wired straight to a counter counts several presses for one, and why every real sketch that reads a button debounces it; a simulator that closes the contact exactly once would hide the single most common reason a beginner's circuit misbehaves. The numbers come from a per-part random stream seeded from the component id, so every button bounces differently, every press bounces differently from the last, and the same circuit run twice bounces identically.

Not modeled

No mechanical click force or travel feel. This is the electrical bounce, not the tactile feedback.

The bounce is a plausible pattern, not a measured waveform. When the button is pressed, the model generates a plan: an odd number of edges (3 to 8 on typical, 11 to 20 on worst) with random gaps scaled so the last one lands exactly on a settle time drawn from the profile's window: 1 to 5 ms, or 10 to 20 ms. The numbers are representative of a small tactile switch rather than taken from any one switch's datasheet, the gaps are drawn from a seeded pseudo-random stream rather than from contact mechanics, and the first edge is always clean and immediate. A real dome's chatter is decaying rather than uniformly spread, and its contact resistance wanders during the bounce; here it is fully closed or fully open at every instant.

There is no contact resistance drift, no wetting current, no wear and no temperature.

From Pushbutton (12 mm tactile), in full.

Projects

See the Pushbutton in a project

110 built-in projects use it. Each opens in the editor, already wired.

Lessons

Where it turns up in a lesson

81 lessons place it in their own circuits.

Learn articles

78 lessons

Boards

The boards it is shown on

Each of these 9 boards has a built-in project with the Pushbutton in it.

Boards

The Pushbutton on each board

The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.

Libraries

Arduino libraries for the Pushbutton

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the Pushbutton

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.