You are on page 1of 50

ARM BASED/ AURDINO BASED PROGRAMMING

GAYATRI VIDYA PARISHAD COLLEGE OF ENGINEERING FOR WOMEN

Approved by AICTE, New Delhi, Affiliated to JNT University, Kakinada

Madhurawada, Visakhapatnam-530048

ARM BASED/ARDUINO BASED PROGRAMMING


LABORATORY MANUAL

(R 20)

Department of Electronics and Communication Engineering


VISION & MISSION

Vision of the Institute


To emerge as an acclaimed Centre of learning that provides value based technical
education for the holistic development of students
Mission of the Institute

• Undertake activities that provide value-based knowledge in Science, Engineering &


Technology
• Provide opportunities for learning through Industry – Institute interaction on the state
– of – the – art technologies
• Create collaborative environment for research, innovation and entrepreneurship
• Promote activities that bring in a sense of social responsibility

Vision of the Department

Produce competitive engineers instilled with ethical and social responsibilities to deal
with the technological challenges in the field of Electronics & Communication
Engineering

Mission of the Department

• Facilitate a value based educational environment that provides updated technical


knowledge

• Provide opportunities for developing creative, innovative and leadership skills

• Imbue technological and managerial capabilities for a successful career and lifelong
learning
III Year – II Semester LTPC
102 2

ARM BASED/ AURDINO BASED PROGRAMMING


LIST OF EXPERIMENTS:
1. Measure Analog signal from Temperature Sensor
2. Generate PWM output
3. Drive single character generation on Hyper Terminal
4. Drive a given string on Hyper Terminal
5. Full duplex Link establishment using Hyper terminal
6. Drive a given value on a 8-bit DAC consisting of SPI
7. Drive Stepper motor using Analog GPIOs
8. Drive Accelerometer and Display the readings on Hyper Terminal
COMPONENTS/ BOARDS:
1. Arduino Duemilanove Board
2. Arduino Software IDE
COs, POs,PSOs & CO-PO-PSO Mapping
Course Outcomes
NBA
Course Outcomes
Subject Code
CO1
Familiar with Arduino Environment and its applications.
CO2 Understand a new IDE, Compiler and MCU chip in Arduino compatible
EC boards.
CO3
Understand Arduino Programming with C++.
CO4
Develop skills to design and implement various smart system applications.

Program Outcomes
Engineering graduate will be able to
PO-1: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering
specialization to the solution of complex engineering problems.
PO-2: Identify, formulate, research literature, and analyse complex engineering problems reaching
substantiated conclusions using first principles of mathematics, natural sciences, and engineering
sciences.
PO-3: Design solutions for complex engineering problems and design system components or processes that
meet the specified needs with appropriate consideration for the public health and safety, and the
cultural, societal, and environmental considerations.
PO-4: Use research-based knowledge and research methods including design of experiments, analysis and
interpretation of data, and synthesis of the information to provide valid conclusions.
PO-5: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools
including prediction and modeling to complex engineering activities with an understanding of the
limitations.
PO-6: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal, and
cultural issues and the consequent responsibilities relevant to the professional engineering practice.
PO-7: Understand the impact of the professional engineering solutions in societal and environmental
contexts, and demonstrate the knowledge of, and need for sustainable development.
PO-8: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
PO-9: Function effectively as an individual, and as a member or leader in diverse teams, and in
multidisciplinary settings.
PO-10: Communicate effectively on complex engineering activities with the engineering community and
with society at large, such as, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear instructions.
PO-11: Demonstrate knowledge and understanding of the engineering and management principles and apply
these to one’s own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.
PO-12: Recognize the need for, and have the preparation and ability to engage in independent and life-long
learning in the broadest context of technological change.
PSO-1: To Acquire knowledge required for designing Electronics and Communication systems.
PSO-2: Design, simulate and implement essential modules in the areas of Electronic circuits, VLSI,
Embedded systems, Communication and Signal processing.
Mapping of Course Outcomes (COs) with Program Outcomes (POs)

Program Outcomes (POs)


Course
PO PO PO PO PO PO PO PO PO PO PO PO PSO PSO
Outcomes
1 2 3 4 5 6 7 8 9 10 11 12 1 2

CO1

CO2
EC

CO3

CO4
LABORATORY RULES
1. Remove your footwear before you enter the lab.
2. Keep the lab premises clean.
3. Always maintain silence in the lab premises. Be considerate to other lab users.
4. Report any problems with the computer to the person in charge.
5. Shut down the computer properly.
6. Do not hit the keys on the computer too hard.
7. If you leave the lab, do not leave your personal belongings unattended.
8. Don’t damage, remove, or disconnect any labels, parts, cables or equipment.
9. Lab users must sign in and out of the lab in the login register (for regular labs) or in
remedial lab register (for extra labs).
10. No food or drink in any form is allowed in the labs.
11. Do not use cell phones in laboratory premises.
12. Lab users should maintain professional and courteous communication.
13. Please operate the equipment with respect and care.
14. Activities in the lab(s) that are considered by the lab in charge to be abusive to the
software, hardware, and\or personnel may result in expulsion from the lab(s) and
denial of future use of the lab(s).
15. Software may be installed by Computer Labs staff only. Do not install any software
on your own. Files not put on by Computer Labs staff will be routinely removed.
16. Do not modify any software or files. Do not overwrite the operating system or modify
any other system parameters.
17. Priority will be given for course related use of computers in the lab.
18. Copying software without appropriate authorization violates the college policy. Illegal
use of materials in the labs is grounds for denial of use of the labs and confiscation of
illegally used materials.
19. The lab assistants are here to help when they can and to maintain the labs' operation.
However, the lab assistants are not here to do your work for you.
20. Any failure to follow these lab rules may result in the loss of your lab privileges.
TABLE OF CONTENTS

