0% found this document useful (0 votes)
22 views

VIRTUAL HANDS ON TRAINING ON ARDUINO PROGRAMMING

This user manual provides comprehensive guidance on Arduino programming and interfacing various components using the Arduino UNO board. It includes setup procedures, basic programming concepts, and hands-on experiments for practical learning, such as LED blinking, reading analog inputs, and interfacing sensors. The document is structured to facilitate understanding for beginners in electronics and programming with Arduino.

Uploaded by

pranesh1362006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

VIRTUAL HANDS ON TRAINING ON ARDUINO PROGRAMMING

This user manual provides comprehensive guidance on Arduino programming and interfacing various components using the Arduino UNO board. It includes setup procedures, basic programming concepts, and hands-on experiments for practical learning, such as LED blinking, reading analog inputs, and interfacing sensors. The document is structured to facilitate understanding for beginners in electronics and programming with Arduino.

Uploaded by

pranesh1362006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

VIRTUAL HANDS ON TRAINING

ON ARDUINO PROGRAMMING
User Manual

Prepared by
Mr. S Arun, Assistant Professor,
ECE Department.
Contents
Basic Components of Arduino UNO board and their functions. ............................................................. 2
Setup Procedure ..................................................................................................................................... 3
Understanding basics of Arduino programming ..................................................................................... 6
Procedure to Login and use Tinkercad to Simulate Arduino Projects .................................................... 8
LED Blink................................................................................................................................................ 11
Reading Analog input using POT ........................................................................................................... 13
LED ON OFF USING PUSH BUTTON ....................................................................................................... 15
Interfacing TMP36 Temperature sensor ............................................................................................... 17
Interfacing 4x4 keyboard ...................................................................................................................... 19
LCD Display Interfacing ......................................................................................................................... 22
Interfacing Ultrasonic Sensor with Arduino .......................................................................................... 24
Interfacing Servo Motor with Arduino .................................................................................................. 26
Interfacing IR Sensor with Arduino. (Home Automation) ..................................................................... 27

1|Page
Basic Components of Arduino UNO board
and their functions.

Figure 1 Basic components of Arduino Uno

Here are the basic components of an Arduino board and their functions.

1. Reset Button – This will restart any code that is loaded to the Arduino board
2. AREF – Stands for “Analog Reference” and is used to set an external reference voltage
3. Ground Pin – There are a few ground pins on the Arduino and they all work the same.
4. Digital Input/output – Pins 0-13 can be used for digital input or output
5. PWM – The pins marked with the (~) symbol can simulate analog output
6. USB Connection – Used for powering up your Arduino and uploading sketches
7. TX/RX – Transmit and receive data indication LEDs
8. ATmega Microcontroller – This is the brains and is where the programs are stored
9. Power LED Indicator – This LED lights up anytime the board is plugged in a power
source
10. Voltage Regulator – This controls the amount of voltage going into the Arduino board
11. DC Power Barrel Jack – This is used for powering your Arduino with a power supply
12. 3.3V Pin – This pin supplies 3.3 volts of power to your projects
13. 5V Pin – This pin supplies 5 volts of power to your projects
14. Ground Pins – There are a few ground pins on the Arduino and they all work the same
15. Analog Pins – These pins can read the signal from an analog sensor and convert it to
digital
2|Page
Setup Procedure
Step 1: Install the Arduino Software (IDE)
(Ignore step1 if software is already installed)
For downloading Arduino software go to https://www.arduino.cc/en/Main/Software.

Step 2: Get an Uno R3 and USB cable


If you are using an Uno R3. You also need a standard USB cable (A plug to
B plug) as shown in Figure 2.

Figure 2 Arduino Uno R3 and USB cable

Step 3: Connect the board


The USB connection with the PC is necessary to program the board and not just to power
it up. The Uno automatically draw power from either the USB or an external
power supply. Connect the board to your computer using the USB cable. The green
power LED (labelled PWR) should go on.

Figure 3 Board connection

3|Page
Step 4: Select your board
You'll need to select the entry in the Tools > Board menu that corresponds to your
Arduino board as shown in Figure 4.

Figure 4 Selecting Arduino board Type

Step 5: Select your serial port


Check which com port is allotted for your
Arduino board in device manager as shown in Figure 5.

Figure 5 com port allotted by computer

4|Page
Select the corresponding com port in the
window as shown in Figure 6

Figure 6 Selecting com port in Arduino sketch window

Step 6: Upload the program


Now, simply click the "Upload" button in the environment as shown in Figure 7. Wait
a few seconds – you should see the RX and TX LEDs on the board flashing. If the upload is
successful, the message "Done uploading." will appear in the status bar.

Figure 7 Compile and upload icon

Step 7: Adding Library


Some of the program needs library files to support certain operation. In order to add
the library Select SketchInclude library Add Zip library(if you already downloaded
library) as shown in Figure 8.

