Pushbutton
A 12 mm tactile switch. Hold it while the simulation runs.
- 4 pins
- 1 property
Every one of its 4 pins
What it does
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.
How to use a pushbutton 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.
A real button bounces for a few milliseconds when it closes, and so does this one, so a sketch that counts presses needs a debounce: ignore changes for 20 milliseconds or so after each one. The circuit here is that fix, running.
The same wiring works on every board here; the ESP32-C3 button example uses GPIO 9 and the Pico’s uses GP15.
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
}
void loop() {
bool pressed = digitalRead(2) == LOW;
digitalWrite(13, pressed ? HIGH : LOW);
}The one property you can set
What is true about the Pushbutton, here
What is 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.
See the Pushbutton in a project
Shown here on: ESP32-C3-DevKitM-1, Arduino Uno R3, BBC micro:bit V2
Where it turns up in a lesson
In the twelve week course
- Week 3: Buttons, pull-ups and contact bounce
- Week 5: Logic gates, as real chips
- Week 11: Interrupts: events instead of polling
In a learn article
- How to Use a Breadboard: Your First Circuit
- Picking a Resistor for an LED
- Pull-Up Resistors and the Floating Input They Fix
- Debouncing a Button: Why It Fires More Than Once
- Logic Gates, and the Truth Table You Can Press
- Shifting a Byte In, One Edge at a Time
- Arduino Button Debounce: See the Bounce, Then Fix It
- How to Simulate an Arduino Project Without Hardware
- Arduino Traffic Light with a Crossing Button
- Arduino 7 Segment Display: an Electronic Die
- Arduino Buzzer and Piezo: Beeps, Notes, Metronome
- Voltage Dividers and Why They Are Bad Power Supplies
- The 555 Monostable: One Press, One Timed Pulse
- Arduino State Machine: A Four-State Reaction Game
- Flip-Flops Explained: SR Latch, D and JK Flip-Flops
- Arduino Science Fair Projects With a Real Hypothesis
- Reaction Time Science Fair Project With an Arduino
- 555 Timer Projects for a Science Fair (No Coding)
- Arduino Projects for Beginners, Each One Running
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Pushbutton
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.