TOPIC PAGE.NO.

Familiarization of Arduino UNO board and Arduino IDE


1. Measure Analog signal from Temperature Sensor
2. Generate PWM output
3. Drive single character generation on Hyper Terminal
4. Drive a given string on Hyper Terminal
5. Full duplex Link establishment using Hyper terminal
6. Drive a given value on an 8-bit DAC consisting of SPI
7. Drive Stepper motor using Analog GPIOs
8. Drive Accelerometer and Display the readings on Hyper Terminal
Familiarization of Arduino UNO board and Arduino IDE

ARDUINO UNO
Arduino UNO is a very valuable addition in electronics that consists of a USB
interface, 14 digital I/O pins(of which 6 Pins are used for PWM), 6 analog pins
and an Atmega328 microcontroller. It also supports 3 communication protocols
named Serial, I2C and SPI protocol.
Arduino Uno Board Layout:
The following image shows the layout of a typical Arduino uno board.
The Arduino Uno R3 pin diagram comprises 14-digit I/O pins. From these pins, 6-pins can
be utilized like PWM outputs. This board includes 14 digital input/output pins, Analog
inputs-6, a USB connection, quartz crystal-16 MHz, a power jack, a USB connection,
resonator-16Mhz, a power jack, an ICSP header an RST button.

Power Supply
The power supply of the Arduino can be done with the help of an exterior power supply
otherwise USB connection. The exterior power supply (6 to 20 volts) mainly includes a battery
or an AC to DC adapter. The connection of an adapter can be done by plugging a center-positive
plug (2.1mm) into the power jack on the board. The battery terminals can be placed in the pins
of Vin as well as GND. The power pins of an Arduino board include the following.
Vin: The input voltage or Vin to the Arduino while it is using an exterior power supply opposite
to volts from the connection of USB or else RPS (regulated power supply). By using this pin,
one can supply the voltage.
5Volts: The RPS can be used to give the power supply to the microcontroller as well as
components which are used on the Arduino board. This can approach from the input voltage
through a regulator.
3V3: A 3.3 supply voltage can be generated with the onboard regulator, and the highest draw
current will be 50 mA.
GND: GND (ground) pins
Memory
The memory of an ATmega328 microcontroller includes 32 KB and 0.5 KB memory is utilized
for the Boot loader), and also it includes SRAM-2 KB as well as EEPROM-1KB.

Input and Output


We know that an arguing Uno R3 includes 14-digital pins which can be used as an input
otherwise output by using the functions like pin Mode (), digital Read(), and digital Write().
These pins can operate with 5V, and every digital pin can give or receive 20mA, & includes a
20k to 50k ohm pull up resistor. The maximum current on any pin is 40mA which cannot
surpass for avoiding the microcontroller from the damage. Additionally, some of the pins of an
Arduino include specific functions.
Serial Pins
The serial pins of an Arduino board are TX (1) and RX (0) pins and these pins can be used to
transfer the TTL serial data. The connection of these pins can be done with the equivalent pins
of the ATmega8 U2 USB to TTL chip.

External Interrupt Pins


The external interrupt pins of the board are 2 & 3, and these pins can be arranged to activate
an interrupt on a rising otherwise falling edge, a low-value otherwise a modify in value

PWM Pins
The PWM pins of an Arduino are 3, 5, 6, 9, 10, & 11, and gives an output of an 8-bit PWM
with the function analog Write ().

SPI (Serial Peripheral Interface) Pins


The SPI pins are 10, 11, 12, 13 namely SS, MOSI, MISO, SCK, and these will maintain the SPI
communication with the help of the SPI library.
LED Pin
An arguing board is inbuilt with a LED using digital pin-13. Whenever the digital pin is high,
the LED will glow otherwise it will not glow.
TWI (2-Wire Interface) Pins
The TWI pins are SDA or A4, & SCL or A5, which can support the communication of TWI
with the help of Wire library.

AREF (Analog Reference) Pin


An analog reference pin is the reference voltage to the inputs of an analog i/ps using the
function like analog Reference ().

Reset (RST) Pin


This pin brings a low line for resetting the microcontroller, and it is very useful for using an
RST button toward shields which can block the one over the Arduino R3 board.

Communication
The communication protocols of an Arduino Uno include SPI, I2C, and UART serial
communication.
UART
An Arduino Uno uses the two functions like the transmitter digital pin1 and the receiver digital
pin0. These pins are mainly used in UART TTL serial communication.
I2C
An Arduino UNO board employs SDA pin otherwise A4 pin & A5 pin otherwise SCL pin is
used for I2C communication with wire library. In this, both the SCL and SDA are CLK signal
and data signal.
SPI Pins
The SPI communication includes MOSI, MISO, and SCK.

MOSI (Pin11)
This is the master out slave in the pin, used to transmit the data to the devices

MISO (Pin12)
This pin is a serial CLK, and the CLK pulse will synchronize the transmission of which is
produced by the master.

SCK (Pin13)
The CLK pulse synchronizes data transmission that is generated by the master. Equivalent pins
with the SPI library is employed for the communication of SPI. ICSP (in-circuit serial
programming) headers can be utilized for programming ATmega microcontroller directly
with the boot loader.

Arduino Uno R3 Programming

