Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Guides
  3. ›Switches, Relays & Input
  4. ›Push Buttons with Arduino
Step 8 of 18 in Electronics from zeroPart of a learning path.
Next

How-to · Beginner · 3 min read

Push Buttons with Arduino

Pull-Ups, Debouncing and Long Press

By Geekobot Learning Team · Updated 24 Oct 2026

I'm using
Wiring, code and the Run it panels follow your board.
On this page
Short answerWiring a tactile button (no external resistor)Why buttons bounce and how to debounceDetecting long press and double pressHardware debouncing and interruptsChoosing a button for the jobTry itCommon mistakesFAQsParts and next steps
Short answer

Wire a push button between a digital pin and ground, set the pin to INPUT_PULLUP, and the pin reads LOW while pressed. Mechanical contacts bounce for a few milliseconds, so ignore changes for about 20 to 50 ms after each transition, or use a debounce library. For long-press detection, record when the button went down and check how long it has been held.

Key specs at a glance

Tactile switch
4 pins; pins on the same side are connected in pairs
Wiring
Pin to button to GND, with INPUT_PULLUP
Bounce time
Typically 1 to 20 ms
Debounce delay
20 to 50 ms in code, or a 10 kΩ + 100 nF RC filter
Panel switches
Momentary (NO/NC) or latching; rated voltage and current printed on the body
Libraries
Bounce2, OneButton, EasyButton
!Safety: Lithium cells need care

A shorted, over-charged or damaged lithium cell can get very hot and catch fire. Use a protection board or BMS, never short the terminals, charge on a non-flammable surface and do not leave a charging pack alone. Throw away cells that are swollen or dented.

01

Wiring a tactile button (no external resistor)

A 4-pin tactile switch has two pairs of legs: legs on the same side are already connected, so wire across the gap. Connect one side to the input pin and the other to GND. With pinMode(pin, INPUT_PULLUP) the internal pull-up holds the pin HIGH until the button connects it to ground. See pull-up and pull-down resistors for why this matters.

02

Why buttons bounce and how to debounce

When the contacts close, they rattle for a few milliseconds, producing several HIGH/LOW edges. Code that counts edges sees one press as two or five. Debounce by accepting a new state only after it has been stable for a short time:

Debounced button that toggles an LED · Arduino C++Verify & upload in Electrolark
const int BTN = 2;
const int LED = 13;
const unsigned long DEBOUNCE = 30;

int stable = HIGH, lastRead = HIGH;
unsigned long lastChange = 0;
bool ledOn = false;

