Tutorial 6 – Using Pushbuttons for Digital Input
Welcome back to the Arduino tutorial series at CraftedTech Engineering! In Tutorial 5, we learned how to fade an LED using a potentiometer and PWM. Now, in Tutorial 6, we’ll explore pushbuttons — one of the simplest and most useful input components in electronics.
You’ll learn how to read digital input, trigger actions with a button press, and build the foundation for more interactive Arduino projects.
🔌 What You’ll Need
- 1 Arduino Board (e.g., Arduino UNO)
- 1 Pushbutton
- 1 10kΩ Resistor (for pull-down)
- 1 LED
- 1 220Ω Resistor
- Breadboard
- Jumper wires
- USB cable for Arduino
You can order the required components here:
🧠 What Is a Digital Input?
A digital input reads either HIGH (5V) or LOW (0V). Pushbuttons are commonly used to send digital signals to the Arduino — allowing you to start/stop actions, toggle lights, control menus, and more.
🧾 Step-by-Step Instructions
🔧 Step 1: Circuit Wiring
- One side of the pushbutton to digital pin 2
- Other side of the pushbutton to 5V
- 10kΩ resistor from pin 2 to GND (acts as a pull-down resistor)
- LED anode (long leg) to digital pin 13 via 220Ω resistor
- LED cathode to GND
💻 Step 2: Arduino Code
int buttonPin = 2; // Pin connected to the pushbutton
int ledPin = 13; // Built-in LED pin
int buttonState = 0; // Variable for reading button status
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on
Serial.println("Button Pressed");
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
delay(100);
}
🔍 Code Breakdown
-
digitalRead(buttonPin)
checks if the button is pressed -
HIGH
means the button is pressed (5V) -
LOW
means it's not pressed (0V) - LED lights up only when the button is pressed
🧪 Try This!
- Add a second button to toggle the LED on and off
- Change the code to detect when the button is released instead
🛠️ Troubleshooting Tips
- Make sure your resistor is acting as a pull-down from pin to GND
- Ensure the button legs are oriented correctly on the breadboard
- Double-check pin numbers in code match your wiring
🧭 What You Learned in This Tutorial
✔️ How to use pushbuttons with Arduino
✔️ How to read digital inputs with digitalRead()
✔️ How to control an LED with a button press
✔️ The role of pull-down resistors in digital circuits
📌 Next Up: Tutorial 7 – Debouncing a Pushbutton
In the next lesson, we'll fix a common problem with buttons: bouncing — which causes multiple unwanted inputs. Learn how to debounce using code for cleaner input detection.
📣 Don’t forget to follow CraftedTech Engineering for more hands-on tutorials and project ideas!
🔗 Website: craftedtechengineering.com
📘 Facebook: @CraftedTechEngineering
📺 YouTube: @CraftedTechEngineering