• The programming of an Arduino Uno R3 can be done using IDE software. The
microcontroller on the board will come with pre-burned by a boot loader that permits
to upload fresh code without using an exterior hardware programmer.
• The communication of this can be done using a protocol like STK500.
• We can also upload the program in the microcontroller by avoiding the boot loader
using the header like the In-Circuit Serial Programming.
Arduino Nano Technical Specifications
Microcontroller ATmega328P

Operating Voltage 5V

Recommended Input Voltage for Vin pin 7-12V

Analog Input Pins 6 (A0 – A5)

Digital I/O Pins 14 (Out of which 6 provide PWM


output)
DC Current on I/O Pins 20 mA

DC Current on 3.3V Pin 50 mA

Flash Memory 32 KB (0.5 KB is used for Bootloader)


SRAM 2 KB

EEPROM 1 KB

Frequency (Clock Speed) 16 MHz

Communication IIC, SPI, USART

LED_BUILTIN 13

Length 68.6 mm

Width 53.4mm
INSTALLATION AND FAMILIARIZATION OF ARDUINO
IDE

Step 1: To install the Arduino IDE use the following link

https://www.arduino.cc/en/software

Click on windows win7 and newer option to download the file

Double click on the executable file highlighted in the oval and proceed to
installation.

During installation, it may ask you for permissions and throw


warnings also. Surely you cangive access to all permissions.

The installation may take several minutes depending on the configuration of


the system.
After
successful installation, one may find the green coloured icon of Arduino

ondesktop. Double click that to open a new sketch.

The basic Arduino sketch contains two parts


1. Setup function
2. Loop function

The code written inside setup function gets executed, line by line, only
once.
i.e if the users presses the RESET button on the Arduino UNO or
Nano, the code written under Setup will get executed only once.
Then directly the controller jumps to Loop functionand executes
the code for ever until a RESET takes place

Under the setup function, Pin declarations like INPUT or


OUTPUT, initialization of Serial modules like Serial.begin(baud
rate), initialization of OLED display, initialization of seven
segment module TM1637, initialization of DHT11 sensor etc. have
to be written.

Under “loop” function, the process that is to be done for ever is


written. The “loop” gets executed line by line until it reaches the
end and repeats from the first line of code writtenunder the “loop”
and so on.

About the pins on ARDUINO Nano:


There are a total of 14 digital input and output pins marked as
0,1,2,. 12
,13 known as
Digital pins. Out of the 14, pin 0 and 1 are used for Hardware
UART by the controller tocommunicate with the Personal Computer
used for programming. Hence pins 0 and 1 should not be used for
connecting digital input output devices.
CONTROL OF DIGITAL PINS IN SOFTWARE

******** ALL CODES WRITTEN HERE ARE CASE-SENSITIVE

************* DONOT CHANGE THE CASE OF ANY OF THE

LETTER IN THE NAME OF


THE FUNCTION

***************** pinMode(pin, INPUT); //

Declares the “pin” as input pinMode(pin, OUTPUT);

// Declares the “pin” as output

pinMode(pin, INPUT_PULLUP); // Declares the “pin” as input


with pin being held at HIGH (5volts for Arduino Nano)

Driving the pin to HIGH or LOW:

digitalWrite(pin, HIGH); // makes the “pin” at 5 Volt

digitalWrite(pin, LOW); // makes the “pin” at 0 Volt

There are 8 analog (INPUT) pins on Arduino named as


A0,A1,A2,A3,A4,A5,A6 and A7.They can be configured as digital
input and output pins also. In addition to this they are special pins as
they can read the analog signal voltages on the pins (< 5 volts). There
is a 10 bit ADC on the controller which multiplexes with all the 8 pins
on the Arduino Board.
There is an internal voltage reference of 1.1Volt which can be
invoked in the setup codewith the following syntax

analogReference (INTERNAL);

// SETS REFERENCE VOLTAGE FOR 10 BIT ADC AS1.1V


INTERNALLY

// RESOLUTION WILL BE 1.1/1024 = 1.07 milli


Volt
If no such reference is used, the controller assumes Vcc (=5 Volt) of the
supply as reference voltage and hence gives a resolution of 5/1024 = 4.88
milli Volt.

For using the ADC,

int val = analogRead(pin);

// “int” is type of variable, which is integer variable named as “val”

// pin refers to the pin number used as analog input, say A0,A5 etc.

Pins A4 and A5 are multiplexed with I2C communication pins


(I2C = Inter Integrated Communication protocol designed by
Philips semiconductors during 1982, which is usedfor
communication between devices on a circuit board, A4 is serial
data pin, A5 is serial clock pin)

All analog input pins, A0 though A7 can be configured as digital pins


also.
Ex:

digitalWrite(A5,OUTPUT)

;digitalWrite(A2,INPUT);

Installation of drivers for Nano:

Arduino Nano comes with an on board TTL – USB chip name


CH340G. It needs driversoftware to connect to the personal
computer.

Use the following link to download the driver


https://sparks.gogo.co.nz/ch340.html
Extract the contents of zip file named CH341SER.zip and click on install to
install the driver.
Now go to device manager using the following.

Connect the Nano board with USB cable to the Computer. Press
the Windows key +R toopen the run command. Then
typedevmgmt.msc
in the dialogue box. This will open the device manager of your computer

Here one may find the item “ports (Com &LPT)” and further
expansion of the tab shows the communication ports connected to
the computer, in the above case it is USB-SERIALCH340
(COM4), the COM number may vary from system to system.
Remember this COM port number.

Go to Arduino IDE and select tools/Board/ AVR


microcontrollers/Arduino Nano

Now select the processor,

(In my case it is ATMega328p with old

boot loader)Then select the PORT,


The port in my case is COM4.

Now it is everything ready to go with the Arduino Nano Board.

To open the Serial monitor/Plotter one may use the Tools menu and
select the option.
Or one may directly click on the lens symbol in the top-right corner of
the window highlighted below. The Serial plotter is graph plotter which
graphs the serial incomingdata. One may use even the keyboard short
cut keys like

ctrl+shift+Mor ctrl+shift+L

A view of the serial monitor. The settings at bottom show the change of
BAUD RATE,Auto Scroll and Time stamp

Baud rate must be the same as the one written in the code while
initializing the serialmodule using

Serial.begin(9600); or

Serial.begin(115200);
TINKERCAD PROCDURE TO DESIGN CIRCUITS

To get started, visit Tinkercad’s website and create an account or log into an existing one. Then
select Circuits on the left side of the screen:

After logging in to Tinkercad, click on "Circuits" on the left-hand side.

Select Create new Circuit on the next page and you be greeted with the following screen:

The "Create New Circuit" homepage in Tinkercad.


To familiarize yourself with the circuit design homepage, let's go over the areas I've marked
with numbers:

1. Change the name of your design here


2. This is the main toolbar. From the left to the right: Rotate the selected part clockwise,
delete the selected part, undo and redo your last action(s), create annotations and toggle
their visibility.
3. Some parts allow you to change their program. Click here to do so.
4. Start the simulation
5. Export your design to Autodesk EAGLE.
6. Choose the parts to display in the list below. I recommend choosing All.
7. These are the parts you can use.
8. The main work area. Drag and drop parts here to add them to your design.
9. Fit everything into the view.

The camera can be moved by holding down any mouse button and moving your mouse without
hovering a part.

Creating a Simple Circuit Design

Generate pseudo-random numbers between 0 and 6.

Start by dragging a breadboard into your design and place a 555-timer IC on it:

Start by adding the 555 timer IC to your design.

Proceed by adding the other components including:

• Two 1K resistors
• One 0.01 micro-Farad capacitor
• One polarized capacitor with a capacitance of 1 microfarad

You can enter the values of each part after placing them or by clicking on a part:

Add the additional components to the circuit design.

**Hint: You can use the R-key to rotate a selected part clockwise.

Now it’s time to connect the parts. Click anywhere to start a new connection. Click again to
create an endpoint. You can change the colour of the wire afterward. Connect the parts to create
a simple clock:
Add connections between the components.

You can add a voltage source and an oscilloscope to test your circuit. Hit Start simulation to
check your design:

Add a voltage source and oscilloscope to test the circuit.

You can change the oscilloscope settings by clicking on it.

Now that the clock is functional, let connect it to an Arduino and write some code. Add an
Arduino to your design and connect the timer pin three to pin two of the Arduino.

Don’t forget to connect the ground of the Arduino to the one on the breadboard. When you are
done, click the Code button in the top menu bar:
Click the "code" button to begin programming your build.

The code window will show the blocks editor by default. change it to text only by clicking the
dropdown-list and selecting text. Enter the example program code (found below) and start the
simulation. The LED on the Arduino should blink slowly.

int count=0;
void setup()
{
pinMode(13, OUTPUT);
pinMode(10, INPUT);
attachInterrupt(digitalPinToInterrupt(2), increment, RISING);
}

void loop()
{
if (count>250)
digitalWrite(13,1);
else
digitalWrite(13,0);
}
void increment (void)
{
if (count<500)
count+=1;
else
count=0;
}
After you are done, you can export your work to Autodesk EAGLE to create a PCB design or
you can generate a list of the necessary components and then build it. To display the list, click
the button next to your profile picture:

Export your list by clicking the icon next to your profile picture.
EXPERIMENT-1
MEASURE ANALOG SIGNAL FROM
TEMPERATURE SENSOR

Aim: To sense the temperature using temperature sensor.


Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. Temperature sensor [TMP36] –1
Theory:
TMP36 is a low voltage temperature sensor chip which generates an analog voltage at the
output which is linearly proportional to the Celsius temperature. Then convert this voltage into
temperature based on a 10 mV/°C scale factor. It has a shutdown capability which limits the
output current to less than 0.5 µA. It provides a supply current of up to 50 µA. This sensor
provides a highly precise temperature in centigrade. On top of that, the Celsius temperature
and an output voltage change linearly which makes it easy to compensate temperature/Voltage
variations. Having a linear relationship is helpful. Because we will not require any external
calibration circuit. Furthermore, it offers a very low output impedance. In short, it is very easy
to interface this sensor with ADCs or microcontrollers having built-in ADCs.
Specifications:
Power supply 2.7 V-5.5 V

Current consumption 50µA

Temperature range -40°C to 125°C

➢ This device operates using a single supply.


➢ It operates within a range of +2.7 V to +5.5 V.
➢ This chip is calibrated in Celsius therefore external calibration is not required. It
provides an output with ±2°C accuracy over the full temperature range.
➢ The operating range for temperature is -40 °C to +125 °C. However, it can operate up
to +150 °C temperature but accuracy reduces.
➢ TMP36 has an output scale factor of 10 mV/°C. The device works well when the
supply current is below 50 μA, which offers very low self-heating. It has an automatic
shutdown capability.
TMP36 IC is used mainly in thermostats and temperature measuring applications. It has low
output impedance and produces a linear output. It does not require external calibration and
therefore you don’t need external components. These devices can handle temperature ranges
of -40°C to 150°C. All these features make this chip suitable for use in a variety of temperature
measuring applications. These devices provide stable operation along with capacitive loads and
drive 10,000 pF load without creating any oscillations.
These less expensive sensors can generate interrupts in microprocessor applications. The
TMP36 chip measures the average temperature in industrial and environmental control
applications. Fire Alarms detect the rise in temperature through this device and start operating
when the temperature reaches a certain threshold limit. Different applications implement
thermal protection mechanisms using this chip. It monitors CPU and other power systems
provide thermal management by measuring temperature through TMP36.
➢ The table below shows its pins with a brief description.
Pin Description

