Push button
Wire a push button with no resistor and make your project react while it’s pressed.
A push button connects its two sides only while you hold it down. Use one to start a light show, ring a doorbell flasher or open a servo gate.
In ArduinoStudio you add a Button block and put a Check right after it. The Check decides whether the rest of the sequence runs. It works in the simulator and over USB direct in Chrome, so you don’t need the desktop app. Through the Bridge it is limited for now: see the questions below.
Wiring
| From | Through | To |
|---|---|---|
| Arduino pin 13 | 220 Ω resistor | Feedback LED long leg (anode) |
| Arduino GND | — | Feedback LED short leg (cathode) |
| Arduino GND | — | Push button leg B |
| Arduino pin 2 | — | Push button leg A |
There is no pull-up or pull-down resistor. ArduinoStudio turns on the board’s internal pull-up, so pin 2 reads 1 when the button is released and 0 when it’s pressed. The only resistor is the 220 Ω in series with the LED. You can skip the LED and watch the Uno’s on-board LED on pin 13 instead.
Block settings
| Setting | New block starts at | In the settings panel |
|---|---|---|
| Digital pin | 2 | Editable |
Step by step
- Wire the button
Put the button across the breadboard’s centre gap. Wire one leg to pin 2 and the diagonally opposite leg to GND. For feedback, add an LED on pin 13 through 220 Ω, or use the on-board LED.
- Add the Button block
Click + on the sequence, open the Components tab, open Inputs and choose Button. Digital pin is already 2.
- Add a Check
Click + after the Button, open the Actions tab and add Check. Keep its defaults (If =, To On/Off, Choose on). Together they mean “continue only if the button is pressed right now.”
- Add the LED blocks
After the Check, add a Standard LED (open LED and choose Standard) with Digital pin 13 and Off/On on. Then add a Wait of 500 ms and a second Standard LED on pin 13 with Off/On off.
- Turn on Infinity Loop
Right-click the sequence name (long-press on a touchscreen) and tick Infinity Loop. A Check reads the button once, at the moment the sequence reaches it, and the loop reads it again every cycle. Without the loop, one unpressed reading ends the run.
- Try it in the simulator
Press Play with no board connected. The Virtual Board lists pin 2 as INPUT_PULLUP with a toggle reading 1 (released). Click it to 0 (pressed): the Check shows PASS and the LED blocks run. Click it back to 1 and each pass stops at FAIL.
- Run it on the board
Plug in the board, click USB direct in the toolbar, press Connect on the USB direct row, pick the board and press Play. Hold the button: while it’s held, the LED lights for half a second on every pass. If the board doesn’t show up, see Getting started.
Mini-project: doorbell flasher
Press the button and the LED flashes three times. With Infinity Loop on, every pass that finds the button still pressed flashes another three, so let go once it starts. The wiring stays exactly as above. Build one sequence and turn on Infinity Loop.
- Read the button
Add a Button block on pin 2, then a Check with its defaults.
- Add a Loop
Add a Loop and keep its default Times of 3.
- Add the flash
Add a Standard LED on pin 13 with Off/On on and a Wait of 150 ms. Then add a Standard LED on pin 13 with Off/On off and another Wait of 150 ms.
- Press and hold
A Loop with nothing closing it repeats every block after it, in the simulator and over USB direct, so the four LED and Wait blocks run three times. Hold the button until the flashing starts, then let go: if it’s still pressed when the next pass reads it, you get another three flashes.
Want a press to open a gate instead? The push-button gate in the servo guide uses the same Button and Check.
Questions
I press the button and nothing happens. Why?
Over USB direct and in the simulator, a Check reads the button once, at the moment the sequence reaches it. It does not wait for a press, so if the button isn’t held right then, that pass ends. Tick Infinity Loop on the sequence so it reads again every cycle, and hold the button for a moment.
Do I need a pull-up or pull-down resistor?
No. Wire the button between the pin and GND. ArduinoStudio turns on the board’s internal pull-up, so the pin reads 1 when released and 0 when pressed, and a Check’s “on” means pressed. Don’t use pull-down wiring (5 V to the button, 10 kΩ to GND): with the internal pull-up on, pressed and released come out reversed.
Can I use a button through the Bridge desktop app?
The Bridge runs the Button block differently: it waits for a press instead of reading once. But it doesn’t turn on the internal pull-up yet, so with pin-to-GND wiring the pin can float and trigger by itself. For button projects, connect with USB direct in Chrome, Edge or on a Chromebook.
Which two legs of a four-leg push button do I use?
Use two legs diagonally opposite each other. Inside the button the legs are joined in pairs, and diagonal legs are always on opposite sides of the switch, so the circuit only closes when you press.
What’s the difference between the Button and Switch blocks?
Both read a digital pin with the internal pull-up and work with a Check the same way. Use Button for a momentary push button, and Switch for a toggle or slide switch that stays where you leave it. The Switch section of the components reference has its wiring.