Jump to content

Push Button: Difference between revisions

From cognifront
CogWikiEditor (talk | contribs)
CogWikiEditor (talk | contribs)
Line 158: Line 158:
| LED control
| LED control
|}
|}
== Procedure ==
# Write the program according to the algorithm given below.
# Save and compile the program.
# Connect the Arduino UNO board to the PC/Laptop using a USB cable.
# Upload the program to the Arduino UNO.
# Open the Serial Monitor if required.
# Press the first push button and observe the LED.
# Press the second push button and observe the buzzer.
# Release the push buttons and observe the corresponding outputs.


== Program ==
== Program ==

Revision as of 17:38, 3 September 2026

Interfacing Push Buttons with Arduino UNO

Interfacing Push Buttons with Arduino UNO demonstrates how push buttons can be interfaced with an Arduino UNO board to control an LED and a buzzer.

The practical also demonstrates the concept of pull-up and pull-down resistor configurations used while interfacing push buttons with a microcontroller.

Objectives

  • To study the concept of push buttons.
  • To study the pull-up resistor and pull-down resistor configurations used for interfacing push buttons with the Arduino UNO.
  • To interface push buttons with the Arduino UNO.
  • To write a program to control the inbuilt LED and buzzer using push buttons.

Theory

Introduction to Push Buttons

A push button or simply button is a simple switch mechanism used for controlling different aspects of a machine or process.

A push button is used to make or break an electrical circuit.

When the push button is pressed, the circuit is closed and current starts flowing through it. As a result, the devices connected in the circuit can be turned ON.

Examples include:

  • Doorbells
  • Horns
  • Calculators
  • Control panels

In this practical, a Momentary Tactile Push Button is used.

A momentary push button temporarily closes the circuit when it is pressed.

When the button is pressed:

Push Button Pressed → Circuit Closed → Device ON

When the button is released:

Push Button Released → Circuit Open → Device OFF

A push button generally has four pins. For interfacing purposes, the appropriate two terminals of the push button are used to provide the required connection to the Arduino UNO.

Push Button as a Digital Sensor

A push button is a digital sensor because it provides two possible logic states:

  • LOW (0)
  • HIGH (1)

One connection from the push button is connected to a digital input pin of the Arduino UNO.

The corresponding Arduino pin is configured as an INPUT.

When the push button is not pressed, the input pin must have a defined logic state.

If the input pin is not connected to a defined HIGH or LOW level, it can enter a floating or undetermined state.

Undefined Input → Floating State

To avoid this condition, pull-up or pull-down resistor configurations are used.

Pull-Up Resistor

In a pull-up resistor configuration, a resistor is connected between the input pin and the VCC supply.

The resistor keeps the input pin at a HIGH state when the push button is not pressed.

When the button is pressed, the input can be connected to ground and becomes LOW.

Pull-Up → Default HIGH

Pull-Down Resistor

In a pull-down resistor configuration, a resistor is connected between the input pin and Ground.

In this practical, the pull-down resistor configuration is used.

The value of the pull-down resistor is approximately 1 kΩ.

When the push button is not pressed, the input pin is connected to ground through the resistor.

Therefore, the input pin reads LOW.

Push Button Not Pressed → Input LOW

When the push button is pressed, the input pin gets connected directly to VCC.

Therefore, the input pin reads HIGH.

Push Button Pressed → Input HIGH

The operation can be summarized as:

Push Button State Input Pin Logic
Not Pressed Connected to GND through pull-down resistor LOW
Pressed Connected to VCC HIGH

Connections

Device Pin Arduino UNO Function
1st Push Button Data D9 Digital input
Push Buttons VCC 5V Power supply
Push Buttons GND GND Ground
Buzzer Data D5 Buzzer control
Buzzer GND GND Ground
LED Inbuilt LED D13 LED control

Program

int ledPin = 13;
int buzzPin = 5;
int pushbutton1Pin = 9;

int pushbutton1Value;

void setup() {
  Serial.begin(9600);

  pinMode(ledPin, OUTPUT);
  pinMode(buzzPin, OUTPUT);
  pinMode(pushbutton1Pin, INPUT);
}

void loop() {
  pushbutton1Value = digitalRead(pushbutton1Pin);

  if (pushbutton1Value == 1) {
    digitalWrite(ledPin, HIGH);
    digitalWrite(buzzPin, HIGH);
  } 
  else {
    digitalWrite(ledPin, LOW);
    digitalWrite(buzzPin, LOW);
  }
}

Observation

Observe the output of the LED and buzzer while pressing the push buttons.

When the 1st push button is pressed, the LED turns ON.

When the 1st push button is released, the LED turns OFF.

When the 2nd push button is pressed, the buzzer turns ON.

When the 2nd push button is released, the buzzer turns OFF.

The push buttons provide digital input to the Arduino UNO in the form of HIGH and LOW signals.

Result

The Arduino UNO successfully interfaces with the push buttons using the pull-down resistor configuration.

The first push button is used to control the LED, while the second push button is used to control the buzzer.

The Arduino UNO correctly detects the HIGH and LOW states of the push buttons and controls the respective output devices accordingly.