Pin1 This is the pin for supplying power to the sensor. Connect a positive
(+V) power supply at this pin.

Pin2 This is the output that provides an analog voltage. This analog voltage
(Vout) is linearly proportional to temperature (in Celsius).

Pin3
This is the ground pin.
(GND)

To convert the output voltage to temperature in degree Celsius we will use the following
formula:
Temp (°C) = (Vout – 0.5) * 100
As we are using 5V Arduino, hence, to find Vout we will use the following formula:
Vout = (ADC sensor reading) * 5/1024
To convert degree Celsius temperature to Fahrenheit(F) we will use the following formula:
tempF = (tempC*9.0/5.0)*32.0;
Circuit Diagram:
Schematic View:

Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.

2. Then, drag one Temperature sensor TMP36 and place that in the breadboard, now
connect Power pin of the temperature sensor to the 5V supply of the Arduino board and
the ground pin to the ground and Vout pin to the A0 pin of the Arduino board.

3. Now go to code section and write your code and start your simulation to observe the
output.

4. After the simulation, we can observe that, while changing the scale of the temperature
sensor which is ranging from -40° C to 125°C the same value is displaying in the Serial
monitor as the scale value in the form of Celsius and Fahrenheit.

Code:
Using Formulas:
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
}

void loop()
{
int x = analogRead(A0);
float voltage = x*(5.0/1024.0);
float tempC = (voltage-0.5)*100;
Serial.print("Temperature :");
Serial.print(tempC);
Serial.print("C | ");

float tempF = (tempC*9.0/5.0)*32.0;

Serial.print(tempF);
Serial.println("F");

delay(1000);

}
➢ Code using MAP Function:
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
}

void loop()
{
Double x = map(analogread(A0), 20,358,-40,1250);
Serial.print("Temperature :");
Serial.print(temperatureC);
Serial.print("C | ");
Serial.print(temperatureF);
Serial.println("F");
Delay(1000);
}

Result:

Conclusion:
EXPERIMENT-2
GENERATE PWM OUTPUT

Aim: To generate PWM signals using Arduino.


Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. LEDs – 2
3. Resistors (220 ohm) – 2
4. Oscilloscopes (1ms) – 2
5. Multimeter – 1
Theory:
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital
means. Digital control is used to create a square wave, a signal switched between on and off.
This on-off pattern can simulate voltages in between the full Vcc of the board (e.g., 5 V on
UNO, 3.3 V on a MKR board) and off (0 Volts) by changing the portion of the time the signal
spends on versus the time that the signal spends off. The duration of "on time" is called the
pulse width. To get varying analog values, you change, or modulate, that pulse width. If you
repeat this on-off pattern fast enough with an LED for example, the result is as if the signal
is a steady voltage between 0 and Vcc controlling the brightness of the LED.
This duration or period is the inverse of the PWM frequency. In other words, with Arduino's
PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call
to analogWrite() is on a scale of 0 - 255, such that
analogWrite(255);
requests a 100% duty cycle (always on), and
analogWrite(127);
is a 50% duty cycle (on half the time)
On some microcontrollers PWM is only available on selected pins. Please consider the pinout
diagram of your board to find out which ones you can use for PWM. They are denoted with
a tilde sign (~).

Once you get this example running, grab your Arduino and shake it back and forth. What you
are doing here is essentially mapping time across the space. To our eyes, the movement blurs
each LED blink into a line. As the LED fades in and out, those little lines will grow and
shrink in length. Now you are seeing the pulse width.
Circuit Diagram:

Schematic View:

Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.

2. Then, drag two LEDs and place them in the breadboard, connect cathode pins of the
two LEDs to ground terminal of the breadboard and the anode terminal of one led to
the 13th pin i.e., non-PWM pin of the Arduino board with the help of resistor and anode
terminal of the second led to the 11th pin i.e., PWM pin of the Arduino board with the
help of a resistor.
3. Take two Oscilloscopes and connect negative terminals to the ground and one
oscilloscope positive terminal to the output of PWM pin led and the other oscilloscope
positive terminal to the output of non-PWM pin led.

4. Drag two multimeters and connect negative terminals to the ground and one multimeter
positive terminal to the output of PWM pin led and the other multimeter positive
terminal to the output of non-PWM pin led.

5. Now go to code section and write your code and start your simulation to observe the
output.

6. At the time of simulation, we can observe that the oscilloscope connected to the non-
PWM pin will not show any signals it will be in the low state and the Led will glow
when it goes to low state to high state and here we can also observe absence of PWM
signals. Now, the Oscilloscope which is connected to PWM pin will show a PWM
signals with percentage change in the duty cycle. In the multimeters we can observe the
voltages of both the non-PWM and PWM pins.

Code:
int x;
int ledR = 13;
int ledY = 11;
void setup()
{
pinMode(ledR, OUTPUT);
pinMode(ledY, OUTPUT);
Serial.begin(9600);
}

