Learning how to use a tactile button with Arduino is a simple and enjoyable way to start exploring electronics. This project involves controlling an LED by toggling it ON and OFF with a single button press. It introduces fundamental concepts like digital input, digital output, and state tracking, which are essential for creating interactive Arduino projects. By the end of this tutorial, you’ll understand how to read input from a button and use it to control an output, such as an LED.
In this setup, the tactile button acts as the user input device, allowing interaction with the Arduino board. Pressing the button will toggle the LED between ON and OFF states. This project not only demonstrates how to write and upload code to an Arduino but also how to connect components properly using a breadboard and jumper wires. These skills form the foundation for more advanced Arduino projects.
Once you’ve completed this tutorial, you’ll be ready to take on more advanced project. This project sets the stage for building creative and complex Arduino setups, opening a world of possibilities in electronics and programming. Dive in and start your Arduino journey today @Circuitrocks!
Components:
To build this project, you’ll need an Arduino board (such as the Uno, Mega, or Nano), a tactile button, an LED, a 220-ohm resistor for the LED, and a 10k-ohm resistor for the button. A breadboard and jumper wires will help you connect the components neatly. You’ll also need a USB cable to program the Arduino. Once you have all the materials ready, setting up the circuit and writing the code will be a breeze.

Connection:

LED:
- Anode (longer leg): Connected to digital pin 9.
- Cathode (shorter leg): Connected to GND through a 220-ohm resistor
Tactile Button:
- One leg of the button: Connected to digital pin 7 (Black).
- The other leg: connected to 5V (Red) from the Arduino.
- Opposite leg of the button: Connected to GND (Brown) directly.
Code:
#define LED_PIN 9
#define BUTTON_PIN 7
bool ledState = false; // Track the LED's state
bool lastButtonState = false; // Track the last button state
bool currentButtonState = false;
void setup() {
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
pinMode(BUTTON_PIN, INPUT); // Set button pin as input
digitalWrite(LED_PIN, LOW); // Turn off the LED initially
}
void loop() {
currentButtonState = digitalRead(BUTTON_PIN); // Read button state
// Check for button press (rising edge)
if (currentButtonState && !lastButtonState) {
ledState = !ledState; // Toggle the LED state
digitalWrite(LED_PIN, ledState); // Turn LED ON/OFF
}
lastButtonState = currentButtonState; // Save the button state
}
If everything works as expected, your circuit is good to go!