Digital input with Arduino (Push button) – How does work push button.

        Hello guys, Welcome back to my blog. I have described in previous articles how to get analog outputs. Do you remember it? We used analog pins for this. Okay, let’s go to the post today. Today we are going to talk about how to get digital input to the Arduino board. Digital pins can be used for this project. These pins are numbered D2 to D13. Do not use 1 or 2 pins for digital readings. These pins are used for Serial communication. We can get the analog reading value from 0 to 1024 but the digital reading value is 0 or 1. It’s a boolean value. We can get this value using various sensors or components connected to the Arduino board. We will build robots using these methods in the next articles.




Let’s do this project using the push button. This circuit can be done in two ways. It is PULL UP and PULL DOWN. These methods are described below. Let’s do this project step by step. The components are given below.

Components

  • Arduino NANO board  — Banggood / Amazon / AliExpress
  • Push-button  —- Banggood / Amazon / AliExpress
  • 10 Resistor x 1 — BanggoodAmazon / AliExpress
  • 1k Resisto x 1 — Banggood /  Amazon  /

            Hello guys, Welcome back to my blog. I have described in previous articles how to get analog outputs. Do you remember it? We used analog pins for this. Okay, let’s go to the post today. Today we are going to talk about how to get digital input to the Arduino board. Digital pins can be used for this project. These pins are numbered D2 to D13. Do not use 1 or 2 pins for digital readings. These pins are used for Serial communication. We can get the analog reading value from 0 to 1024 but the digital reading value is 0 or 1. It’s a boolean value. We can get this value using various sensors or components connected to the Arduino board. We will build robots using these methods in the next articles.




    Let’s do this project using the push button. This circuit can be done in two ways. It is PULL UP and PULL DOWN. These methods are described below. Let’s do this project step by step. The components are given below.

    Components

     
    Step 1
    Let’s identify the components.
    Arduino nano board
    I used the Arduino Uno board in previous articles but I used the Arduino Nano board for this project. Because the Arduino Nano board is a very cheap price.
    Push Button
    The push-button has four legs but this project uses two legs.
    10k Resistor and 1k Resistor.
     

    This component is mainly used to control the current. According to this project, the 10k resistor is used to PULL UP and PULL DOWN. The 1k resistor is used to control the current.

    Breadboard
    The breadboard is very important for testing circuits.
    LED Bulb

    Jumper Wires
    I have used five (male to male) jumper wires for this project.




    Step 3

    Attach the push button and the Arduino Nano board to your breadboard.
    Step 5
    Ok, let’s see the PULL UP circuit.




    The D2 pin and GND pin on the Arduino board is connected to the push button. After, The D2 pin is then connected to a 5v supply via a 10K resistor from the connection point. In this case, the value is 0 when the push buttons are pressed. Otherwise, the digital reading value is 1.You can watch this process with your serial monitor. Use the code below.
    PULL DOWN circuit
    Understand well. In this case, the D2 pin and 5v pins on the Arduino board are connected to the push button. After, The D2 pin is then connected to a GND via a 10K resistor from the connection point. In this case, the value is 1 when the push buttons are pressed. Otherwise, the digital reading value is 0. You can watch this process with your serial monitor. Use the code below.




    So today I am using the PULLUP circuit for my project. Today I am going to show you the project where an LED bulb on when the push button is pressed. For this, we will connect the LED bulb to the PULLUP circuit itself using a 1k resistor. Use the Arduino D3 pin for that. See the circuit below.
    Step 6
    Look at the code below, read and understand it.
    The complete program of this project – Download
    void setup() {
      pinMode(2, INPUT);
      pinMode(3, OUTPUT);
    }
    void loop() {
      bool value = digitalRead(2);
      if (value == 0) {
        digitalWrite(3, HIGH);
      } else {
        digitalWrite(3, LOW);
      }
    }
    In the void setup code, the D2 pin defines an input pin and the D3 pin defines the output pin. One by one the code parts of the void loop code are described below.
    bool value =digitalRead(2);   –  This code is read to the digital value of the component connected to the D2 pin. Then it put into the Boolean variable. Only 1 or 0 can be stored in the Boolean data type.
      if (value == 0) {
        digitalWrite(3, HIGH);
      } else {
        digitalWrite(3, LOW);
      }

    This code checks that the Boolean variable is equal to 0. If it is equal to 0 then the code inside it is run. Then the LED bulbs light up. If the value of the variable is 1, the bulb will be switched off.

    Step 7

    Select board and port



    .

     




    Step 8
    Upload this code.

    Watch the video below for more details. We will meet in the next post. Have a good day. Bye-bye.

  • Breadboard  — BanggoodAmazon / AliExpress
  • LED bulb x 1 — BanggoodAmazon / AliExpress
  • Jumper Wires  — BanggoodAmazon / AliExpress
 
Step 1
Let’s identify the components.
Arduino nano board
I used the Arduino Uno board in previous articles but I used the Arduino Nano board for this project. Because the Arduino Nano board is a very cheap price.
Push Button
The push-button has four legs but this project uses two legs.
10k Resistor and 1k Resistor.
 

This component is mainly used to control the current. According to this project, the 10k resistor is used to PULL UP and PULL DOWN. The 1k resistor is used to control the current.

Breadboard
The breadboard is very important for testing circuits.
LED Bulb

Jumper Wires
I have used five (male to male) jumper wires for this project.




Step 3

Attach the push button and the Arduino Nano board to your breadboard.
Step 5
Ok, let’s see the PULL UP circuit.




The D2 pin and GND pin on the Arduino board is connected to the push button. After, The D2 pin is then connected to a 5v supply via a 10K resistor from the connection point. In this case, the value is 0 when the push buttons are pressed. Otherwise, the digital reading value is 1.You can watch this process with your serial monitor. Use the code below.
PULL DOWN circuit
Understand well. In this case, the D2 pin and 5v pins on the Arduino board are connected to the push button. After, The D2 pin is then connected to a GND via a 10K resistor from the connection point. In this case, the value is 1 when the push buttons are pressed. Otherwise, the digital reading value is 0. You can watch this process with your serial monitor. Use the code below.




So today I am using the PULLUP circuit for my project. Today I am going to show you the project where an LED bulb on when the push button is pressed. For this, we will connect the LED bulb to the PULLUP circuit itself using a 1k resistor. Use the Arduino D3 pin for that. See the circuit below.
Step 6
Look at the code below, read and understand it.
The complete program of this project – Download
void setup() {
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
}
void loop() {
  bool value = digitalRead(2);
  if (value == 0) {
    digitalWrite(3, HIGH);
  } else {
    digitalWrite(3, LOW);
  }
}
In the void setup code, the D2 pin defines an input pin and the D3 pin defines the output pin. One by one the code parts of the void loop code are described below.
bool value =digitalRead(2);   –  This code is read to the digital value of the component connected to the D2 pin. Then it put into the Boolean variable. Only 1 or 0 can be stored in the Boolean data type.
  if (value == 0) {
    digitalWrite(3, HIGH);
  } else {
    digitalWrite(3, LOW);
  }

This code checks that the Boolean variable is equal to 0. If it is equal to 0 then the code inside it is run. Then the LED bulbs light up. If the value of the variable is 1, the bulb will be switched off.

Step 7

Select board and port



.

 




Step 8
Upload this code.

Watch the video below for more details. We will meet in the next post. Have a good day. Bye-bye.

Digital input with Arduino (Push button) – How does work push button.

Similar Posts

Leave a Reply

Your email address will not be published.