void loop()
{
for (x=0; x<256; x++)
{
Serial.print("x =");
Serial.println(x);
analogWrite(ledR, x);
analogWrite(ledY, x);
}
Serial.println("Finished");
}

Result:

Conclusion:
EXPERIMENT-3
DRIVE SINGLE CHARACTER GENERATION
ON HYPER TERMINAL
Aim: To drive a Single character generation on hyper terminal.
Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. LED – 1
3. Resistor (220 ohm) – 1
Theory:
The functions which help in receiving the data from the serial port and which helps in sending
the character value to the serial port without formatting them are namely ‘Serial.available()’,
‘Serial.read()’ and ‘Serial.write()’ whose details are discussed in the following section.
➢ Serial.available():
This particular function is always called before reading a data byte from the serial port of the
arduino. This function returns a positive value when the data byte reception is complete and
otherwise it returns a non-positive value. It serves the purpose of waiting till the data byte
reception is complete so that there should not be any error in reading the data byte.
The Serial.available() function can be used to simply check whether an entire data byte is
received or not as shown in the following statement
If (Serial.available())
{

} else;
The code will enter the ‘if condition’ only when the one byte of data is completely received in
the serial port of the Arduino board.
The Serial.available() function can be used for waiting till an entire data byte is received as
shown in the following statement
while (!Serial.available());
Please note the logic NOT symbol ‘!’ used with the function Serial available() so that the
condition remain true till the data reception is complete and becomes false when after the
completion of the data byte reception.
➢ Serial.read():
The function Serial.read() is used to read a data byte from the serial port of the Arduino. It can
return the data byte which can then be stored in a variable or used for some condition check
etc. The following statement shows how the data byte is read from the serial port and is stored
into a variable.
var = Serial.read();
The above statement should always appear after making a function call to the Serial.available()
to make sure that the data byte reception has been completed before reading the data. The
statement reads the data byte and stores the data byte to a variable ‘var’. The variable could be
of type integer or character.
➢ Serial. write():
The Serial.write() is also a function which is used to send the data byte to the serial port of the
Arduino like the functions Serial.print() and Serial.println() explained in the previous
project how to send data from the serial port of Arduino. Unlike actually printing the data value
in the serial port by sending the data byte after formatting it as ASCII character as the functions
Serial.print() and Serial.println() does, the function Serial.write() simply sends the data byte to
the serial port. For example, the statement given below will print the character ‘A’ in the serial
monitor software.
➢ Serial.write(65);
It is possible since the ASCII value of the character ‘A’ is 65. Suppose if one use the value ‘10’
as the parameter of the function Serial.write() then it won’t display anything in the serial
monitor software since there is no displayable ASCII character of the value 10, but if the same
parameter 10 is used with the function Serial.print() as shown in the following statement will
print ‘10’ in the serial port.
Serial.print(10);

Circuit Diagram:

Schematic View:
Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.

2. Then, drag one LED and place that in the breadboard, connect cathode pin of the LED
to ground terminal of the breadboard and the anode terminal of one led to the 13th pin
of the Arduino board along with the resistor.
3. Now go to code section and write your code and start your simulation to observe the
output.

4. After the simulation, we can observe that if we give certain single character as input in
the Hyper terminal it is displaying as output.

Code:
int led =13;
int inByte = 0;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
delay(100);
}

void loop()
{
if(Serial.available())
{
inByte = Serial.read();
Serial.write(inByte);
digitalWrite(led, HIGH);
delay(1000);
}
else
digitalWrite(led, LOW);
}

Result:

Conclusion:
EXPERIMENT-4
DRIVE A GIVEN STRING ON HYPER
TERMINAL

Aim: To drive a given String on hyper terminal.


Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. LED – 1
3. Resistor (220 ohm) – 1
Theory:
The functions which help in receiving the data from the serial port and which helps in sending
the character value to the serial port without formatting them are namely ‘Serial.available()’,
‘Serial.read()’ and ‘Serial.write()’ whose details are discussed in the following section.
➢ Serial.available():
This particular function is always called before reading a data byte from the serial port of the
arduino. This function returns a positive value when the data byte reception is complete and
otherwise it returns a non-positive value. It serves the purpose of waiting till the data byte
reception is complete so that there should not be any error in reading the data byte.
The Serial.available() function can be used to simply check whether an entire data byte is
received or not as shown in the following statement
If (Serial.available())
{

} else;
The code will enter the ‘if condition’ only when the one byte of data is completely received in
the serial port of the arduino board.
The Serial.available() function can be used for waiting till an entire data byte is received as
shown in the following statement
while (!Serial.available());
Please note the logic NOT symbol ‘!’ used with the function Serial available() so that the
condition remain true till the data reception is complete and becomes false when after the
completion of the data byte reception.
➢ Serial.read():
The function Serial.read() is used to read a data byte from the serial port of the arduino. It can
return the data byte which can then be stored in a variable or used for some condition check
etc. The following statement shows how the data byte is read from the serial port and is stored
into a variable.
var = Serial.read();
The above statement should always appear after making a function call to the Serial.available()
to make sure that the data byte reception has been completed before reading the data. The
statement reads the data byte and stores the data byte to a variable ‘var’. The variable could be
of type integer or character.

Circuit Diagram:

Schematic View:
Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.
2. Then, drag one LED and place that in the breadboard, connect cathode pin of the LED
to ground terminal of the breadboard and the anode terminal of one led to the 13th pin
of the Arduino board along with the resistor.
3. Now go to code section and write your code and start your simulation to observe the
output.
4. After the simulation, we can observe that if we give a string as input in the
HyperTerminal it is displaying as output.

