Menu Close

Arduino – Digital Input & Output | Pushbutton & LED

This tutorial explains basic concepts of arduino. Digital input and digital output. Digital input is taken through push button and that is detected by Arduino. This input is processes by Arduino and it send digital command to attached LED.

When the button is pressed LED glows.

1. Introduction:

A step by step illustrated basic tutorial for Arduino. In this tutorial we are taking digital input from a push button switch. That input is read by Arduino board and decision is taken accordingly. When we press the button LED glows. Thus this tutorial is for both digital input and digital output.

1.1 Digital Input:

Digital input means when we are supplying HIGH/1/+5V or LOW/0/GND to the Arduino board. On the contrary digital output means when we are taking HIGH/1/+5V or LOW/0/GND from the Arduino.

In this example Pin No. 2 of Arduino is connected to +5V through a switch and the same pin is also connected to GND via 10K resistance. This resistance keeps this pin at GND and when we press button it gets connected to +5V. So we can understand that if switch is released the Input Pin (Pin No.2) is GND/LOW/0 and when switch is presses it is +5V/HIGH/1.

2. Required Hardware

S.No.ItemQuantity
1 Arduino UNO 1
2 Breadboard 1
3 LED 1
4 Resistor 1k 1
5 Resistor 10k 1
6 Jumper Male to male 6
7 Push Button Switch 1

3. Building Circuit

Schematic Diagram:

Circuit Layout:

4. Programming:

Once we are done with circuit part, here is our programme to this circuit. All of the commands are explained in the comment section. Output video is attached at the last of this tutorial, This example will be clear after watching the video.

You may download codes (Arduino Sketch) from here.

This code has a simple function to perform, if Button is pressed glow the LED.

/*
Tutorial on Digital input through button.
By Robo India
http://roboindia.com/
*/

const int BUTTON = 2;     // Pushbutton Input to Pin No.2
const int LED =  3;       // Output LED to Pin No. 3


int BUTTONState = 0;      // To store input status

void setup() {
  pinMode(LED, OUTPUT);    // Define LED pin as output.   
  pinMode(BUTTON, INPUT);  // Define BUTTON pin as Input.   
}


void loop(){
  BUTTONState = digitalRead(BUTTON); // Reading input from Button Pin.

  if (BUTTONState == HIGH) // Checking if Input from button is HIGH (1/+5V)
   {     
     digitalWrite(LED, HIGH);  // If input is High make LED ON (HIGH/1/+5V)
   } 
  else  
  {
     digitalWrite(LED, LOW);  // For every other condition make LED OFF (0/GND/LOW)
  }
}

 5. output:

Here is the output of this tutorial. Above code is implemented on Robo India R-Board and Arduino UNO Both.

 6. Actual Circuit

Actual circuit with Robo India R-Board looks like-

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply