It is assumed that the reader has gone through the project Getting started with arduino and done all the things discussed in it.
Fig. 2: Typical Arduino Pro-Mini Board
This project also uses the arduino pro-mini board and the same version of the arduino IDE 1.0.3.
Fig. 3: Arduino IDE Software Window
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:
All the arduino code has two basic functions namely setup() and loop() explained in the project Getting started with arduino. Apart from these functions there are four other library functions used in this project namely pinMode (), digitalRead (), digitalWrite () and delay().
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.
For example to generate a delay of 5 seconds,
Once the coding has been done verify the code and upload the code to the arduino board as mentioned in the project how to get started with the arduino.