Push button interfacing with Arduino Tutorial #5

Push button interfacing with Arduino Tutorial #5

Welcome back to the Techatronic, in this article, I am gonna do a brief description of Push-button interfacing with Arduino tutorial. if you are a learner and want to learn the Arduino. Arduino is an open-source multipurpose development board which can be used to learn and automate the small thing in daily life like curtain riser. and there are many other applications like stepper motor rotation and pixel led driving with the Arduino. push button interfacing helps you to learn to control the project by one push button or switch and it will also help you to learn the Coding part. so .let’s start the tutorial.

So first we will understand the working principle of this experiment. There are a lot of communication pins on an Arduino but in this experiment, we will use the digital pins of the Arduino. there are 14 digital pins in the Arduino Uno so we will use that digital pins in this experiment. we can use digital pins as input pins as well as the output pins. so now we will use both functions of the pins in this experiment which is push-button interfacing with the Arduino. there are two devices to interface with the Arduino one is push-button and the other is an LED bulb. the push button has to be connected to the Arduino input pins and the LED to be connected to the output pin.

The Push-button has to be connected to the input pins so It can read the push button. when you press the push button then the edge of the attitude will change for example the voltage change from 5v to 0 in binary 1 to 0, in assembly HIGH to LOW you can use the last two in the Arduino language.

How does it work?

in a push-button interface with Arduino when you press that button the input voltage will change from high to low then the pin connected to the push button gets to recognize and send to the Arduino that it get some value on the input pins. now the code start to process and the led connected to the Arduino will start to glow. you need to press the push button only the rest of the work will be done by the Arduino and the system. so, this is the lesson in the article to learn the input and the output peripheral of the Arduino and the Arduino coding. you need only a few components to make it run. it will help you to learn the basics of robotics and sensor interfacing.

 

Components Required for Interface push button with the Arduino

  • Arduino Uno
  • USB to A type cable
  • Jumper wires
  • LED
  • Push Button
  • Resistor
  • Breadboard

Arduino interfacing with push-button circuit diagram. 

push butto interface with arduino

 

Now it turns to code the Arduino for the project. if you don’t know how to operate Arduino software install and setup the Arduino IDE app.

 

/*
  Button

 Turns on and off a light emitting diode(LED) connected to digital
 pin 13, when pressing a pushbutton attached to pin 2.


 The circuit:
 * LED attached from pin 13 to ground
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.



 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

upload the given code in the Arduino with the given step. all the best.

Leave a Reply