Simple Button Digital Input using Arduino

Today we learn the simple simple Button Digital Input using Arduino it is very easy.

The Arduino has Digital I/O PINs. Which “I/O” is Input and Output We used the output of Arduino to display the LEDs.
Today we need to use the switches as digital input pins to get a various electrical signals to control the operation of the circuit as well.

What is Digital?
Digital is a kind of electrical signal. Which has work of only two states are:
– HIGH or ON or “1”
– LOW or OFF or “0”
We bring this digital Go to the many benefits and high accuracy.


What is the digital Input?

Digital Pins of Arduino can read 2 status are “HIGH” and “LOW” depend on that Pin has current or not.

Pull-up , Pull-Down
The Button switch to Input Pin of Arduino. We need to connect the resistor to exact status of the inputs. We use 2 form circuits

• Pull-Up: the Input will be connected with a resistor that call “Pull-UP Resistor” to a Vin we will have the status “HIGH” all the time, until you press button to LOW or ground, the Arduino will read “LOW” or we call “Active Low”

• Pull-Down: the Input will be connected with a resistor that call “Pull-Down Resistor” to a Ground we will have the status “LOW” all the time, until you press button to Vin or HIGH, the Arduino will read “HIGH” or we call “Active High”

We will see that 2 circuits have the operation reversed. Depending on what is selected.

Pull-up-Pull-Down_schem
Figure 1 Pull-up and Pull-Down Circuits

This resistors Pull-Up / Down Resistor used the 5K – 20K. We use 10K

Start to build the Button to control LED

We will use Input Pin of Arduino to receive the button status, then control LED display on Output Pin 13. By use the Pull-Down to apply LED grow up when we press the button only.

STEP 1

Parts will you needs
• Arduino UNO R3
• Normally open pushbutton
• one LED
• 10K resistor
• 470 ohms resistor
• jumper wires
• Breadboard

Simple Button Digital Input using Arduino_bb
Step 2 connect the parts as circuit Figure 2 The circuit connection

This circuit use Pull-Down by connect the Button to 5V power supply and 10K resistors to ground. And We use Digital PIN 3 as Input. Next, the Output is Digital PIN 13 connected to LED by 470 ? resistor to limit current.

Simple button digital input using arduino
Figure 3 Simple Button Digital Input using Arduino

Let’s test it

We type the code on IDE below

Simple-Button-Digital-Input-code-with-delay
Figure 4 the Simple Button Digital Input code with delay

  1. int buttonPin = 3;  // the number of the pushbutton pin
  2. int ledPin = 13;   // the number of the LED pin
  3. int buttonState = 0; // variable for reading the pushbutton status
  4. int delay1 = 10000;
  5.  
  6. void setup() {
  7.   pinMode(ledPin, OUTPUT);  // initialize the LED pin as an output:
  8.   pinMode(buttonPin, INPUT);  // initialize the pushbutton pin as an input:
  9. }
  10.  
  11. void loop() {
  12.   buttonState = digitalRead(buttonPin);   // read the state of the pushbutton value:
  13.   // check if the pushbutton is pressed.
  14.   // if it is, the buttonState is HIGH:
  15.  
  16.   if (buttonState == HIGH) {
  17.     digitalWrite(ledPin, HIGH);// turn LED on:
  18.      delay(delay1);
  19.   }
  20.   else {
  21.     digitalWrite(ledPin, LOW);// turn LED off:
  22.   }
  23. }

We test it as Video, first type code on IDE without “delay” command. And upload When we press the button LED will glow as we press. Then, we put code delay. The LED will delayed time turn ON about 10S.

Now we use the button or switch as digital input. It is easy