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

Following Hardware will be required to perform this LED fade in and fade out circuit.

S.No.ItemQuantity
1.R-Board with FTDI or Arduino Board1
2.Bread Board1
3.Male to male Jumpers 7
4.Indicator LED1
5100 Ohm Resistance1
6.100 K Resistance1
7.Micro Push button switch1

3. Building Circuit

To run these practical examples make following circuit with the help of above mentioned components.

3.1 You may go with Robo India’s R-Board(UNO Compatible)-

here is the schematic:

or

3.2 You may go with original Arduino UNO Board-

here is the schematic:

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
http://roboindia.com

Leave a Reply