Figure 8 Adding Library files

5|Page
Arduino interface introduction

Figure 9 Arduino IDE sketch window

A ->Compile
B ->Upload
C ->New
D ->Open
E ->Save
F ->Serial monitor

Understanding basics of Arduino


programming
The code you write for your Arduino are known as sketches.
Every sketch needs two void type functions, setup() and loop(). A void type function doesn’t
return any value.

The setup() method will run once after the Arduino is powered up and the loop() method will
run continuously afterwards. The setup() is where you want to do any initialisation steps, and
in loop() you write the code which you want to run over and over again.

6|Page
Program Structure
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}

Controlling onboard LED available in Arduino


Onboard LED is connected to pin number 13. While writing the program we can use the pin
number directly or we can assign any name to that pin and use it inside our program.
We know that void setup is used for initialization. It means the program which you are writing
inside the Void setup() will execute only once. Onboard LED is already connected to pin 13,
If you want to control the onboard LED, we need to set the 13 pin to output mode inside void
setup.
For example, we have special function called pinMode().
Syntax:
pinMode(pin, mode);
Parameters:
Pin-the number of the pin whose mode you wish to set.
Mode-It may be INPUT, OUTPUT etc.

Void setup()
{
pinMode(13,OUTPUT);
}
In this case pin number 13 is selected and configured pin number 13 as output pin.

In Void loop, the main code which has to run repeatedly has to be written. In our case, we
need to program Arduino to switch ON the inbuilt LED(Connected to 13th pin).

In order to do this, we have another function called digitalWrite().

Syntax
digitalWrite(pin,value);
pin: the pin number
Value:HIGH OR LOW

For example you want to keep the LED conned to pin 13 in ON state, we should write
digitalWrite(13,HIGH);
Suppose, we need to write the code which makes the digital pin 13 an OUTPUT and toggles
it by alternating between HIGH and LOW at one second pace.
void setup()
{
pinMode(13,OUTPUT);
}
void loop()

7|Page
{
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}

Procedure to Login and use Tinkercad to


Simulate Arduino Projects
Step 1:Click here to open tinkercad.
Step 2: Sign in using any one of the following method.

8|Page
Step 3: Select Circuits Create new Circuits

Step 4: Type on search bar to find the required


components. Click and drag the component to the
circuit Connection area.

Step 5: After Arduino is placed in Circuit connection


area, select code option, the following window will
appear.

9|Page
Step 6: Click on blocks and select text

Step 7: You can type required program on the text


window.

Step 8: If Circuit connection and programming are over,


click on start simulation.

10 | P a g e
Hands on Experiment No.1:
Experiment Name:

LED Blink
Connection Diagram

Figure 10 Connection diagram for LED blink

LED anode is connected to 11th pin and cathode is connected to ground.


Program
void setup() {
pinMode(11, OUTPUT); //initialize 11th pin as output pin
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(11, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Or Same program can be written as

int led=11; // we can give name to pin number


void setup() {
11 | P a g e
//initialize 11th pin as output pin
pinMode(led, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

12 | P a g e
Hands on Experiment No.2:
Experiment Name:

Reading Analog input using POT


Connection Diagram

Figure 11 Potentiometer

1. Middle pin of potentiometer


is connected to Analog input pin 0.
2. Outside pins are connected
to Vcc and Ground.
3. Type the following program
and view the result in serial monitor.

Figure 12 Connection diagram for Analog Read

Program
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:


void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:

float voltage = sensorValue * (5.0 / 1023.0);


Serial.println(voltage);
delay(100); // delay in between reads for stability
}
13 | P a g e
Function used
analogRead(A0);

Reads the value from the specified analog pin.Arduino has 10-bit analog to digital converter. This
means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023.
This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.

Syntax
analogRead(pin)

Pin: the number of the analog input pin to read from (0 to 5 on most boards)

Returns integer value between 0 to 1023.

14 | P a g e
Hands on Experiment No.3:
Experiment Name:

LED ON OFF USING PUSH BUTTON


Connection Diagram:

1. LED attached from pin 13 to ground.


2. Pushbutton attached to pin 2 from +5V.
3. 10K resistor attached to pin 2 from ground. If
push button is not pressed pin 2 will be pulled low
through 10k resistor.
Note: on most Arduino’s there is already an LED on
the board attached to pin 13.

Figure 13 Connection diagram for controlling LED using


push button

Program:
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13;
// the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
digitalWrite(ledPin,HIGH);
}
void loop() {
// 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:
digitalWrite(ledPin, HIGH);

15 | P a g e
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Function used

digitalRead()

Description

Reads the value from a specified digital pin, either HIGH or LOW.

Syntax
digitalRead(pin)

Parameters
pin: the number of the digital pin you want to read

Returns
HIGH or LOW

if...else

Description

The if statement checks for a condition and executes the proceeding statement or set of
statements if the condition is 'true'. Otherwise statement present in else part will be executed.

Syntax
if (condition)
{
//statement(s)
}else
{
//Statement(s)
}
Parameters
condition: a boolean expression i.e., can be true or false.

16 | P a g e
Hands on Experiment No.4:
Experiment Name:

Interfacing TMP36 Temperature sensor


Connection Diagram
1. Refer pin diagram of TMP36 to
identify Vcc, output and Ground pins.
2. Connect Vcc pin of TMP36 to 5 volts.
3. Middle pin is connected to A0(analog
input 0)
4. Connect Ground pin to Ground in
Arduino.

Figure 14 Connection diagram for interfacing TMP36 sensor

Program
//TMP36 Pin Variables
int sensorPin = 0;
//the analog pin the TMP36's Vout (sense) pin is connected //to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}

void loop() // run over and over again


{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);

// converting that reading to voltage, for 3.3v arduino use 3.3


17 | P a g e
float voltage = reading * 5.0;
voltage /= 1023.0;

// print out the voltage


Serial.print(voltage); Serial.println(" volts");

// now print out the temperature


float temperatureC = (voltage - 0.5) * 100 ;
//converting from 10 mv per degree with 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");

// now convert to Fahrenheit


float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");

delay(1000); //waiting a second


}

Result can be viewed in serial monitor. To open serial monitor, select Tools Serial monitor as
shown in Figure 15.

Figure 15 Open serial monitor

18 | P a g e
Hands on Experiment No.5
Experiment Name:

Interfacing 4x4 keyboard


Connection Diagram

Figure 16 Connection diagram for interfacing 4x4 keyboard

Program
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6};


byte colPins[COLS] = {5, 4, 3, 2};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();

19 | P a g e
if (customKey){
Serial.println(customKey);
}
}
Internal structure of KeyPad Module

