Pushbutton
A 12 mm tactile switch. Hold it while the simulation runs.
- 4 pins
- 1 setting
- In 110 projects
- In 81 lessons
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).
4 pins
Named as the editor names them, so a wire lands where you expect 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.
The same wiring works on every board here; the ESP32-C3 button example uses GPIO 9 and the Pico’s uses GP15.
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);
}
}
}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.
See the Pushbutton in a project
110 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
81 lessons place it in their own circuits.
The twelve week course
3 lessons
Learn articles
78 lessons
- 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 Code with a Pedestrian 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
- "Was Not Declared in This Scope" in Arduino: 6 Fixes
- Arduino "expected ';' before" and Similar Errors
- Wemos D1 R32 Pinout: Uno Names to ESP32 GPIOs
- Arduino Functions: Write It Once, Call It Anywhere
- Arduino Random Numbers: random() and randomSeed()
- Arduino switch case: Modes, Menus and break
- Arduino if else: One Branch Runs, and Why
- Arduino while Loop: Wait, Repeat, Break Out
- Arduino digitalRead(): Buttons, HIGH and LOW
- Arduino Data Types: int, long, float and byte
- Arduino const vs #define: Which One to Use
- Arduino Struct: Group Values, With Examples
- Arduino enum: Named States, enum class and Switch
- Arduino Timer Interrupt: Timer1 Every Second
- Arduino Watchdog Timer: Reset a Stuck Sketch
- Arduino Button Counter: Count Presses, Not Bounces
- Arduino AI Assistant in Your Browser: Meet Mokxi AI
- Fix Arduino Code With AI, and Know It Compiles
- ChatGPT for Arduino Code, and an AI That Compiles
- ESP32 Interrupts: attachInterrupt and Debounce
- Arduino Multitasking With millis(), Step by Step
- Fix "lvalue required as left operand of assignment"
- Prototype Your Keyboard Matrix Before You Solder
- DIY Rhythm Game Controller: Guitar and Dance Pad
- DIY Stream Deck and Camera Slider With Arduino
- Arduino Eurorack CV Quantizer With a PWM DAC
- Arduino nRF24L01: Wiring, Code and a Radio Doorbell
- Arduino IR Transmitter: Laser Tag With Two Nanos
- Arduino TM1637 Display: Library and Countdown
- Arduino PCF8574 and MCP23017 I/O Expanders
- Arduino DS1302 RTC: an Alarm Clock With Code
- Arduino E-Paper Display: GxEPD2 on a 2.9 Inch Panel
- Arduino Thermal Printer: Wiring, Code and Barcodes
- Arduino ACS712 Current Sensor: Wiring and Code
- Arduino Laser Module (KY-008): Wiring and Code
- Arduino pinMode(): OUTPUT, INPUT and INPUT_PULLUP
- Arduino Interrupts: attachInterrupt on Pin 2 and 3
- Arduino millis(): Timers and Multiple Tasks
- AccelStepper Arduino Library: Examples and Homing
- Stepper Motor Vibrating but Not Turning: Fixes
- "Does Not Name a Type" Arduino Error: How to Fix It
- Arduino "Redefinition of void setup()": Fixes
- Arduino "control reaches end of non-void function"
- Arduino "call of overloaded is ambiguous": Fixes
- Arduino INA219: Current Sensor Library and Code
- Export a Circuit to a KiCad Schematic
- Follow Your Arduino Starter Kit in the Browser
- Digital Logic Lab Experiments, Graded in the Browser
- Microcontroller Lab Experiments With No Kits
- Free Arduino Simulator for Students, in the Browser
- Arduino Practical Exam Practice: Ten Timed Tasks
- Raspberry Pi Pico Button: Wiring and Code
- Arduino Holiday Projects for Every Celebration
- Arduino Simon Says Game: Four LEDs, Four Buttons
- Arduino Whack-a-Mole Game: LEDs, Buttons, Score
- Arduino Game Projects You Can Play in Your Browser
- STEM Club Ideas: Electronics and Coding Sessions
- Wokwi Alternatives for Arduino and ESP32, Compared
- Best Logic Gate Simulator: Free Tools Compared
The boards it is shown on
Each of these 9 boards has a built-in project with the Pushbutton in it.
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.
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.