Home / Learn Embedded C / Reading a Push Button
Reading a Push Button
Detecting a button press reliably using GPIO input.
Theory in plain words
Definition
Reading a push button means configuring its pin as input (usually with a pull-up), then checking GPIO_READ against the "pressed" level — often LOW, if wired active-low with a pull-up.
Why you need this
Buttons are the most common physical user-input device in embedded projects, and getting the read polarity (active-high vs active-low) right is a frequent early source of "my button does nothing" bugs.
How it works
A button that connects the pin to ground when pressed, combined with an internal/external pull-up, reads HIGH when unpressed and LOW when pressed — the opposite of what beginners often expect.
Where you'll see this
- User input handling
- Mode-switching controls
- Simple HMI (human-machine interface)
Try it
This sandbox's simulated GPIO_READ returns a fixed test value — on real hardware this would reflect the physical button state at read time.
Try it: checking two buttons for a combo press
Reading several buttons is just repeating the single-button read pattern per pin and combining the results with logical AND/OR.
Test what you just read
1. With a button wired to ground and a pull-up resistor, what does GPIO_READ return when the button is PRESSED?
Pressing the button connects the pin directly to ground, overriding the pull-up and reading LOW.