Code:
String myName;
String msg = "what is your name?";
String msg2 = "Hello ";
String msg3 = " , Welcome";

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

void loop()
{
Serial.println(msg);
while(Serial.available()==0)
{
}
myName=Serial.readString();

Serial.print(msg2);
Serial.print(myName);
Serial.println(msg3);

delay(2000);
}

Result:

Conclusion:
EXPERIMENT-5
FULL DUPLEX LINK ESTABLISHMENT USING
HYPER TERMINAL
Aim: To generate full duplex link establishment using hyper terminal.
Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. LED – 3
3. Resistor (220 ohm) – 3
Theory:
The functions which help in receiving the data from the serial port and which helps in sending
the character value to the serial port without formatting them are namely ‘Serial.available()’,
‘Serial.read()’ and ‘Serial.write()’ whose details are discussed in the following section.
➢ Serial.available():
This particular function is always called before reading a data byte from the serial port of the
arduino. This function returns a positive value when the data byte reception is complete and
otherwise it returns a non-positive value. It serves the purpose of waiting till the data byte
reception is complete so that there should not be any error in reading the data byte.
The Serial.available() function can be used to simply check whether an entire data byte is
received or not as shown in the following statement
If (Serial.available())
{

} else;
The code will enter the ‘if condition’ only when the one byte of data is completely received in
the serial port of the Arduino board.
The Serial.available() function can be used for waiting till an entire data byte is received as
shown in the following statement
while (!Serial.available());
Please note the logic NOT symbol ‘!’ used with the function Serial available() so that the
condition remain true till the data reception is complete and becomes false when after the
completion of the data byte reception.
➢ Serial.read():
The function Serial.read() is used to read a data byte from the serial port of the Arduino. It can
return the data byte which can then be stored in a variable or used for some condition check
etc. The following statement shows how the data byte is read from the serial port and is stored
into a variable.
var = Serial.read();
The above statement should always appear after making a function call to the Serial.available()
to make sure that the data byte reception has been completed before reading the data. The
statement reads the data byte and stores the data byte to a variable ‘var’. The variable could be
of type integer or character.
Circuit Diagram:

Schematic View:

Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.
2. Then, drag three LEDs and place them in the breadboard, connect cathode pin of the
LEDs to ground terminal of the breadboard and the anode terminal of one led to the
10th ,11th ,12th pins of the Arduino board along with the resistor.
3. Now go to code section and write your code and start your simulation to observe the
output.
4. After the simulation, we can observe that if we give input as red then red color led
should glow, if we give green as input then green color led should glow and if we give
blue as input then blue color led should glow.
Code:
int redpin=12;
int greenpin=11;
int bluepin=10;
String mycolor, red, green, blue;
String msg = "What Color LED";

