# Button
Hey there, future engineers and coders! Today, we’re diving into a cool and simple project that combines hardware and software: connecting a pushbutton to a Lonely Binary Uno R3 (a version of the popular Arduino Uno R3 microcontroller) and making it talk to us! By the end of this project, you’ll have a button that, when pressed, tells your computer, “Button is pressed.” Let’s get started with some basic electronics and coding—perfect for beginners in STEM!
# What You’ll Need
- **Lonely Binary Uno R3**: This is our microcontroller, the “brain” of the project. It’s just like an Arduino Uno R3, so it’s great for learning.
- **Pushbutton**: A simple button that completes a circuit when pressed.
- **Breadboard**: A tool to easily connect components without soldering.
- **10kΩ Resistor**: This will help us set the button’s default state to LOW (off).
- **Jumper Wires**: To connect everything together.
- **USB Cable**: To connect your Uno R3 to your computer.
- **Computer with Arduino IDE**: This free software lets you write and upload code to the Uno R3.

# Understanding the Circuit
Before we wire things up, let’s talk about what’s happening. The Lonely Binary Uno R3 has pins called GPIO (General Purpose Input/Output) that we can use to read signals—like whether a button is pressed. We’re using **GPIO 4** (also called digital pin 4) for this project.
The button will connect to this pin, and we’ll use a **pull-down resistor** (the 10kΩ one) to make sure the pin reads LOW (0 volts) when the button isn’t pressed. When you press the button, it connects GPIO 4 to 5V (HIGH), and the Uno R3 will detect that change. Then, we’ll tell it to print “Button is pressed” to the computer screen. Cool, right?
# Wiring It Up on the Breadboard
Here’s how to set up the circuit:
1. **Place the Button on the Breadboard**: Push the button’s legs into the breadboard so it straddles the center gap (this keeps the legs separate). Most buttons have four legs, but we’ll only use two opposite ones.
2. **Connect Power**: Use a jumper wire to connect one side of the button to the **5V pin** on the Uno R3.
3. **Connect to GPIO 4**: Use another jumper wire to connect the opposite side of the button to **digital pin 4** on the Uno R3.
4. **Add the Pull-Down Resistor**: Connect the 10kΩ resistor between the same side of the button as GPIO 4 and the **GND (ground)** pin on the Uno R3. This pulls the voltage to 0V (LOW) when the button isn’t pressed.
5. **Ground the Circuit**: Make sure the breadboard’s ground rail is connected to the Uno R3’s GND pin if needed.
Double-check your connections—loose wires can cause headaches!
# Writing the Code
Now, let’s program the Uno R3 using the Arduino IDE. Open the IDE on your computer and type this code:
```cpp
// Define the pin for the button
const int buttonPin = 4; // GPIO 4
// Variable to store the button state
int buttonState = 0;
void setup() {
// Start the serial communication at 9600 baud rate
Serial.begin(9600);
// Set the button pin as an input
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed (HIGH)
if (buttonState == HIGH) {
Serial.println("Button is pressed");
delay(200); // Small delay to avoid spamming the screen
}
}
```
Here’s what the code does:
- `const int buttonPin = 4;` assigns GPIO 4 to our button.
- `Serial.begin(9600);` starts communication with your computer so we can see the message.
- `pinMode(buttonPin, INPUT);` tells the Uno R3 that pin 4 is for reading the button.
- `digitalRead(buttonPin);` checks if the pin is HIGH (5V, button pressed) or LOW (0V, button not pressed).
- `Serial.println("Button is pressed");` prints the message when the button is pressed.
- `delay(200);` adds a tiny pause so the message doesn’t flood the screen too fast.
# Upload and Test
1. Connect your Uno R3 to your computer with the USB cable.
2. In the Arduino IDE, select **Tools > Board > Arduino Uno** (the Lonely Binary Uno R3 works the same way).
3. Select the correct port under **Tools > Port**.
4. Click the **Upload** button (right arrow) to send the code to the Uno R3.
5. Open the Serial Monitor (**Tools > Serial Monitor**) and set the baud rate to **9600**.
Now, press the button! You should see “Button is pressed” appear in the Serial Monitor each time you push it. If nothing happens, check your wiring—maybe the resistor or a wire isn’t snug.
Push Button
RELATED ARTICLES
Photoresistor Sensor
Project - Temperature Measurement
NTC Temperature Sensor
Project - IR Sender
Project - IR Receiver
Remote infrared Sensor
Project - Motion Detection Alarm
- Choosing a selection results in a full page refresh.