How To Use Digital Input And Digital Output Of Arduino
Again with new Arduino Project. Here this is simple arduino Tutorial.
There is no other tool available which helps in easy prototyping like the arduino does. Any AVR microcontroller based board which follows the standard arduino schematic and is flashed with the arduino boot-loader can be called an arduino board. The arduino can be used as a stand-alone board of which the output or inputs can be taken from the boards or given to the board using convenient connectors. Both digital and analog inputs and outputs are available in all arduino boards. When it comes to programming the arduino board anyone who have basic knowledge of c programming can quickly get started with the arduino IDE.
Since the arduino board can act as a stand-alone system it should have capabilities to take inputs process the input and then generate a corresponding output. It is through these inputs and outputs that the arduino as a system can communicate with the environment. The arduino boards can communicate with other devices using digital input/output analog input/output standard communication ports like USART, IIC, and USB etc.
This article explains how to use the digital input and output of the arduino board with the help of a simple push button as a digital input device and a LED as a digital output device.
The digital output device in this particular project is an LED which is connected to the pin number 5 of the arduino board through a 1K current limiting resistor. A push button is connected to the pin number 13 using a pull down resistor. The code continuously reads the status of the pin number 13 which has been configured as digital output. Due to the presence of the pull down resistor the default value will be zero (the value when the key is not pressed). When the key is pressed the value at the pin 13 suddenly becomes logic high and the code detects the change and glows the LED connected to the pin number 5.
const int buttonPin = 13; // the number of the pushbutton pin
const int ledPin = 5; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
// initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH)
// turn LED on:
// turn LED off:
The function pinMode() is a built-in function used to set a particular pin as input or output. The first parameter is pin number and the second parameter suggests whether the pin should be input or output.
For example to make pin number 5 as output
pinMode (5, OUTPUT);
To make pin number 6 as input
The digitalWrite() is another function which can be used to write a digital value (logic 0 or logic high) to a particular pin which has already been made as output using the pinMode() function.
For example to make the pin number 5 as logic high
And to make the same pin as logic low
The digitalRead is a function which is used to read the value (logic0 or logic1) at a pin which has already been made input using the pinMode() function. Suppose if the pin number 13 is an input pin then one can use the pinMode () function to store the value of the pin number 13 into a variable ‘var’ as shown in the following example;
var = digitalRead(13);
The function returns the value 0 or 1 according to the voltage existing at the pin number 13 into the variable ‘var’ which can be an integer or character type.
The function delay () is a very useful function for almost all the projects and it can generate a delay in milliseconds between the code steps.
Keil is a German based Software development company. It provides several development tools like
IDE (Integrated Development environment)
C Cross Compiler , Cross Assembler, Locator/Linker