void setup()
{
Serial.begin(9600);
pinMode(redpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
}
void loop()
{
Serial.println(msg);
while(Serial.available()==0)
{
}
mycolor= Serial.readString();

if (mycolor == "red")
{

digitalWrite(redpin,HIGH);
digitalWrite(greenpin,LOW);
digitalWrite(bluepin,LOW);
delay(1000);
}
if (mycolor == "green")
{
digitalWrite(redpin,LOW);
digitalWrite(greenpin,HIGH);
digitalWrite(bluepin,LOW);
delay(1000);
}
if (mycolor == "blue")
{
digitalWrite(redpin,LOW);
digitalWrite(greenpin,LOW);
digitalWrite(bluepin,HIGH);
delay(1000);
}
}

Result:

Conclusion:
EXPERIMENT-6
Drive a given value on 8-bit DAC consisting of SPI
Aim: To drive a given value on 8-bit DAC consisting of SPI using Arduino.
Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. Resistors (1k) – 8
3. Resistors (2k) – 8
4. Oscilloscope (1000 micros) – 1
5. Bread board – 1
Theory:
Digital to Analog Converter (DAC) is a system that converts digital signal to its corresponding
analog signal. Vice versa, Analog to Digital Converter (ADC) is a system that converts analog
signal into digital ones. There are many applications of DAC such as audio, video, mechanical,
and communication purposes. Most of its use is for audio. The suitability of a DAC is
determined by its parameters some of which are resolution and sampling frequency, There are
several architectures of DAC. In this experiment, we will understand the R-2R Ladder (Resistor
to 2 Resistor Ladder) DAC.
The R-2R Ladder is one of the most popular DAC converters because of its simplicity. It
utilizes only two values of resistors and it can be extended to any number of bits.
Furthermore, its output impedance is always equal to R regardless of the number of bits,
greatly simplify filtering and further circuit design.
The number of levels are equal to two power the number of bits. In this project, 8 bits means
there will be 256 levels. We can calculate the maximum voltage output by this equation.

and the voltage output equation for R-2R DAC itself is this :

Circuit Diagram:
Schematic View:

Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.

2. Then, drag 8 resistors(1k) and place them in the breadboard in parallel, and then drag 8
resistors(2k) and connect them serially as shown in above circuit diagram. Now connect
the resistors to the 1,2,3,4,5,6,7,8 pins of the Arduino board.
3. Take one Oscilloscope and connect negative terminal to the ground and positive
terminal to the output of the DAC.

4. Now go to code section and write your code and start your simulation to observe the
output.

5. At the time of simulation, we can observe the waveforms in the Oscilloscope.


Code:
uint8_t level = 0;

void setup()
{
DDRD = B11111111; // set all Digital Pins on PORTD to OUTPUT
}

void loop()
{
//Rectangle
PORTD = 255; // 255 is 11111111 in binary
//delay(1);
PORTD = 0; // 0 is 00000000 in binary
//delay(1);

//Sawtooth
level %= 255;
PORTD = level++;

//Triangle
for(int i = -255 ; i < 255 ; i++){
PORTD = abs(i);
}
}

Conclusion:

Result:
EXPERIMENT-7
DRIVE STEPPER MOTOR USING ANALOG
GPIOs
Aim: To drive a stepper motor and rotate the shaft.
Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. 16 DC motor with encoder –1
3. Potentiometer – 250 k-ohm - 1
Theory:
A stepper motor is an electromechanical device it converts electrical power into mechanical
power. Also, it is a brushless, synchronous electric motor that can divide a full rotation into an
expansive number of steps. The motor’s position can be controlled accurately without any
feedback mechanism, as long as the motor is carefully sized to the application. Stepper motors
are similar to switched reluctance motors. The stepper motor uses the theory of operation for
magnets to make the motor shaft turn a precise distance when a pulse of electricity is provided.
The stator has eight poles, and the rotor has six poles. The rotor will require 24 pulses of
electricity to move the 24 steps to make one complete revolution. Another way to say this is
that the rotor will move precisely 15° for each pulse of electricity that the motor receives.

The construction of stepper motor is fairly related to a DC motor. It includes a permanent


magnet like Rotor which is in the middle & it will turn once force acts on it. This rotor is
enclosed through a no. of the stator which is wound through a magnetic coil all over it. The
stator is arranged near to rotor so that magnetic fields within the stators can control the
movement of the rotor.
The stepper motor working principle is Electro-Magnetism. It includes a rotor which is made
with a permanent magnet whereas a stator is with electromagnets. Once the supply is provided
to the winding of the stator then the magnetic field will be developed within the stator. Now
rotor in the motor will start to move with the rotating magnetic field of the stator. So this is the
fundamental working principle of this motor.

Circuit Diagram:
Schematic View:

Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.

2. Then, drag one DC motor with encoder and place that in the breadboard, now connect
Motor Positive pin to the 5V supply of the Arduino board and the motor negative pin
to the ground and channel-A, channel-B, Encoder power and Encoder ground pins to
the 8,9,10,11 pins of the Arduino board. Now, drag a potentiometer and place it in the
breadboard and connect terminal-1 to the 5v supply pin and terminal-2 to the ground
pin and wiper pin to the A0 pin of the Arduino board.

3. Now go to code section and write your code and start your simulation to observe the
output.

4. After the simulation, we can observe that, while varying the potentiometer the motor
shaft is rotating.
Code:
#include <Stepper.h>
// change this to fit the number of steps per revolution for your
Motor
int stepsPerRevolution = 200;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

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

void setup()
{
pinMode(A0, INPUT);
}

void loop() {
// read the sensor value:
int x = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(x, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0)
{
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}

Result:

Conclusion:
EXPERIMENT-8
DRIVE ACCELEROMETER AND DISPLAY THE
READINGS ON HYPER TERMINAL
Aim: To drive an Accelerometer and display the readings on hyper terminal.
Software used: Tinker Cad
Requirements: 1. Arduino Uno R3 – 1
2. LED –1
3. Tilt sensor – 1
4. resistor (220 ohm) – 1
Theory:
An accelerometer is an electromechanical device that is used to measure acceleration forces.
Such forces may be static like the force of gravity or, they may be dynamic as in the case of
mobile devices. An accelerometer comes in the form of a simple circuit for a large electronic
device. Despite the humble appearance, the accelerometer is made of different parts and works
in many ways, two of which are the Piezoelectric Accelerometer and the Capacitance
Accelerometer.
The applications of accelerometer extend to multiple disciplines, following are a few of its
uses:

• Accelerometers in laptops protect the hard drive from damage. If the laptop were to
fall while in use, the accelerometer would detect the fall and immediately turn off the
hard drive to avoid hitting the reading heads into the hard drive platter.
• Accelerometers in cars are used to detect car crashes and deploy airbags immediately.
• Smartphones rotate their display between landscape and portrait mode depending on
how one titles the phone.
Accelerometers are actively used in many electronics today, and it plays an active role in a
wide range of functionalities. In many cases, the presence of this simple sensor is unnoticed,
and the odds are that you may already be using a device with it.

Circuit Diagram:
Schematic View:

Procedure:
1. Open Tinker cad software in your system, go to new circuit then first drag and drop
Arduino board along with breadboard in the workspace.

2. Then, drag one tilt sensor and place that in the breadboard, now connect one pin of the
tilt sensor to the 7th pin and the other pin to the gnd pin of the Arduino board. Now drag
the led and place it in the breadboard and connect led cathode to the ground and anode
to the 13th pin of the Arduino board. Now, drag a 220 ohms resistor and connect one
terminal to the 5v supply of the Arduino board and connect another terminal to the
terminal1 of the tilt sensor.

3. Now go to code section and write your code and start your simulation to observe the
output.

4. After the simulation, we can observe that, while varying the scale on the tilt sensor the
angle is changing from -90 to +90 degrees.
Code:
int ledpin = 13;
int inpin = 7;

void setup()
{
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(inpin, INPUT);
}

void loop()
{
int val = digitalRead(inpin);
int angle = map(val, 0, 1, -90, 90);
Serial.print("Angle: ");
Serial.print(angle);
Serial.println(" degrees");
if (val ==0)
{
digitalWrite(ledpin,HIGH);
}
else
{
digitalWrite(ledpin, LOW);
}
}

Result:

Conclusion:

You might also like