Arduino with Push Button Interfacing-3rd Tutorial

Hello,

Today we are going to make this Tutorial on How to do Arduino with Push button interfacing. this is our 3rd tutorial on Arduino. all the students of BTech and schools who want to learn Embedded and Arduino they can learn from our tutorial. to learn the embedded system first you have to know what is an embedded system. and then learn something about the microcontroller. Arduino is also a microcontroller having many specific functions and used for many applications nowadays. So, the push button also having much application so we have to learn how’s it work. so now let’s understand the function and working of the push button with Arduino.

 

As you know we can use Arduino as output and also in the input configuration. in our last tutorial led blinking with Arduino. we used the pins as output pins and now we are going to use these pins as input pins.so how to configure and how to use all thing we will discuss it in this post.so read full article carefully to understand the Arduino with push button interfacing work properly.

 

How to Configure Arduino pins as an input pin.

In the last post, we have configured the pins as output pins and all the thing about we have discussed there. and now, there we understand the procedure to configure the Arduino pins as input pins. when we talk about the register inside the Arduino which help to configure any pin. so there is also a register which helps to configure the pin as an input pin. but in the Arduino IDE, there is a library. there are some functions used to configure the pins. there is a function call pinMode.  we have to give some value in the pinMode bracket to configure the pin as an input pin.

fox example:-  pinMode(6, INPUT)

after writing this the pin will configure as an input pin. but, the work is not yet completed as we are making a pushbutton interfacing. this can only the configure the pin. it can not get the value at the input pin. to get the value from the pin 6 which we have made input. we have to write digitalRead. 

  • digitalRead

it is used to get the value from the digital pin. it means when we write this. it gets the value from the pin. means what actually connected to the pin. for example, we have connected an IR sensor to pin 6 and. then we can receive the data from the IR sensor.

ex:- digitalRead(6) in this case, Arduino get value from the digital pin 6

sometimes we have to get the value from the analog sensor so we can not get the value by writing the digitalRead now. we have to write another function which is analogRead . to know more click here

read this para carefully

when we get the digital value from any sensor on the digital pin, then we have to store this value into any variable.

for example:-  int m= digitalRead(6);

in this code, we store the value in the “m

first, we read the value from the digital pin and then stores in any variable.

now the value in the “m ”

we can compare this value with any other value.

we connected a digital sensor and getting the digital value it means we have 0 or 1. either we are getting 0 or either we are getting 1 from the sensor.

now we know we are getting 0. so we can put a condition in the code.

if (m ==HIGH)    // it means if we get high or 1 at pin 6

{

digitalWrite(2, HIGH);     //  send HIGH 0r 1 on the pin 2 which is output pin.

}

it means when we get 1 at the input pin.

then, Arduino will send HIGH on pin 2

now take a look on the circuit.

Arduino with Push Button Interfacing circuit diagram

arduino push button interfacing

 

CIRCUIT FOR PUSH BUTTON:-

 

Code for Arduino with Push Button Interfacing:- 

void setup()

{

pinMode(4, INPUT_PULLUP);

pinMode(8, OUTPUT);

}

void loop()

{

int m= digitalRead(4);

if (m==HIGH)

 

{

digitalWrite(8, HIGH);

}

}

copy this sketch and paste into the Arduino IDE and upload it into the Arduino. click here to learn how to upload the sketch.

Leave a Reply

Your email address will not be published. Required fields are marked *