Consider we have connected the KEYPAD MODULE to a microcontroller.STEP1: First set all
ROWS to OUTPUT and set them at +5V. Next set all COLUMNS as INPUT to sense the HIGH
logic. Now consider a button is pressed on keypad. And that key is at 2nd COLUMN and 3rd ROW.

Figure 17 Keyboard module step 1

With the button being pressed the current flows as shown in Figure 17. With that a voltage of +5V
appears at terminal C2. Since the COLUMN pins are set as INPUTS, the controller can sense C2
going high. The controller can be programmed to remember that C2 going high and the button pressed
is in C2 COLUMN.

STEP2: Next set all COLUMNS to OUTPUT and set them at +5V. Next set all ROWS as INPUT to
sense the HIGH logic. Since the key pressed is at 2nd COLUMN and 3rd ROW. The current flows as
shown in Figure 18.

Figure 18 Operation of Keyboard module Step 2

20 | P a g e
With that current flow a positive voltage of +5V appears at R3 pin. Since all ROWS are set as INPUTS,
the controller can sense +5V at R3 pin. The controller can be programmed to remember the key being
pressed at third ROW of KEYPAD MATRIX.

From previous step, we have known the COLUMN number of key pressed and now we know ROW
number. With that we can match the key being pressed. We can take the key INPUT provided by this
way for 4X4 KEYPAD MODULE.

21 | P a g e
Hands on Experiment No.6
Experiment Name:

LCD Display Interfacing


Connection Diagram:

1. Connect Arduino pin 0,1,2,3 with D7, D6, D5, D4 pins of LCD display.
2. Connect 4th pin of Arduino with E pin of LCD display.
3. Connect 5th pin of Arduino with RS pin of LCD display.
4. Connect RW, Vss pin of LCD display with ground pin of Arduino.
5. Connect Vcc Pin of LCD display with 5V supply.
6. Connect middle wire of potentiometer with V0. Other two ends of potentiometer are
connected to Vcc and Ground.
7. Anode of LCD display is connected to +5V through 330 Ω resistor and cathode is connected
to Ground

Program:
#include<LiquidCrystal.h>
LiquidCrystal lcd (5, 4, 3, 2, 1, 0); // sets the interfacing pins
void setup ()
{
lcd.begin(16, 2); // initializes the 16x2 LCD
}
void loop ()
{
lcd.setCursor (0, 0); //sets the cursor at row 0 column 0
lcd.print ("Amrita Vishwa"); // prints 16x2 LCD MODULE
lcd.setCursor (0,1); //sets the cursor at row 0 column 1
lcd.print ("Vidyapeetham,NGL");
}

22 | P a g e
The name and functions of each pin of the 16×2 LCD module is given below.
 Pin1(Vss):Ground pin of the LCD module.
 Pin2(Vcc): Power to LCD module (+5V supply is given to this pin)
 Pin3(V0):Contrast adjustment pin. This is done by connecting the ends of a 10K potentimeter
