Experiments 5.
Learning hardware and software of Arduino board and developing basic programs
using GPIO.
Aim:Learning and developing programs on Arduino board
Learning Arduino IDE Programming Environment
Learning Hardware features of Arduino Development Board
Developing basic programs using GPIO (Analog Input, Analog
Output, Digital Input & Output)
1. Learning Hardware features of Arduino Development Board
Materials Required:
Arduino UNO Board
Bread board
LED
Wires
Data Cable
Theory:
The Arduino UNO R3 is frequently used microcontroller board in the family of
an Arduino. The main advantage of this board is if we make a mistake we can
change the microcontroller on the board. The mainfeatures of this board mainly
include, it is available in DIP (dual-inline-package), detachable and ATmega328
microcontroller. The programming of this board can easily be loaded by using an
Arduino computer program. This board has huge support from the Arduino
community, which will make a very simple way to start working in embedded
electronics, and many more applications.
Arduino Uno R3 Specifications
The Arduino Uno R3 board includes the following specifications.
It is an ATmega328P based Microcontroller
The Operating Voltage of the Arduino is 5V
The recommended input voltage ranges from 7V to 12V
The i/p voltage (limit) is 6V to 20V
Digital input and output pins-14
Digital input & output pins (PWM)-6
Analog i/p pins are 6
DC Current for each I/O Pin is 20 mA
DC Current used for 3.3V Pin is 50 mA
Flash Memory -32 KB, and 0.5 KB memory is used by the boot loader
SRAM is 2 KB
EEPROM is 1 KB
The speed of the CLK is 16 MHz
In Built LED
Length and width of the Arduino are 68.6 mm X 53.4 mm
2. Learning Arduino IDE Programming Environment
Arduino Integrated Development Environment (IDE)
You use the Arduino IDE on your computer to create, open, and change sketches
(Arduino calls programs
“sketches”). You can download the Arduino IDE software from
https://www.arduino.cc/en/software.
1. Setting up the Hardware
a. Plug in your board via USB and wait for Windows to begin its driver installation
process.
b. Click on the Start Menu, and open up the Control Panel.
c. While in the Control Panel, navigate to System and Security. Next, click on
System. Once the System
window is up, open the Device Manager.
d. Look under Ports (COM & LPT). You should see an open port named "Arduino
UNO (COMxx)".
e. Right click on the "Arduino UNO (COMxx)" port and choose the "Update Driver
Software" option.
f. Next, choose the "Browse my computer for Driver software" option.
g. Finally, navigate to and select the Uno‟s driver file, named "ArduinoUNO.inf",
located in the "Drivers" folder of the Arduino Software download. Windows will
finish up the driver
installation from there.
h. Double-click to open the Arduino application.
Writing a Program in Arduino IDE
1. Creating a Folder:
a. Make a new folder on Desktop.
b. Name it as “ECE_[Your group number]”
2. Launching the Arduino IDE:
a. First make a folder on Desktop. Name it as ECE.
b. Click on Start Programs Arduino
c. Arduino IDE software will appear.
3. Writing the program:
In most programming languages, you start with a program that simply prints “Hello,
World” to the screen.
The equivalent in the micro-controller world is getting a light to blink on and off. This
is the simplest
program we can write to show that everything is functioning correctly.
Write the following code in the sketch editor:
Example: Basic Program on LED blinking
void setup()
{
pinMode(4, OUTPUT);
}
void loop() {
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
4. Uploading the Code to Arduino Board:
Once you have written the code, compile and upload the code in your Arduino board.
You will see that
the build in LED on your Arduino UNO will turn on for one second and turn off for
once second
repeatedly.
3.Developing basic programs using GPIO (Analog Input, Analog Output, Digital
Input & Output)
Aim:Develop a program on Digital Input & Output using GPIOS
Hardware Required:
Component Name Quantity
Arduino UNO 1
LED 1
Push Button 1
220Ω resistor 1
10KΩ resistor 1
USB Cable 1
Breadboard 1
Jumper wires Several
Theory:
Push-button is a very simple mechanism which is used to control electronic signal
either by blocking it or allowing it to pass. This happens when mechanical pressure is
applied to connect two points of the switch together. Push buttons or switches connect
two points in a circuit when pressed. When the push-button is released, there is no
connection between the two legs of the push-button. Here it turns on the built-in LED
on pin 2 when the button is pressed. The LED stays ON as long as the button is being
pressed.
Connection Diagram:
Procedure
1. Insert the push button into your breadboard and connect it to the digital
pin 7(D7) which act as INPUT.
2. Insert the LED into the breadboard. Attach the positive leg (the longer
leg) to digital pin 2 of the Arduino Uno, and the negative leg via the
220-ohm resistor to GND. The pin D2 is taken as OUTPUT.
3. The 10kΩ resistor used as PULL-UP resistor and 220 Ω resistors is used
to limit the current through the LED.
4. Upload the code as given below.
5. Press the push-button to control the ON state of LED.
The Sketch
➢ This sketch works by setting pin D7 as for the push button as INPUT
and pin 2 as an OUTPUT to power the LED.
➢ The initial state of the button is set to OFF.
➢ After that the run a loop that continually reads the state from the pushbutton and
sends that value as voltage to the LED. The LED will be ON accordingly
/****************Pressing Button LED*****/
Program Digital Input & Output
const int buttonPin = 7; // choose the pin for the choose the pin for the
pushbutton
const int LED = 2; // choose the pin for a LED
int buttonState = 0; // variable for reading the choose the pin for the
pushbutton pin status
void setup()
{
pinMode(LED, OUTPUT); // declare LED as output
pinMode(buttonPin, INPUT); // declare choose the pin for the pushbutton as
input
}
void loop()
{
buttonState = digitalRead(buttonPin); // read input value
if (buttonState == HIGH)
{ // check if the input is HIGH (button pressed)
digitalWrite(LED, HIGH); // turn LED ON
delay(2000);
} // wait for a two seconds
else
{
delay(2000); // wait for a two second s
digitalWrite(LED, LOW); // turn LED OFF
}
}
Observation Table:
Sr no. Push button State LED State
1
2
Precautions:
1. The pushbutton is square so it is important to set it appropriately on
breadboard.
2. While making the connections make sure to use a pull-down resistor
because directly connecting two points of a switch to the circuit will
leave the input pin in floating condition and circuit may not work
according to the program.
3. It is very important to set pinMode() as OUTPUT first before using
digitalWrite() function on that pin.
4. If you do not set the pinMode() to OUTPUT, and connect an LED to a
pin, when calling digitalWrite(HIGH), the LED may appear dim.
Result: