0% found this document useful (0 votes)
12 views21 pages

Arduino Programming Laboratory Guide

Arduino lab manual

Uploaded by

pavannit4
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)
12 views21 pages

Arduino Programming Laboratory Guide

Arduino lab manual

Uploaded by

pavannit4
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

ARM/ARDUINO

PROGRAMMING
LABORATORY -R20
Department of ECE
HoD, Mr. T. Jagadeesh
LIST OF EXPERIMENTS:

1. Display Your Name and Roll Number on a 16x2 Display using Arduino.
2. Measure Analog signal from Temperature Sensor.
a.​ Arduino
b.​ Tinker Cad
3. Generate PWM output
a.​ Arduino
b.​ Tinker Cad
4. Drive single-character generation on HyperTerminal
5. Drive a given string on Hyper Terminal.
6. Full duplex Link establishment using HyperTerminal
7. Drive the Stepper motor using Tinker Cad.
8. Drive the Accelerometer and Display the readings on the HyperTerminal
Basics of Arduino
Definition:

An Arduino is actually a microcontroller-based kit which can be either


used directly by purchasing from the vendor or can be made at home
using the components, owing to its open-source hardware feature. It is
basically used in communications and in controlling or operating many
devices. It was founded by Massimo Banzi and David Cuartielles in 2005.

Arduino Architecture:
Arduino’s processor basically uses the Harvard architecture where the
program code and program data have separate memory. It consists of two
memories- Program memory and the data [Link] code is stored in the
flash program memory, whereas the data is stored in the data memory. The

Atmega328 has 32 KB of flash memory for storing code (of which 0.5 KB is
used for the bootloader), 2 KB of SRAM and 1 KB of EEPROM and operates
with a clock speed of 16MHz.
Fig 2. Arduino Architecture
Arduino Pin Diagram
A typical example of Arduino board is Arduino Uno. It consists of ATmega328-
a 28 pin microcontroller.2

Arduino Pin
Diagram
Arduino Uno consists of 14 digital input/output pins (of which 6 can be used as PWM
outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power
jack, an ICSP header, and a reset button
Arduino Uno consists of 14 digital input/output pins (of which 6 can be used as PWM
outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power
jack, an ICSP header, and a reset button

Power Jack: Arduino can be power either from the pc through a USB or through an
external source like adaptor or a battery. It can operate on a external supply of 7 to
12V. Power can be applied externally through the pin Vin or by giving voltage
reference through the IORef pin.
Digital Inputs: It consists of 14 digital inputs/output pins, each of which provide or
take up 40mA current. Some of them have special functions like pins 0 and 1, which
act as Rx and Tx respectively, for serial communication, pins 2 and 3-which are
external interrupts, pins 3,5,6,9,11 which provides pwm output and pin 13 where LED
is connected.
Analog inputs: It has 6 analog input/output pins, each providing a resolution of 10
bits.
ARef: It provides reference to the Analog inputs
Reset: It resets the microcontroller when low.
Exp: 1: Temperature Sensor (Analog Input)
In this project, you will turn the Arduino into a thermometer! Use a
temperature sensor to measure your skin temperature, and register the output
with three LEDs. Even though the Arduino is a digital tool, it can interpret
signals from an Analog input, like the temperature sensor, using the built-in
Analog-to-Digital (ADC) converter, accessed through the Analog pins.

Program:
//IOT BASED TEMPERATURE / LIGHT MONITORING
Pin Diagram:

The temperature sensor in Arduino converts the surrounding temperature to voltage. It


further converts the voltage to Celcius, Celcius to Fahrenheit, and prints the Fahrenheit
temperature on the LCD screen.

We will use a temperature sensor (TMP 36) of low voltage. Such sensors are also stable
while dealing with large capacitive loads. It is also suitable for automotive applications.

The temperature sensors TMP 35, TMP 36, and TMP 37 are the sensors with the same
features.

The operating voltage of the TMP 36 sensor ranges from 2.7V to 5.5V.

The sensor will look like the image shown below:


It has three terminals, which are listed below:

○​ Pin 1: DC voltage

Here, we will connect the DC voltage pin to 5V on the Arduino UNO board.

○​ Pin 2: Analog voltage output

We will consider the Analog voltage output pin as the output.

○​ Pin 3: GND

We will connect the GND pin to the Ground on the Arduino UNO board.

Aim: Measure Analog signal from Temperature Sensor

Apparatus: The components required for the project are listed below:

○​ 1 x TMP 36 sensor (Temperature sensor)

○​ 1 x LCD display

○​ Arduino UNO R3 board (We can take any Arduino board).

○​ Jump wires

Program:​
#include <LiquidCrystal.h>
// initialize the library with the pins on the Arduino board

LiquidCrystal lcd(13, 12, 6, 4, 3, 2);

const int temperature = A0; //A0 is the analog pin

const int D = 8; // Vo of LCD is connected to pin 8 of the Arduino

void setup()

[Link](16, 2);

[Link](9600);

pinMode(D, OUTPUT);

void loop()

digitalWrite(D,LOW);

int Temp = analogRead(temperature);

float volts = (Temp / 965.0) * 5;

float celcius = (volts - 0.5) * 100;

float fahrenheit = (celcius * 9 / 5 + 32);

[Link](fahrenheit);

[Link](5, 0);

[Link](fahrenheit);

delay(2000);

// time delay of 2000 microseconds or 2 seconds

}
Exp2: Arduino PWM
In Arduino PWM Tutorial, you are going to learn about what PWM is and how you can get the
PWM output from the digital pins of Arduino. First, we will control the brightness of LED
through code and then we will control it manually by adding the potentiometer.

PWM stands for Pulse Width Modulation and it is a technique used in controlling the brightness
of LED, speed control of DC motor, controlling a servo motor or where you have to get analog
output with digital means.

The Arduino digital pins either gives us 5V (when turned HIGH) or 0V (when turned LOW) and
the output is a square wave signal. So if we want to dim a LED, we cannot get the voltage
between 0 and 5V from the digital pin but we can change the ON and OFF time of the signal. If
we will change the ON and OFF time fast enough then the brightness of the led will be changed.

Before going further, let’s discuss some terms associated with PWM.

TON (On Time): It is the time when the signal is high.

TOFF (Off Time): It is the time when the signal is low.

Period: It is the sum of on time and off time.

Duty Cycle: It is the percentage of time when the signal was high during the time of period.

So at 50% duty cycle and 1Hz frequency, the led will be high for half a second and will be low
for the other half second. If we increase the frequency to 50Hz (50 times ON and OFF per
second), then the led will be seen glowing at half brightness by the human eye.
Arduino and PWM
The Arduino IDE has a built-in function “analogWrite()” which can be used to generate a PWM
signal. The frequency of this generated signal for most pins will be about 490Hz and we can give
the value from 0-255 using this function.

analogWrite(0) means a signal of 0% duty cycle.

analogWrite(127) means a signal of 50% duty cycle.

analogWrite(255) means a signal of 100% duty cycle.

On Arduino Uno, the PWM pins are 3, 5, 6, 9, 10 and 11. The frequency of PWM signal on pins
5 and 6 will be about 980Hz and on other pins will be 490Hz. The PWM pins are labeled with ~
sign.
Controlling Brightness of LED through Code

Firstly, make the connections as described below.

Connect the positive leg of LED which is the longer leg to the digital pin 6 of Arduino. Then
connect the 220 ohm resistor to the negative leg of LED and connect the other end of resistor to
the ground pin of Arduino.

Read More: Interfacing LED with Arduino

Now let’s write a code to change the brightness of the LED using PWM.
EXP:2
Aim: To Generate PWM Output
Apparatus: 1. Arduino Software
2. Arduino Uno Board
3. LED
4. 220 Ohm Resistors
5. Connecting wires, Adapter
6. USB cable
Arduino Code
Upload the code in the Arduino IDE and the LED will start to fade.

//Initializing LED Pin

int led_pin = 6;

void setup() {

//Declaring LED pin as output

pinMode(led_pin, OUTPUT);

void loop() {

//Fading the LED

for(int i=0; i<255; i++){

analogWrite(led_pin, i);

delay(5);

for(int i=255; i>0; i--){

analogWrite(led_pin, i);

delay(5);

}
EXP:3

Aim: Drive single character generation on Hyper Terminal

Apparatus: 1. Arduino software


2. Arduino Uno
3. USB cable
4. Adapter 5v

Arduino Code:​
//***** Single Character Generation ON HYPER TERMINAL ****
String readString;
void setup() {

[Link](9600);
delay(100);
}

void loop() {

while([Link]()){
delay(3);
char d = [Link]();
readString+=d;
}

if([Link]() >00 && [Link]() <=02 )


{
[Link]("CHAR REC:");
[Link](readString);
delay(100);
}
readString = "";
}
Exp-4

Aim: Drive a given string on Hyper Terminal


Apparatus: 1. Arduino software
2. Arduino Uno
3. USB cable
4. Adapter 5v

Arduino Code:​
//***** String Generation ON HYPER TERMINAL ****
String readString;
void setup() {

[Link](9600);
delay(100);
}

void loop() {

while([Link]()){
delay(3);
char d = [Link]();
readString+=d;
}

if([Link]() >0 )
{
[Link]("CHAR REC:");
[Link](readString);
delay(100);
}
readString = "";
}
Exp-5
Aim: Full Duplex Link Establishment Using Hyper terminal in Arduino
Apparatus:
1.​ Arduino UNO
2.​ Arduino Software
3.​ LCD Display
4.​ Connecting wires
5.​ USB cable
6.​ Adapter 5v

Code:

//***** FULL DUPLEX LINK ON HYPER TERMINAL ****

#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
String readString;

void setup() {

[Link](9600);
[Link](16, 2);
[Link]();
[Link](0,0);
[Link](" FULL DUPLEX LINK ");
[Link](0,1);
[Link](" ON HYPER TERMINAL");
delay(3000);
[Link]();
[Link](0,0);
[Link](" WAITING FOR DATA ");
[Link](0,1);
[Link](" ");
delay(100);
}

void loop() {

while([Link]()){
delay(3);
char c = [Link]();
readString+=c;
}

if([Link]() >0)
{
[Link](0,1);
[Link](" ");
[Link](0,1);
[Link](readString);
[Link]("DAT RECEIVED: ");
[Link](readString);
delay(100);
}
readString = "";
}
EXP :6
Arduino Accelerometer

In this topic, we will discuss a project based on an accelerometer. The value will be read from the
series of accelerometers and received in the Arduino IDE's serial monitor. It means the data will
be read and received over the serial port.

We will use a three-axis accelerometer that gives acceleration for each Axis as an analog voltage
for separate pins.

The position of the three axes (X-axis, Y-axis, and Z-axis) will change according to the
ADXL335 accelerometer's position.

If we hold the board in a different position, the direction of the three-axis will also change.
Moving the board in a particular direction will cause a change in the voltage of the respective
axis. We can measure the changed voltage on the Arduino.

When we hold the board up and flat, the measured acceleration of 9.8m/s^2 will appear on the
Z-axis.

It is also called gravity. Here,

1.0G = of 9.8m/s^2

where,

G is the acceleration due to earth's gravity.

The sensitivity of the ADXL335 accelerometer is:

s = 0.33V/G.

Gravity force per ADC (Analog to Digital Converter) unit is:

It is because the sensors need 3.3V to operate.

The accelerometer at rest will read half of its maximum analog voltage.
Aim: Drive Accelerometer and Display the readings on Hyper Terminal
Apparatus:
1 x ADXL335 accelerometer

1 x Arduino UNO R3

PIN Diagram:

Program:

const int GND = A4;

const int PowerPIN = A5;

const int pinOfX = A3;

const int pinOfY= A2;


const int pinOfZ= A1;

void setup()

[Link](9600);

pinMode(GND , OUTPUT);

pinMode(PowerPIN , OUTPUT);

digitalWrite(GND , LOW); // configuring the GND pin as LOW

digitalWrite(PowerPIN , HIGH); // configuring the power pin HIGH (5V/3.3V)

void loop()

// It prints the values of the sensors

[Link](analogRead(pinOfX)); // print a tab between values:

[Link]("\t");

[Link](analogRead(pinOfY));

[Link]("\t");

[Link](analogRead(pinOfZ));

[Link](); // It delays before next reading

delay(100);

}
EXP 7:​
Aim : Drive a stepper Motor using Arduino
Apparatus:

○​ 1 x Arduino UNO R3 (We can use any Arduino board)

○​ 1 x Breadboard

○​ Jump Wires

○​ 1 x 10K Ohm Potentiometer

○​ 1 x Stepper motor

○​ 1 x power supply (according to the stepper)

○​ LM298 Driving IC

Program :
#include <Stepper.h> //library declared for the operation of stepper motor
const int stepsPERrevolution = 200; // We can change it according to the required steps per
revolution

// for our motor

// the initialization of pins 8 to 11 of stepper library

Stepper myStepper(stepsPERrevolution, 8, 9, 10, 11);

int CountofSTEP = 0; // number of steps the motor has taken

void setup()

[Link](9600);

void loop()

// read the sensor value:

int ReadingINSensor = analogRead(A1);

// we can map it to a range from 0 to 100:

int SpeedOFmotor = map(ReadingINSensor, 0, 1023, 0, 100);

// to set the speed of the motor

if (SpeedOFmotor > 0)

[Link](SpeedOFmotor);

// step 1/100 of a revolution

[Link](stepsPERrevolution/ 100);

You might also like