void setup() {
  pinMode(BTN, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
}

void loop() {
  int r = digitalRead(BTN);
  if (r != lastRead) { lastChange = millis(); lastRead = r; }
  if (millis() - lastChange > DEBOUNCE && r != stable) {
    stable = r;
    if (stable == LOW) {                 // a clean press
      ledOn = !ledOn;
      digitalWrite(LED, ledOn);
    }
  }
}
03

Detecting long press and double press

Store the time when the button goes down. If it is still down after 800 ms, treat it as a long press (and remember so you do not also fire a short press on release). For double presses, note the time of each release and compare with the previous one. The OneButton library handles click, double-click and long-press callbacks and is worth using for menus.

04

Hardware debouncing and interrupts

A 10 kΩ pull-up with a 100 nF capacitor across the button smooths the bounce so even an interrupt pin sees one edge; a Schmitt-trigger buffer (74HC14) makes it bullet-proof. Use interrupts (attachInterrupt) only when the loop is too busy to poll; for most projects polling every loop pass is simpler and avoids bounce-triggered interrupt storms.

05

Choosing a button for the job

SwitchUse
6 x 6 mm or 12 x 12 mm tactileBreadboards, PCBs, menus
Panel-mount momentary (12 to 22 mm)Enclosures, user-facing buttons; often with LED ring
Latching push buttonOn/off power without code
Mushroom emergency stop (NC)Machines and robots: cuts power when pressed, wired in series with the supply
Micro / limit switchEnd-stops, lid detection
Capacitive touch (TTP223)Sealed panels, no moving parts
SwitchUse
6 x 6 mm or 12 x 12 mm tactile
Breadboards, PCBs, menus
Panel-mount momentary (12 to 22 mm)
Enclosures, user-facing buttons; often with LED ring
Latching push button
On/off power without code
Mushroom emergency stop (NC)
Machines and robots: cuts power when pressed, wired in series with the supply
Micro / limit switch
End-stops, lid detection
Capacitive touch (TTP223)
Sealed panels, no moving parts
06

Try it: RC time constant calculator

Change the values and the diagram and results update as you type.

07

Common mistakes to avoid

  • !Wiring the button to 5 V with INPUT_PULLUP, so it never changes.
  • !Using delay() for debouncing inside a loop that also drives motors or displays.
  • !Treating a bounced edge in an interrupt as multiple presses.
  • !Choosing a tactile switch for a panel and having it break off.
  • !Using a normally-open button for an emergency stop; it must be normally-closed.
08

Frequently asked questions

Do I need a resistor for a push button on Arduino?

No. Use pinMode(pin, INPUT_PULLUP) and wire the button to ground. An external 10 kΩ pull-up or pull-down works too.

Why does my button register multiple presses?

Contact bounce. Ignore changes for 20 to 50 ms after each transition in code, or add an RC filter.

How do I detect a long press?

Record millis() when the button goes down. If it stays down past your threshold (for example 800 ms), fire the long-press action and flag it so the release does not count as a short press.

Which pins of a tactile switch are connected?

Legs on the same side of the switch body are connected to each other. Wire across the body (opposite sides) so pressing closes the circuit.

Can I use a push button with an ESP32 or Pico?

Yes. Both have internal pull-ups and pull-downs. On the ESP32, avoid GPIO 34 to 39 for buttons unless you add an external resistor, since they have no internal pull-ups.

Parts for this guide

  • Tactile Push Button Switch
    ₹7View
  • Panel Mount Push Button (Momentary)
    ₹19View
  • Emergency Stop Mushroom Push Button 22mm
    ₹67View
  • Resistor Assortment Kit (30 Values)
    ₹33View
Shop Push Buttons & TactileShop Keypads & Touch

Calculators

RC time constant calculator

Terms in this guide

DebounceFiltering the rapid on-off bouncing of a mechanical switch so one press counts once.Pull-up resistorA resistor from a signal line to the supply that keeps the line high when nothing pulls it low.Floating inputAn input pin that is connected to nothing, so it picks up noise and reads random HIGH or LOW values. Fix it with a pull-up or pull-down resistor.InterruptA hardware signal that makes the microcontroller pause its program and run a short function immediately, for example when a button pin changes.Normally closedA switch or relay contact that conducts until it is pressed or energised (NC), the opposite of normally open (NO).

Projects that use it

Put this into practice: 133 step-by-step builds in our project library use parts from this guide.

Intermediate · 2–3 hoursStepper photo turntableView projectBeginner · 1 hourElectronic dice on an LED matrixView projectBeginner · 1 hourReaction timer gameView project
Browse all 133 projects

Keep learning

Concept explainerBeginnerPull-Up and Pull-Down ResistorsA pull-up resistor connects an input pin to the supply so it reads HIGH when nothing drives it; a pull-down connects it to ground so it reads LOW.3 min read · Electronics FundamentalsComponent guideBeginnerArduino UnoThe Arduino Uno is a beginner-friendly microcontroller board that reads sensors and controls LEDs, motors and relays using simple C++ programs called sketches.5 min read · Boards & MicrocontrollersComponent guideBeginnerESP32 GuideThe ESP32 is a low-cost 3.3 V microcontroller from Espressif with built-in Wi-Fi and Bluetooth, used for IoT devices, smart-home controllers and web dashboards.5 min read · Boards & MicrocontrollersComponent guideBeginnerLEDs ExplainedAn LED (light-emitting diode) lights when current flows from its longer leg (anode, +) to its shorter leg (cathode, -).3 min read · Displays & LEDsComponent guideBeginnerRelay ModulesA relay module is an electrically controlled switch that lets a microcontroller turn a separate circuit on or off, such as a 12 V pump or a mains lamp.4 min read · Switches, Relays & Input

Sources

  • Arduino Debounce tutorial (Arduino)
  • Bounce2 and OneButton library documentation
  • Omron B3F tactile switch datasheet

Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

On this page
Short answerWiring a tactile button (no external resistor)Why buttons bounce and how to debounceDetecting long press and double pressHardware debouncing and interruptsChoosing a button for the jobTry itCommon mistakesFAQsParts and next steps
Need a hand?Ask Geeko AI which part fits your project, or talk to the Geekobot team.Ask Geeko AIHelp & support

Parts for this guide4 items · ₹126

Tactile Push Button Switch · Panel Mount Push Button (Momentary) · Emergency Stop Mushroom Push Button 22mm · Resistor Assortment Kit (30 Values)

Run itChange the inputs and watch the output

A cheap button bounces for a few ms when pressed. With DEBOUNCE 0, one press can toggle the LED twice.

LED OFF
0 / 0Presses / toggles

A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.

Ask the Community

Ask a question