to +5V and ground and then connecting the slider pin to the VEE pin. The voltage at the VEE
pin defines the contrast. The normal setting is between 0.4 and 0.9V.
 Pin4(RS):Register select pin. The JHD162A has two registers namely command
register and data register. Logic HIGH at RS pin selects data register and logic LOW at RS
pin selects command register. If we make the RS pin HIGH and feed an input to the data lines
(DB0 to DB7), this input will be treated as data to display on LCD screen. If we make the RS
pin LOW and feed an input to the data lines, then this will be treated as a command ( a
command to be written to LCD controller – like positioning cursor or clear screen or scroll).
 Pin5(R/W): Read/Write modes. This pin is used for selecting between read and write modes.
Logic HIGH at this pin activates read mode and logic LOW at this pin activates write mode.
 Pin6(E): This pin is meant for enabling the LCD module. A HIGH to LOW signal at this pin
will enable the module.
 Pin7(DB0) to Pin14(DB7): These are data pins. The commands and data are fed to the LCD
module though these pins.
 Pin15(LED+): Anode of the back light LED. When operated on 5V, a 330 ohm resistor
should be connected in series to this pin.
 Pin16(LED-): Cathode of the back light LED.

23 | P a g e
Hands on Experiment No.7
Experiment Name:

Interfacing Ultrasonic Sensor with


Arduino
Connection Diagram

1. Connect SR04 Vcc to 5V pin in Arduino.


2. Connect ground pin of SR04 with ground pin in
Arduino.
3. Connect trigger pin of SR04 with 11 pin of
Arduino.
4. Connect Echo pin of SR04 with 12 pin of
Arduino

Description: The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object. It
comes with ultrasonic transmitter and receiver modules. Its range of detection is between 2cm to
400cm or 1’’ to 13ft. Its trigger input pulse width is 10µs.
Program
// Ultrasonic Sensor HC-SR04 interfacing with Arduino.
// defining the pins
const int trigPin = 11;
const int echoPin = 12; // defining variables long duration; int distance; void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an
Input Serial.begin(9600); // Starts the serial communication
}
void loop()
{ // Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
24 | P a g e
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.0343/2; // Prints the distance on the Serial Monitor
Serial.print("Distance in cm: ");
Serial.println(distance);
delay(500);
}

25 | P a g e
Hands on Experiment No.8
Experiment Name:

Interfacing Servo Motor with Arduino


Connection Diagram

1. Connect Ground pin of servo motor to ground pin of Arduino.


2. Connect power pin of Servo motor to 5v supply.
3. Connect signal pin of servo motor to pin 3 of Arduino.

Program
// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int servoPin = 3;
// Create a servo object
Servo Servo1;
void setup() {
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(3000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(3000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
}

26 | P a g e
Hands on Experiment No.9
Experiment Name:

Interfacing IR Sensor with Arduino.


(Home Automation)
Connection Diagram

1. Connect IR sensor ground pin to ground pin of Arduino uno.


2. Connect IR sensor power pin to Vcc.
3. Connect out pin of IR sensor to 3rd pin of Arduino.
4. Connect LED cathode to ground and anode to pin number 11 of Arduino.
5. Connect any one terminal of light bulb to 12th Pin and another terminal to ground.
6. Connect one terminal of DC motor to 5th Pin and another terminal to ground..

Program
#include <IRremote.hpp>
const int rcvPin=3;
IRrecv irrecv(rcvPin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(5, OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);

27 | P a g e
void loop() {

if(IrReceiver.decode()) {
auto value= IrReceiver.decodedIRData.decodedRawData;
//switch(results.value)
switch(value)
{
case 4010852096:
Serial.println("1"); // Button 1
digitalWrite(5,HIGH);
break;

case 3994140416: // Template


Serial.println("2"); // Button
digitalWrite(5,LOW);
break;

case 3944005376:
Serial.println("4"); // Button 1
digitalWrite(11,HIGH);
break;

case 3927293696: // Template


Serial.println("5"); // Button
digitalWrite(11,LOW);
break;

case 3877158656:
Serial.println("7"); // Button 1
digitalWrite(12,HIGH);
break;

case 3860446976: // Template


Serial.println("8"); // Button
digitalWrite(12,LOW);
break;
default: Serial.println(value);
}
Serial.println(value);
IrReceiver.resume(); // Receive the next value
}

28 | P a g e
Following Program can be used to identify the code for IR remote buttons

#include <IRremote.hpp>
const int rcvPin=3;
IRrecv irrecv(rcvPin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

}
void loop() {
if(IrReceiver.decode()) {
auto value= IrReceiver.decodedIRData.decodedRawData;
Serial.println(value);
IrReceiver.resume(); // Receive the next value
}
}

29 | P a g e

You might also like