Download as pdf or txt
Download as pdf or txt
You are on page 1of 79

DEPARTMENT OF ELECTRONICS AND

COMMUNICATION ENGINEERING

18ECO108J – EMBEDDED SYSTEM DESIGN USING ARDUINO

LAB MANUAL

SEMESTER V
(2020- 2021)

FACULTY OF ENGINEERING AND TECHNOLOGY


SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
(Under SECTION 3 of the UGC Act, 1956)
S.R.M. NAGAR, KATTANKULATHUR – 603203.
CHENGALPATTU DISTRICT

1
DEPARTMENT OF ELECTRONICS AND COMMUNICATION
ENGINEERING

18ECO108J – EMBEDDED SYSTEM DESIGN USING ARDUINO

LABORATORY MANUAL
Course Team
Course Teacher(s)

Mr. S.Vijay Ananth


Dr.R.Manohari
Mr.A.Joshua Jafferson

June 2021

2
Course Learning Rationale (CLR):

The purpose of learning this course is to:


CLR-1: Get to know about ARDUINO hardware details and environment
CLR-2: To understand the core elements of ARDUINO programming language
CLR-3: Create insights to the concepts of serial communication
CLR-4: To use common input and output devices
CLR-5: Apply the ARDUINO programming into real time applications

Course Learning Outcomes (CLO):

At the end of this course, learners will be able to:


CLO-1: Analyze the programming skill
CLO-2: Apply the real time data’s into digital
CLO-3: Interact with almost many devices
CLO-4: Learn techniques to handle timer delays and IO devices
CLO-5: Use and modifying the existing libraries

Performance Criteria
The committee has decided that the following performance criteria (Key topics/questions) will be
used for evaluation of CLR and CLO pertaining to this course.

PLO 1: Engineering Knowledge


PLO 2: Problem Analysis
PLO 3: Design & Development
PLO 4: Analysis, Design, Research
PLO 5: Modern Tool usage
PLO 9: Individual &Teamwork
PLO 11: Project Management & Finance

PSO 1: Professional Achievement


PSO 2: Project Management Techniques
PSO 3: Analyze & Research

3
Program Educational Objectives

Graduates will be able to:

PEO1: Establish themselves as successful and creative practicing professional engineers both
nationally and globally in related fields of Electronics and Communication Engineering.
PEO2: Apply the acquired knowledge and skills in solving real-world engineering problems; develop
novel technology and design products, which are economically feasible and socially relevant.
PEO3: Develop an attitude of lifelong learning for sustained career advancement and adapt to the
changing multidisciplinary profession.
PEO4: Demonstrate leadership qualities, effective communication skills, and to work in a team of
enterprising people in a multidisciplinary and multicultural environment with strong adherence to
professional ethics.

Course Articulation Matrix

PROGRAM
18ECO108J - Embedded
PROGRAM LEARNING OUTCOMES STUDENT
System Design Using ARDUINO OUTCOMES
S.NO COURSE LEARNING OUTCOMES 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3
1 Analyze the programming skill. H - - - - - - - - - - - - H H
Apply the real time data’s into
2 H H H H H - - - H - H - - H H
digital
Interact with almost many devices H
3 - H H H - - - H - H - H H -
Learn techniques to handle timer
4 H H H H - - - H - H - H H -
delays and IO devices H
Use and modifying the existing
5 H - H H H - - - H - H - H H -
libraries
.
Session Plan

Contact
S. No. Description of Topic References
hours
Unit-I 6
1. [2]
Introduction to Arduino platform, Block diagram, 1
2. AT mega 328p architecture 1 [2]
3. Pin function, Overview of main features-I/O ports 1 [2]
4
Features-timers, interrupts 1 [2]
5. Features-PWM, SERIAL PORT, ADC 1 [2]
6. Introduction to Arduino IDE, Writing, saving, [2]
1
compiling with IDE.
Unit-II: 6
7. [4] chapters 1, 3
Introduction To Arduino C, Arduino C Data Types 1
8. [4] chapter 4
Decision Making in C 1
9. [4] chapters 5, 6
Program Loops in C, Functions in C 1
10. [4] chapter 8
Introduction to Pointers 1
11. Using Pointers Effectively, Structures, Unions, and [4] chapters 9, 10
1
Data Storage
12. [4] chapter 12
Arduino Libraries 1

Unit-III: 6
13. Analog And Serial Communication, Introduction To [2]
1
Analog Communication
14. Pulse Width Modulation, RS232 1 [2]
15. I2C 2 [2]
16. SPI Protocol 1 [2]
17. Interfacing with sensors 1 [2]
Unit-IV: 6
18. IO Programming, Introduction To Timer/Counters 2 [1], [3]
19. [1], [3]
Timer programming 2

20. Interrupts, Interrupt programming, External interrupt 2 [1], [3]


Unit-V: 6
21. Case Studies, Wireless Communication Using Zigbee, 2 [1], [2]
Bluetooth
22. Robotics -Motor And Sensor, Security-RFID, 2 [1], [2]
Infrared,
23. Bio medical application, GPS Navigation 2 [1], [2]
Total contact hours 30

5
Sl.No Contac Referenc
Description of experiments
. t hours e
1. Getting Started With Adriano 2 5
2. GPIO LED 2 5
3. Display Interface-7 Segment 2 5
4. Serial Communication 2 5
5. Sensor Interfacing For Temperature Monitoring 2 5
6. Sensor Interfacing For Displacement Measurement 2 5
7. DC Motor 2 5
8. PWM Based Servo Motor Interfacing 2 5
9. I2C Communication 2 5
10. Interrupt Programming 2 5
11. Repeat/Revision Of Experiments 2 5
Actuators – Stepper Motor, Watch Dog Timer (Study 2 5
12.
experiments)
13. Construct mini project work 6
Total contact hours 30

References
1. Michael-Margolis,Arduino-Cookbook., Revised edition, O’Reilly,1st edition, 2011
2. D.Dale.Wheat, Arduino.Internals, TIA publication, 5th edition, 2011
3. James M. Fiore, Embedded Controllers Using C and Arduino, ARDUINO open source
community, 2018
4. Jack Purdum ,Beginning C for Arduino , Apress, 2012

5. Lab Manual of the course 18ECO108J, Department of ECE, SRM University

Assessment Methods

Compone Assessment Tool Weightage


nt
Course Learning Assessment T1 10%
Theory Course Learning Assessment T2 15 %
and Course Learning Assessment T3 15%
Lab Course Learning Assessment T4 10 %
(Surprise Test, Quiz & Assignment)
End-Semester Theory Examination 50 %

6
PREFACE

The 18ECO108J – EMBEDDED SYSTEM DESIGN USING ARDUINO Lab is designed


to
help students understand the basic principles of ARDUINO as well as giving them the insight on
design, simulation and hardware implementation of circuits. The main aim is to provide hands-on
experience to the students so that they are able to put theoretical concepts to practice.

The content of this course consists of two parts, ‘simulation’ and ‘hardwired’. Computer simulation is
stressed upon as it is a key analysis tool of engineering design. “Arduino IDE” and “Tinkercad”
software is used for simulation of experiments

Students will carry out design experiments as a part of the experiments list provided in this lab
manual. Students will be given a specific design problem, which after completion they will verify
using the simulation software or hardwired implementation.

7
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
Faculty of Engineering and Technology
Department of Electronics and Communication Engineering
Sub Code : 18ECO108J Semester : V
Sub Title : EMBEDDED SYSTEM DESIGN USING ARDUINO Lab Course Time: June-Dec ‘20
Pre- requisite : NIL
Co- requisite : NIL
PROGRAM LEARNING OUTCOMES
PLO 1: Engineering Knowledge
Experiment 1: Getting Started With ARDUINO
Experiment 2: GPIO LED
Experiment 3: Display Interface-7 Segment
Experiment 4: Serial Communication
Experiment 5: Sensor Interfacing For Temperature Monitoring
Experiment 6: Sensor Interfacing For Displacement Measurement
Experiment 7: DC Motor
Experiment 8: PWM Based Servo Motor Interfacing
Experiment 9: I2C Communication
Experiment 10: Interrupt Programming

PLO 2: Problem Analysis

Experiment 4: Serial Communication


Experiment 5: Sensor Interfacing For Temperature Monitoring
Experiment 6: Sensor Interfacing For Displacement Measurement
Experiment 8: PWM Based Servo Motor Interfacing
Experiment 9: I2C Communication
Experiment 10: Interrupt Programming

PLO 3: Design & Development

Experiment 4: Serial Communication


Experiment 5: Sensor Interfacing For Temperature Monitoring
Experiment 6: Sensor Interfacing For Displacement Measurement
Experiment 7: DC Motor
Experiment 8: PWM Based Servo Motor Interfacing
Experiment 9: I2C Communication
Experiment 10: Interrupt Programming
8
PLO 4: Analysis, Design, Research

Experiment 4: Serial Communication


Experiment 5: Sensor Interfacing For Temperature Monitoring
Experiment 6: Sensor Interfacing For Displacement Measurement
Experiment 7: DC Motor
Experiment 8: PWM Based Servo Motor Interfacing
Experiment 9: I2C Communication
Experiment 10: Interrupt Programming
PLO 5: Modern Tool usage

Experiment 4: Serial Communication


Experiment 5: Sensor Interfacing For Temperature Monitoring
Experiment 6: Sensor Interfacing For Displacement Measurement
Experiment 7: DC Motor
Experiment 8: PWM Based Servo Motor Interfacing
Experiment 9: I2C Communication
Experiment 10: Interrupt Programming
PLO 9: Individual &Teamwork

Experiment 4: Serial Communication


Experiment 5: Sensor Interfacing For Temperature Monitoring
Experiment 6: Sensor Interfacing For Displacement Measurement
Experiment 7: DC Motor
Experiment 8: PWM Based Servo Motor Interfacing
Experiment 9: I2C Communication
Experiment 10: Interrupt Programming

PLO 11: Project Management & Finance

Experiment 4: Serial Communication


Experiment 5: Sensor Interfacing For Temperature Monitoring
Experiment 6: Sensor Interfacing For Displacement Measurement
Experiment 7: DC Motor
Experiment 8: PWM Based Servo Motor Interfacing
Experiment 9: I2C Communication
Experiment 10: Interrupt Programming

9
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
Faculty of Engineering and Technology
Department of Electronics and Communication Engineering
Sub Code: 18ECO108J Semester : V
Sub Title: EMBEDDED SYSTEM DESIGN USING ARDUINO Lab Course Time: June-Dec ‘20
Pre- requisite : NIL
Co- requisite : NIL

PROGRAM EDUCATION OBJECTIVE VERSUS PROGRAM LEARNING OUTCOME

Program PEO1: PEO2: PEO3: PEO4:


Educational Graduates will Graduates will Graduates will Graduates will
Objective Establish Apply the Develop an Demonstrate
Program Learning themselves as acquired attitude of leadership
Outcomes successful and knowledge and lifelong learning qualities, effective
creative practicing skills in solving for sustained communication
professional real-world career skills, and to work
engineers both engineering advancement in a team of
nationally and problems; and adapt to the enterprising
globally in related develop novel changing people in a
fields of technology and multidisciplinary multidisciplinary
Electronics and design products, profession and multicultural
Communication which are environment with
Engineering economically strong adherence
feasible and to professional
socially relevant ethics
PLO1: Engineering
X X
Knowledge
PLO2: Problem
X X
Analysis
PLO3: Design &
X
Development
PLO4: Analysis,
Design, Research X X

PLO5:Modern Tool
usage X X X X

PLO9: Individual &


X X X
Teamwork
PLO11: Project
Management & X X
Finance

10
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
Faculty of Engineering and Technology
Department of Electronics and Communication Engineering
Sub Code: 18ECO108J Semester : V
Sub Title: EMBEDDED SYSTEM DESIGN USING ARDUINO Lab Course Time: June-Dec ‘20
Pre- requisite : NIL
Co- requisite : NIL

S. No. Experiments Details Equipment / Software Components Required


Required
1 Getting Started With Arduino IDE, Tinkercad -
Arduino
2 GPIO LED Arduino IDE, Tinkercad Resistors
3 Display Interface-7 Arduino IDE, Tinkercad Resistors
Segment
4 Arduino IDE, Tinkercad Resistors: As per design
Serial Communication
5 Sensor Interfacing For Arduino IDE, Tinkercad -
Temperature Monitoring
6 Sensor Interfacing For Arduino IDE, Tinkercad -
Displacement Measurement
7 DC Motor Arduino IDE, Tinkercad -
8 PWM Based Servo Motor Arduino IDE, Tinkercad -
Interfacing
9 I2C Communication Arduino IDE, Tinkercad -
10 Interrupt Programming Arduino IDE, Tinkercad -
11 Actuators – Stepper Motor -
12 Watch Dog Timer -

11
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
Faculty of Engineering and Technology
Department of Electronics and Communication Engineering
Sub Code: 18ECC205J Semester : V
Sub Title: EMBEDDED SYSTEM DESIGN USING ARDUINO Lab Course Time: June-Dec ‘20
Pre- requisite : NIL
Co- requisite : NIL
MAPPING OF COURSE LEARNING OUTCOMES WITH EXPERIMENTS:

CLO#1 CLO#2 CLO#3 CLO#4 CLO#5

Apply the Interact Learn Use and


List of
Analyze the real time with techniques to modifying
Experiments
programming data’s almost handle timer the existing
skill into many delays and IO libraries
digital devices devices
Getting Started
X
With Arduino
GPIO LED X
Display
Interface-7 X
Segment
Serial X
Communication
Sensor
Interfacing For X
Temperature
Monitoring
Sensor
Interfacing For X
Displacement
Measurement
DC Motor X
PWM Based
Servo Motor X
Interfacing
I2C X
Communication
Interrupt X
Programming
X
X

12
LABORATORY ORIENTATION

I. OVERALL PURPOSE

The laboratory portion of this course is designed to give the student practical experience in working
with ARDUINO. The laboratory integrate the theory taught in the lectures with practical design, and
should help the student to apply his or her knowledge of ARDUINO.

II. GENERAL COMMENTS

Every week before lab, each student should read over the laboratory design or experiment and work
out the various calculations, etc. that are outlined. The student should refer to the text as prescribed in
the course description for the fundamental theory.

Your grade will reflect how well you have prepared for the lab.

III LABORATORY AND EQUIPMENT MAINTENANCE

It is the responsibility of not only the laboratory staff, but also the students. A concerted effort to keep
the equipment in excellent condition and the working environment well-organized will result in a
productive and safe laboratory. There are useful guides one should follow to avoid the pitfalls in
measurement. Above all, keep in mind that safety is first!

IV. LABORATORY NOTEBOOK

Each student should maintain a laboratory notebook according to the following guidelines:

1. Obtain a printed material whose pages are consecutively numbered.


1. Write name, register number, course code and title, section, lab location, semester and course
teacher’s name on the cover sheet.
2. Record data by pen, not pencil. Do not use eraser.
3. Sign and date each page that has data.
4. Log all events, whether positive or negative, in the lab. This includes not only data, but also
problems encountered, equipment use, equipment settings, measurement technique, or any
departure from the procedure suggested by the lab manual.
5. Record instruments, their settings, and methods used to acquire data.
6. Label the axes of a graph with variable names, units, origin, and scales.
7. Demonstrate to the lab staff your understanding and achievement of the lab objectives.
8. Have the lab staff sign and date all data groups before completing each laboratory session. It
is the responsibility of both the staff and the student to make sure that the data is within
expectation before the student leaves each lab session.

13
V. PRE-LAB WORK

There are pre-lab works for each experiment. The pre work must be completed in the logbook before
entering the laboratory. The pre-lab work usually consists of some questions that is closely related to
the experimental work and is intended to prepare you for the lab. The labs are designed so that a
student who has done the pre-lab work should be able to complete the lab in the allotted time. If you
find that you are having difficulties completing labs then it is probably a good idea for you to do all of
the theoretical work (in addition to the assigned pre work) for the experiment before entering the lab.

To ensure that you can complete the experimental tasks within the allocated lab session, you could
collect all the parts and components from the Lab stores and build the circuits on breadboards before
starting the actual lab. Therefore you have more time on testing in the lab session.

VI. LABORATORY REPORTS

Lab reports will be submitted by each student at the beginning of the following lab period. The report
will be graded on clarity, legibility, and content, neither on length nor on the quality of the artwork.
Although the data is measured jointly, the text and analysis of the report must be original work and
may not be copied.

14
LABORATORY POLICIES AND REPORT FORMAT:
TITLE PAGE:

EXPERIMENT #

EXPERIMENT NAME

DATE

REPORT CONTENT:

I. OBJECTIVES (5 sentences max.)

II. EQUIPMENT (1 paragraph max.)

- include pertinent theory for experiment

III. DESIGN

IV. EXPERIMENT

- include schematic of all circuits built

- include names and values of all components actually used

- include all data recorded (tables, plots, printouts, observations)

V. POSTLAB QUESTIONS

- answer all the questions in the post lab component available at the end of each experiment in the
laboratory manual.

- the post lab questions are closely related to the experimental work you had done in the lab.

VI. SUMMARY

VII. EQUIPMENT AND LABORATORY MAINTENANCE

15
Be responsible for equipment and laboratory maintenance. For example:

1. Keep the lab and benches neat and organized.


1. Use the equipment properly. For example, use only the probes that have been compensated
for your oscilloscope with your oscilloscope. An oscilloscope and its matched probes are labelled by
the same number to help you keep using them together. Do not take the sleeve off the sensitive probe
tip and use the probe tip directly (e.g., by inserting the probe tip directly into a hole on a breadboard).
Many probes have been permanently damaged when used this way because a) the fragile tip is broken
by the severe probing strain, b) the probe accidentally falls to the ground, breaking the fragile tip, or c)
the probe sleeve is lost after it is removed from the probe tip. A short hook-up wire hooked to the
probe will allow fine probing without using the probe tip directly.
2. Return instruments, manuals, tools, components, cables, etc., to the proper storage location.
3. Bring defective equipment to the lab staff or laboratory maintenance staff for repair.
4. Notify the lab staff when the stock is about to run out of a certain component.

VIII. USEFUL LABORATORY PRACTICES


In general, keep the following points in mind:
1. Identify lab objectives. An experiment should not be treated as a cookbook procedure. Find a
rationale behind each step.
1. Come to the lab prepared. Preview the experiment as homework.
2. Keep a lab notebook to record all activities during all lab sessions.
3. Finish as much as possible before leaving. This includes acquiring data, interpreting data,
answering questions, and revolving uncertainties.
4. All data are real. If data look unbelievable, check all the steps carefully. Consult the lab staff.
5. Safety is first. Change instrument settings slowly. Observe the effect of the most recent change
before proceeding with more change. Set voltage/current/power limit. It is important that right from
the beginning of your lab work you consider the possible interactions between measuring instruments
and the device under test. For example:
6. The input impedance of meters can cause measurement error in high impedance circuits.
7. The input capacitance of scopes, scope probes, or connecting cables may have important high
frequency loading effects.
8. When using an oscilloscope to make accurate waveform or frequency response measurements
with an x10 probe, make sure the probe is properly compensated.
9. Learn to use the current limiting features of the laboratory power supplies to protest the device
under test from possible damage under short circuit conditions.

16
10. Make sure to have low impedance ground connections between the test instruments and your
“breadboard”. Avoid ground loops!
The list could go on much longer. It represents the pitfalls of doing electronics in the real world.

IX. SAFETY PRECAUTIONS AND LABORATORY RULES

To be responsible for your own safety and keep the laboratory in a good order, you must comply with
the rules below.

 Solid footwear must be worn by all students inside the laboratory. Staffs are required by the
university to ensure that everyone in the laboratory is wearing solid footwear. Students with bare feet,
thongs, sandals, or other forms of open footwear will not be allowed into the laboratory.
 No smoking, drinking, or eating is permitted in the laboratory (this includes chewing gum and
confectionaries).
 Always have your circuits checked by a demonstrator before switching on, and always switch
the power off immediately after taking measurements.
 Act sensibly and tidy up after yourself.
 There is a safety switch on each bench which switches power to (and protects) the GPO's
(general purpose outlets/power points).
 Under no circumstances should you attempt to remove any of the panels on the bench. There is
a 220 volt supply behind them which could be lethal.
 You should not take equipment from another bench. If something is faulty (or missing) ask the
lab staff for assistance.

17
SAFETY

Safety in the electrical laboratory, as everywhere else, is a matter of the knowledge of potential
hazards, following safety precautions, and common sense. Observing safety precautions are important
due to pronounced hazards in any electrical/computer engineering laboratory. Death is usually certain
when 0.1 ampere or more flows through the head or upper thorax and have been fatal to persons with
coronary conditions. The current depends on body resistance, the resistance between body and ground,
and the voltage source. If the skin is wet, the heart is weak, the body contact with ground is large and
direct, then 40 volts could be fatal. Therefore, never take a chance on "low" voltage. When working in
a laboratory, injuries such as burns, broken bones, sprains, or damage to eyes are possible and
precautions must be taken to avoid these as well as the much less common fatal electrical shock. Make
sure that you have handy emergency phone numbers to call for assistance if necessary. If any safety
questions arise, consult the lab demonstrator or technical assistant/technician for guidance and
instructions. Observing proper safety precautions is important when working in the laboratory to
prevent harm to yourself or others. The most common hazard is the electric shock which can be fatal if
one is not careful.

ELECTRIC SHOCK

Shock is caused by passing an electric current through the human body. The severity depends mainly
on the amount of current and is less function of the applied voltage. The threshold of electric shock is
about 1 mA which usually gives an unpleasant tingling. For currents above 10 mA, severe muscle pain
occurs and the victim can't let go of the conductor due to muscle spasm. Current between 100 mA and
200 mA (50 Hz AC) causes ventricular fibrillation of the heart and is most likely to be lethal. What is
the voltage required for a fatal current to flow? This depends on the skin resistance. Wet skin can have
a resistance as low as 150 Ohm and dry skin may have a resistance of 15 kOhm. Arms and legs have a
resistance of about 100 Ohm and the trunk 200 Ohm. This implies that 240 V can cause about 500 mA
to flow in the body if the skin is wet and thus be fatal. In addition skin resistance falls quickly at the
point of contact, so it is important to break the contact as quickly as possible to prevent the current
from rising to lethal levels.

18
EQUIPMENT GROUNDING

Grounding is very important. Improper grounding can be the source of errors, noise and a lot of
trouble. Here we will focus on equipment grounding as a protection against electrical shocks. Electric
instruments and appliances have equipments casings that are electrically insulated from the wires that
carry the power. The isolation is provided by the insulation of the wires. However, if the wire
insulation gets damaged and makes contact to the casing, the casing will be at the high voltage
supplied by the wires. If the user touches the instrument he or she will feel the high voltage. If, while
standing on a wet floor, a user simultaneously comes in contact with the instrument case and a pipe or
faucet connected to ground, a sizable current can flow through him or her. However, if the case is
connected to the ground by use of a third (ground) wire; the current will flow from the hot wire
directly to the ground and bypass the user.

Equipment with a three wire cord is thus much safer to use. The ground wire (3rd wire) which is
connected to metal case is also connected to the earth ground (usually a pipe or bar in the ground)
through the wall plug outlet.

Always observe the following safety precautions when working in the laboratory:

1. Do not work alone while working with high voltages or on energized electrical equipment or
electrically operated machinery like a drill.
1. Power must be switched off whenever an experiment or project is being assembled, disassembled,
or modified. Discharge any high voltage points to grounds with a well-insulated jumper.
2. Remember that capacitors can store dangerous quantities of energy.
3. Make measurements on live circuits or discharge capacitors with well insulated probes keeping
one hand behind your back or in your pocket. Do not allow any part of your body to contact any
part of the circuit or equipment connected to the circuit.
4. After switching power off, discharge any capacitors that were in the circuit. Do not trust
supposedly discharged capacitors. Certain types of capacitors can build up a residual charge after
being discharged. Use a shorting bar across the capacitor, and keep it connected until ready for use.
If you use electrolytic capacitors, do not:
 put excessive voltage across them
 put ac across them
 connect them in reverse polarity
1. Take extreme care when using tools that can cause short circuits if accidental contact is made to
other circuit elements. Only tools with insulated handles should be used.

19
5. If a person comes in contact with a high voltage, immediately shut off power. Do not attempt to
remove a person in contact with a high voltage unless you are insulated from them. If the victim is
not breathing, apply CPR immediately continuing until he/she is revived, and have someone dial
emergency numbers for assistance.
6. Check wire current carrying capacity if you will be using high currents. Also make sure your leads
are rated to withstand the voltages you are using. This includes instrument leads.
7. Avoid simultaneous touching of any metal chassis used as an enclosure for your circuits and any
pipes in the laboratory that may make contact with the earth, such as a water pipe. Use a floating
voltmeter to measure the voltage from ground to the chassis to see if a hazardous potential
difference exists.
8. Make sure that the lab instruments are at ground potential by using the ground terminal supplied
on the instrument. Never handle wet, damp, or ungrounded electrical equipment.
9. Never touch electrical equipment while standing on a damp or metal floor.
10. Wearing a ring or watch can be hazardous in an electrical lab since such items make good
electrodes for the human body.
11. When using rotating machinery, place neckties or necklaces inside your shirt or, better yet, remove
them.
12. Never open field circuits of D-C motors because the resulting dangerously high speeds may cause
a "mechanical explosion".
13. Keep your eyes away from arcing points. High intensity arcs may seriously impair your vision or a
shower of molten copper may cause permanent eye injury.
14. Never operate the black circuit breakers on the main and branch circuit panels.
15. In an emergency all power in the laboratory can be switched off by depressing the large red button
on the main breaker panel. Locate it. It is to be used for emergencies only.
16. Chairs and stools should be kept under benches when not in use. Sit upright on chairs or stools
keeping the feet on the floor. Be alert for wet floors near the stools.
17. Horseplay, running, or practical jokes must not occur in the laboratory.
18. Never use water on an electrical fire. If possible switch power off, then use CO2 or a dry type fire
extinguisher. Locate extinguishers and read operating instructions before an emergency occurs.
19. Never plunge for a falling part of a live circuit such as leads or measuring equipment.
20. Never touch even one wire of a circuit; it may be hot.

20
21. Avoid heat dissipating surfaces of high wattage resistors and loads because they can cause severe
burns.
22. Keep clear of rotating machinery.
PRECAUTIONARY STEPS BEFORE STARTING AN EXPERIMENT SO AS NOT TO WASTE TIME
ALLOCATED

a) Read materials related to experiment beforehand as preparation for pre-lab quiz and experimental
calculation.
b) Make sure that apparatus to be used are in good condition. Seek help from technicians or the lab
demonstrator in charge should any problem arises.
 Power supply is working properly ieImax (maximum current) LED indicator is disable. Maximum
current will retard the dial movement and eventually damage the equipment. Two factors that will
light up the LED indicator are short circuit and insufficient supply of current by the equipment
itself. To monitor and maintain a constant power supply, the equipment must be connected to
circuit during voltage measurement. DMM are not to be used simultaneously with oscilloscope to
avert wrong results.
 Digital millimetre (DMM) with low battery indicated is not to be used. By proper connection,
check fuses functionality (especially important for current measurement). Comprehend the use of
DMM for various functions. Verify measurements obtained with theoretical values calculated as
it is quite often where 2 decimal point reading and 3 decimal point reading are very much
deviated.
 The functionality of voltage waveform generators are to be understood. Make sure that
frequency desired is displayed by selecting appropriate multiplier knob. Improper settings (i.e.
selected knob is not set at minimum (in direction of CAL – calibrate) at the bottom of knob)
might result in misleading values and hence incorrect results. Avoid connecting oscilloscope
together with DMM as this will lead to erroneous result.
 Make sure both analog and digital oscilloscopes are properly calibrated by positioning sweep
variables for VOLT / DIV in direction of CAL. Calibration can also be achieved by standalone
operation where coaxial cable connects CH1 to bottom left hand terminal of oscilloscope. This
procedure also verifies coaxial cable continuity.
c) Internal circuitry configuration of breadboard or Vero board should be at students’ fingertips (i.e.
holes are connected horizontally not vertically for the main part with engravings disconnecting in-
line holes).

21
d) Students should be rest assured that measured values (theoretical values) of discrete components
retrieved i.e. resistor, capacitor and inductor are in accordance the required ones.
e) Continuity check of connecter or wire using DMM should be performed prior to proceeding an
experiment. Minimize wires usage to avert mistakes.

Laboratory Report Cover Sheet

SRM Institute of Science and Technology


Faculty of Engineering and Technology
Department of Electronics and Communication Engineering
18ECO108J EMBEDDED SYSTEM DESIGN USING ARDUINO
Fifth Semester, 2020-21 (odd semester)

Name :
Register No. :
Day / Session :
Venue :
Title of Experiment :
Date of Conduction :
Date of Submission :

Particulars Max. Marks Marks Obtained


Pre-lab questions 10
In-lab experiment 20
Post-lab questions 10
Total 40

REPORT VERIFICATION
22
Date :

Staff Name :

Signature :

TABLE OF CONTENTS

Sl. No. Experiment Name Page No.

1. Getting Started With ARDUINO 24


2. GPIO LED 34 26
3. Display Interface-7 Segment 29
4 Serial Communication 35
5. Timer Programing 42
6. Sensor Interfacing For Displacement Measurement 47
7. DC Motor 51
8. PWM Based Servo Motor Interfacing 57
9. I2C Communication 61
10 Interrupt Programming 65
11 Sensor Interfacing For Temperature Monitoring
12 LCD Interfacing

23
Exp. 1: Getting Started With ARDUINO
Aim:
To blink the on-board LED with 75% Duty cycle and total time period of 1000ms.
Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinkercad online Virtual Lab (For simulatuion)

Theory:

Arduino is an open-source prototyping platform in electronics based on easy-to-use hardware and


software. Subtly speaking, Arduino is a microcontroller based prototyping board which can be used in
developing digital devices that can read inputs like finger on a button, touch on a screen, light on a
sensor etc. and turning it in to output like switching on an LED, rotating a motor, playing songs
through a speaker etc.

Since this experiment uses onboard LED, no hardware interface is required.

Code Structure

void setup() {
// put your setup code here, to run once:

pinMode(13, OUTPUT);

24
void loop() {
// put your main code here, to run repeatedly:

digitalWrite(13, HIGH);

delay(750); // Wait for 750 millisecond(s)

digitalWrite(13, LOW);

delay(250); // Wait for 250 millisecond(s)

Bare minimum code

 setup: It is called only when the Arduino is powered on or reset. It is used to initialize
variables and pin modes
 loop: The loop functions runs continuously till the device is powered off. The main logic of
the code goes here. Similar to while (1) for micro-controller programming.

PinMode

 A pin on Arduino can be set as input or output by using pinMode function.


 pinMode(13, OUTPUT); // sets pin 13 as output pin
 pinMode(13, INPUT); // sets pin 13 as input pin

Pre lab Questions:


1. How many GPIO pins are there in Arduino Uno Development Board?
2. Write about Expansion connectors in Arduino Uno Development Board.

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB cable.
2. Write the code and compile it in Arduino IDE.
3. Select USB port in Arduino IDE.
4. Select Arduino Uno Development Board in Arduino IDE.
5. Download the code into Arduino Uno Development Board
6. Run the code in Arduino Uno Development Board.
7. Observe and verify the output.

Post lab Questions:


1. What register is used to configure the IO port direction?
2. What statement is used to send a digital data in IO pin Using Arduino IDE?

Output:

Paste your Screenshots here.

Result:
25
Exp. 2: GPIO LED

Aim:
To control the brightness of the LED which is connected in any of the PWM pin.

Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinkercad online Virtual Lab (For simulation)

Theory:

Led blinking is the most beginner & easy step to start your experiment with Arduino. Let’s get started.
Firstly, identify anode(+ve) & cathode (-ve) leg of LED. Following diagram gives a clear idea of LED.

A LED is connected to the GPIO pin 9 through a ballast resister to limit the current through the
LED.

26
Code Structure

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Bare minimum code

 setup: It is called only when the Arduino is powered on or reset. It is used to initialize
variables and pin modes
 loop: The loop functions runs continuously till the device is powered off. The main logic of
the code goes here. Similar to while (1) for micro-controller programming.

PinMode

 A pin on Arduino can be set as input or output by using pinMode function.


 pinMode (9, OUTPUT); // sets pin 9 as output pin
 pinMode (9, INPUT); // sets pin as input pin

Pre lab Questions:


1. How many analog pins are there in Arduino Uno Development Board?
2. Which of general purpose working register are used as 16-bit indirect address register pointers?

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB
cable.
2. Write the code and compile it in Arduino IDE.
3. Select USB port in Arduino IDE.
4. Select Arduino Uno Development Board in Arduino IDE.
5. Download the code into Arduino Uno Development Board
6. Run the code in Arduino Uno Development Board.
7. Observe and verify the output.

Post lab Questions:

1. What are the register associated with each port?


27
2. What statement is used to send an analog data in IO pin Using Arduino IDE?

Output:

Paste your Screenshots here.

Code
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.

The analogWrite() function uses PWM, so if you


want to change the pin you're using, be sure to
use another PWM capable pin. On most Arduino,
the PWM pins are identified with a "~" sign,
like ~3, ~5, ~6, ~9, ~10 and ~11.
*/

int brightness = 0;

void setup()
{
pinMode(9, OUTPUT);
}

void loop()
{
for (brightness = 0; brightness <= 255; brightness += 5) {
analogWrite(9, brightness);
delay(30); // Wait for 30 millisecond(s)
}
for (brightness = 255; brightness >= 0; brightness -= 5) {
analogWrite(9, brightness);
delay(30); // Wait for 30 millisecond(s)
}}

Result:

28
Exp. 3: DISPLAY INTERFACE-7 SEGMENT
Aim:
To display 7-segment LED
Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinkercad online Virtual Lab (For simulatuion)

Theory:

A seven segment display got its name from the very fact that it got seven illuminating
segments. Each of these segments has a LED (Light Emitting Diode), hence the lighting. The
LEDs are so fabricated that lighting of each LED is contained to its own segment. The
important thing to notice here that the LEDs in any seven segment display are arranged in
common anode mode (common positive) or common cathode mode (common negative).

29
Code Structure

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Pre lab Questions:


1. How are LEDs connected in 7 segment?
2. What is common cathode 7 segment?

Lab Procedure:
30
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB
cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Post lab Questions:

1. Give the syntax of the switch statement.


2. Which are digital PWM pins?

Output:

Paste your Screenshots here.

Code.
#define segA 6//connecting segment A to PIN6
#define segB 7// connecting segment B to PIN7
#define segC 8// connecting segment C to PIN8
#define segD 9// connecting segment D to PIN9
#define segE 10// connecting segment E to PIN10
#define segF 11// connecting segment F to PIN11
#define segG 12// connecting segment F to PIN12

int COUNT=0;//count integer for 0-9 increment


void setup()

{
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);

31
void loop()

switch (COUNT)
{
case 0://when count value is zero show”0” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;

case 1:// when count value is 1 show”1” on disp

digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

case 2:// when count value is 2 show”2” on disp

digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;

case 3:// when count value is 3 show”3” on disp

digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
32
break;

case 4:// when count value is 4 show”4” on disp

digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 5:// when count value is 5 show”5” on disp

digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);

break;

case 6:// when count value is 6 show”6” on disp

digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 7:// when count value is 7 show”7” on disp

digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

33
case 8:// when count value is 8 show”8” on disp

digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 9:// when count value is 9 show”9” on disp

digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

if (COUNT<10)
{
COUNT++;
delay(1000);///increment count integer for every second
}

if (COUNT==10)
{
COUNT=0;// if count integer value is equal to 10, reset it to zero.
delay(1000);
}

Result:

34
Exp. 4: SERIAL COMMUNICATION

Aim:
1. To establish serial communication between Arduino Uno and PC
2. To receive a number through serial communication and display it in 7 segment display.

Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinkercad online Virtual Lab (For simulatuion)

Theory:

Arduino is an open-source prototyping platform in electronics based on easy-to-use hardware and


software. The communication between arduino and computer is established at a specific baud rate. The
baud rate specifies how fast the data is sent over the serial line or in simple terms, the speed of serial
communication. Some common rates for UART are 9600 baud, 11520 baud etc. To start serial
communication the baud rate set for arduino and computer must be the same, if baud rate for both is
set at 9600 baud, then to transmit 1 bit of data it will take 1/9600 sec = 0.014 msec.The main purpose
of this serial communication is to transfer the sketch from computer to Arduino, send information to
computer etc.The most common type of serial communication protocol is UART i.e. Universal
Asynchronous Receiver Transmitter. The UART connection requires a 9 pin DE – 9 Connector. But,
most modern computers and laptops do not include these COM ports. Hence, if we want to connect
our microcontrollers like 8051, AVR or ARM, we need to use an external serial to USB converter.But
Arduino UNO has an on board serial to USB converter and hence we can directly connect the Arduino
to the computer. Using this USB connection and Arduino IDE, we can send data to Arduino or receive
data from Arduino. This data can be monitored with the help of Serial Monitor in the Arduino IDE.

35
Code Structure

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Bare minimum code

 setup : It is called only when the Arduino is powered on or reset. It is used to initialize variables and
pin modes
 loop : The loop functions runs continuously till the device is powered off. The main logic of the code
goes here. Similar to while (1) for micro-controller programming.

PinMode

 A pin on arduino can be set as input or output by using pinMode function.


 pinMode(13, OUTPUT); // sets pin 13 as output pin
 pinMode(13, INPUT); // sets pin 13 as input pin

Pre Lab:
1. What is serial communication?
2. What is baud rate?

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB
cable.
2. Write the code and compile it in Arduino IDE.
3. Select USB port in Arduino IDE.
4. Select Arduino Uno Development Board in Arduino IDE.
5. Download the code into Arduino Uno Development Board
6. Run the code in Arduino Uno Development Board.
7. Observe and verify the output.

Post Lab:
1. How do you establish serial communication between Arduin and PC?
2. In the code, explain the statement
COUNT = Serial.read()-48;

Output:

Paste your Screenshots here.


36
CODE:

#define segA 6//connecting segment A to PIN6


#define segB 7// connecting segment B to PIN7
#define segC 8// connecting segment C to PIN8
#define segD 9// connecting segment D to PIN9
#define segE 10// connecting segment E to PIN101.
#define segF 11// connecting segment F to PIN11
#define segG 12// connecting segment G to PIN12
int COUNT=7;//count integer for 0-9 increment
void setup()

{
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);

//Initialize serial and wait for port to open:


Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Welcome all. I am Arduino");

}
void loop()
{
switch (COUNT)
{
case 0://when count value is zero show”0” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;

case 1:// when count value is 1 show”1” on disp


digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
37
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);

break;

case 2:// when count value is 2 show”2” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, LOW);

digitalWrite(segD, HIGH);

digitalWrite(segE, HIGH);

digitalWrite(segF, LOW);

digitalWrite(segG, HIGH);

break;

case 3:// when count value is 3 show”3” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, LOW);

digitalWrite(segF, LOW);

digitalWrite(segG, HIGH);

break;

case 4:// when count value is 4 show”4” on disp

digitalWrite(segA, LOW);
38
digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, LOW);

digitalWrite(segE, LOW);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

case 5:// when count value is 5 show”5” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, LOW);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, LOW);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

case 6:// when count value is 6 show”6” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, LOW);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, HIGH);

digitalWrite(segF, HIGH);

39
digitalWrite(segG, HIGH);

break;

case 7:// when count value is 7 show”7” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, LOW);

digitalWrite(segE, LOW);

digitalWrite(segF, LOW);

digitalWrite(segG, LOW);

break;

case 8:// when count value is 8 show”8” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, HIGH);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

case 9:// when count value is 9 show”9” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);
40
digitalWrite(segD, HIGH);

digitalWrite(segE, LOW);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

break;

}
while(!Serial.available());
COUNT = Serial.read()-48;
Serial.println(COUNT);

/*
if (COUNT<10)
{
COUNT++;
delay(1000);///increment count integer for every second
}
if (COUNT==10)
{
COUNT=0;// if count integer value is equal to 10, reset it to zero.
delay(1000);
}*/
}

Result:

41
Laboratory Report Cover Sheet

SRM Institute of Science and Technology


Faculty of Engineering and Technology
Department of Electronics and Communication Engineering
18ECO108J EMBEDDED SYSTEM DESIGN USING ARDUINO
Sixth Semester, 2020-21 (Even Semester)

Name :
Register No. : RA
Day / Session : DAY-4/AN
Venue :
Title of Experiment : EXPERIMENT-4 (TIMER PROGRAMMING)
Date of Conduction : 05.02.2021
Date of Submission :

Particulars Max. Marks Marks Obtained


Pre-lab questions 10
In-lab experiment 20
Post-lab questions 10
Total 40

REPORT VERIFICATION

Date :

Staff Name :

Signature :

42
Experiment 4: TIMER PROGRAMMING

Aim:
1. To generate delay using timer programming using Arduino Uno and PC

Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinkercad online Virtual Lab (For simulation)

Theory:

Timer in AVR
Many time we need our Application to wait for some time and retain its stage as it is – it is that time
when we need to delay our CPU i.e waste our CPU cycle. A timer is simply a register of 8 or 16 bit
size. And these values like 16 or 8 bit signifies the Resolution of a timer i.e till what value it can
count. It basically means it can count from 0 to 2^8 255. . Likewise, a 16 bit timer can hold a value
between 0 to 65535.

This Timer register(Timer value storing register) has a property of increasing or decreasing its value
without any intervention by CPU at a rate frequently defined by the user. This frequency (at which the
timer register increases/decreases) is known as the Timer Frequency. Note that Timer Frequency can
be less than or equal to the CPU clock frequency.

ATmega328P have 3 different timers, of which the simplest one is TIMER0, with an 8 bit (0-255)
resolution.

Basic working of timer in AVR


Software loads the count register with an initial value between 0x00 and 0xFF (in case of 8-bit). Each
subsequent transition of the input clock signal increments that value.

Up mode– it counts up from the initial value toward 0xFF.


Down mode- A down counter counts down, toward 0x00.

When the counter overflows or reaches 0x00, the output signal is asserted. The output signal may
thereby trigger an interrupt at the processor or set a bit/Flag that the processor can read. To restart the
timer, software reloads the count register with the same or a different initial value.

Frequently used terms in Timer

43
Prescaler: As we already discussed that the Timer frequency can be less than or equal to the CPU clock
frequency. Then how are we decide or set the timer frequency as per our needs? Here the “Prescaler”
comes in picture. This is actually a method of generating the clock frequency for the TIMER from the
CPU clock by dividing it with a suitable number.

Overflow: The timer in some conditions automatically take an action or informs the CPU to suspend
the current execution, by an Interrupt signal. One example of this is the Timer Overflow, i.e an 8 bit
timer has counted upto its maximum value (255) and revert to 0.Here, the timer sends a signal or
interrupt to the CPU to break its current execution and execute the ISR (interrupt service routine). ISR
is a function that the CPU should execute whenever an interrupt occurs. The programmer must write
into the ISR to handle the interrupt.

After understanding the terms like Prescaler and overflow comes the next point i.e what are the
registers involved in programming a timer according to our needs.The registers description can be
found in Register Description section of datasheet.

Register description
So the registers involved are as following:

1. TCCRxA – Timer/Counter Control Register A

This register controls the mode in which Timer will work. On setting and resetting the value
of COM0A1:0 bits we can also control the behaviour of output compare pin (OC0A). However, note
that the data direction register (DDR) bit corresponding to the OC0A pin must be set in order to enable
the output driver.

However WGM01:0( Waveform Generation Mode) combined with the WGM02 bit found in the
TCCR0B register are used to control the counting sequence of the counter, the source for maximum
(TOP) counter value, and what type of waveform would be generated. And thus decide in which mode
timer will operate.

In AVR we have various modes of operations for a timer. And those are as following-

1. Normal Mode

2. Clear Timer on Compare Match (CTC) Mode


44
3. Fast PWM Mode

4. Phase Correct PWM Mode

Thus according to how your counting will start and which register you want to use for counting you
can decide in which mode you want your timer to count.

2. TCCR0B – Timer/Counter Control Register B

This register is used to set the pre-scalar and along with TCCRxA we can decide the type of waveform
generated. CS02:0 (Clock Select) these three are clock select bits which are used to select the clock
source to be used by the Timer/Counter.

3. TCNT0 – Timer/Counter Register


The Timer/Counter register gives direct access, both for read and write operations. This register is
used for storing the value of count till where you want your timer to count.

4. OCR0A – Output Compare Register A


The output compare register A contains an 8-bit value that is continuously compared with the counter
value (TCNT0). A match can be used to generate an output compare interrupt, or to generate a
waveform output on the OC0A pin. Thus this is used when we want to generate waveform using timer.

5. OCR0B – Output Compare Register B


The output compare register B contains an 8-bit value that is continuously compared with the counter
value (TCNT0). A match can be used to generate an output compare interrupt, or to generate a
waveform output on the OC0B pin. Used alongside OCR0A for generating waveforms.

45
6. TIMSK0 – Timer/Counter Interrupt Mask Register

This register is used for setting up the local timer interrupt. If I bit is set then after setting bits here the
timer interrupt is enabled.

7. TIFR0 – Timer/Counter 0 Interrupt Flag Register


This register contains timer flags that are used when we use timer in polling mode so as to keep
continuous watch on their values.

So these are all registers involved in programming a timer.

The mathematics behind how timer works in AVR


Since we know that our clock source is 16 MHZ in case of atmega328P so if want to create a delay of
1 sec without prescaler then we need to do following calculations:

Time period taken in one clock tick =1/frequency = 1/ (16*10^6) = 0.0625 us =0.0625*10^-6

So to complete 1 sec your clock will tick for 1/ (0.0625*10^-6) = 16,000,000 times.

Thus if you are creating a delay for 1 sec then you need to count for 16,000,000 times. But since our 8
bit timer can only count up-to 255 and our 16 bit timer can only count up-to 65,536 so we need some
other method to reduce the count. To do that our prescaler comes into picture.

So our controller has various prescaler figure below-

So, we will use divide by 1024 now when we divide our clock frequency

i.e 16MHZ by 1024 = (16*10^6)/1024=15,625

Time period taken in one clock tick =1/frequency = 1/15,625 = 64 us =64 *10^-6
46
So to complete 1 sec your clock will tick for 1/(64*10^6)=15,625 times

Thus, now if our 8 bit timer will count for 255 times it will cover only 255*64*10^-6 = 266*64 us =
16.32 ms

Now if 1 sec =1000 ms

So how many time does our timer should count to 255 so as to get 1 sec.

1000 ms/16.32 ms =62.35 times =approximately 62 times.

So this is how we will get delay of 1 sec.

Pre lab Questions:


1. Write the steps sequence to program Delay using Timer 0 in ATMega328P microcontroller.

Lab Procedure:
8. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB
cable.
9. Write the code and compile it in Arduino IDE.
10. Select USB port in Arduino IDE.
11. Select Arduino Uno Development Board in Arduino IDE.
12. Download the code into Arduino Uno Development Board
13. Run the code in Arduino Uno Development Board.
14. Observe and verify the output.

Post Lab:
3. Calculate the hexadecimal value to be loaded in TCNT0 register to generate 10ms of delay by
considering 8MHz CPU frequency.

CODE FOR DELAY GENERATION USING TIMERS (TO BLINK THE LED WITH TIMER
BASED DELAY):
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>

#define SET(port,bit) port|=(1<<bit)


#define CLR(port,bit) port&=~(1<<bit)
#define TOGGLE(PORT,BIT) PORT^=(1<<BIT)

int count=0;
void timer0_init()
{
CLR(TCCR0A,WGM00);//SET TIMER0 TO NORMAL MODE
CLR(TCCR0A,WGM01);
CLR(TCCR0B,WGM02);
TCNT0=0X00;
SET(SREG,7);
47
SET(TIMSK0,TOIE0); // overflow interrupt enable
}

void enable_timer()
{
SET(TCCR0B,CS00);//set prescalar to 1024
CLR(TCCR0B,CS01);
SET(TCCR0B,CS02);
}

int main()
{
DDRB|=(1<<PB5); //LED CONNECTED TO DIGITAL PIN 13 ,and all the
//bits of the port is set so as to make it an
//output port
timer0_init();
enable_timer();
while(1)
{
if(count==62)
{
TOGGLE(PORTB,PB5);
count=0;
}
}
}

ISR(TIMER0_OVF_vect)
{
count++;
}

Result:

48
Lab 6: Sensor Interfacing For Displacement Measurement

Aim: To indicate the distance range using three LEDs and use ultrasonic sensor to measure distance.
Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinker cad online Virtual Lab (For simulation)

Theory:

Ultrasonic sensor HC-SR04 is used here to measure distance in range of 2cm-400cm with accuracy
of 3mm. The sensor module consists of ultrasonic transmitter, receiver and the control circuit. The
working principle of ultrasonic sensor is as follows:

 High level signal is sent for 10us using Trigger.


 The module sends eight 40 KHz signals automatically, and then detects whether pulse is
received or not.
 If the signal is received, then it is through high level. The time of high duration is the time gap
between sending and receiving the signal.
 Distance= (Time x Speed of Sound in Air (340 m/s))/2

49
Code Structure

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Bare minimum code

 setup : It is called only when the Arduino is powered on or reset. It is used to


initialize variables and pin modes
 loop : The loop functions runs continuously till the device is powered off. The main
logic of the code goes here. Similar to while (1) for micro-controller programming.

PinMode

 A pin on arduino can be set as input or output by using pinMode function.


 pinMode(9, OUTPUT); // sets pin 9 as output pin
 pinMode(9, INPUT); // sets pin as input pin

Prelab :
1. What are ultrasonic sensors?
2. What environmental conditions affect an ultrasonic sensor?

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB
cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Post Lab:

1. Write a note on the Arduino function used to detect the length of a pulse.
2. What is a dead zone in ultrasonic ranging?

50
Output:

Paste your Screenshots here.

Code.
long cm = 0;

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

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}

void loop()
{
51
cm =readUltrasonicDistance(7, 6);

Serial.print(cm);
Serial.println("cm");

if (cm > 250) {


digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (cm <= 250 && cm > 175) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (cm <= 175 && cm > 100) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
if (cm <= 100) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}

delay(100); // Wait for 100 millisecond(s)


}

long readUltrasonicDistance(int triggerPin, int echoPin)


{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds *0.01723
return (pulseIn(echoPin, HIGH)*0.01723);

RESULT :
52
Exp. 7: DC MOTOR INTERFACE

Aim:
To run a DC motor with the help of a motor driver(L239D) using Arduino Uno.
Components Requirement:

Hardware components: (i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable

Software Tools: Arduino IDE, Tinkercad online Virtual Lab (For simulation)

Theory:

A DC motor is any of a class of rotary electrical motors that converts direct


current electrical energy into mechanical energy. The most common types rely
on the forces produced by magnetic fields. Nearly all types of DC motors have
some internal mechanism, either electromechanical or electronic, to periodically
change the direction of current in part of the motor.

The L293D is a popular 16-Pin Motor Driver IC. As the name suggests it is
mainly used to drive motors. A single L293D IC is capable of running two DC
motors at the same time; also the direction of these two motors can be
controlled independently.

Pin Pin Name Description


Number

1 Enable 1,2 This pin enables the input pin Input 1(2) and Input 2(7)

2 Input 1 Directly controls


53 the Output 1 pin. Controlled by digital circuits
3 Output 1 Connected to one end of Motor 1

4 Ground Ground pins are connected to ground of circuit (0V)

5 Ground Ground pins are connected to ground of circuit (0V)

6 Output 2 Connected to another end of Motor 1

7 Input 2 Directly controls the Output 2 pin. Controlled by digital circuits

8 Vcc2 (Vs) Connected to Voltage pin for running motors (4.5V to 36V)

9 Enable 3,4 This pin enables the input pin Input 3(10) and Input 4(15)

10 Input 3 Directly controls the Output 3 pin. Controlled by digital circuits

11 Output 3 Connected to one end of Motor 2

12 Ground Ground pins are connected to ground of circuit (0V)

13 Ground Ground pins are connected to ground of circuit (0V)

14 Output 4 Connected to another end of Motor 2

15 Input 4 Directly controls the Output 4 pin. Controlled by digital circuits

16 Vcc2 (Vss) Connected to +5V to enable IC function

54
Features

 Can be used to run Two DC motors with the same IC.


 Speed and Direction control is possible
 Motor voltage Vcc2 (Vs): 4.5V to 36V
 Maximum Peak motor current: 1.2A
 Maximum Continuous Motor Current: 600mA
 Supply Voltage to Vcc1(vss): 4.5V to 7V
 Transition time: 300ns (at 5Vand 24V)
 Automatic Thermal shutdown is available
 Available in 16-pin DIP, TSSOP, SOIC packages

Code Structure:

void setup()
{
// put your setup code here, to run once:
}

void loop()
{
// put your main code here, to run repeatedly:
55
}

Pre-Lab Questions:

1. What is DC motor?
2. On what principle DC motor works?

Procedure:

1. Connect the Arduino Uno Development Board to the Desktop/Laptop through


Type B USB cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Note:
We use a slide switch to alter the direction of rotation of the motor. When
the slide switch is in the left side, the DC motor rotates in an anticlockwise
fashion. When switch slides to the right, the DC motor rotates in clockwise
direction.

56
Post Lab:

1. What is the purpose of H-Bridge in interfacing a DC motor with Arduino?


2. Write a C program to control two DC motors based on the two-slide
switch.

Output

Paste your Screenshots here.

Code:

void setup()
{
pinMode(13, OUTPUT); // enable l293d
pinMode(11,OUTPUT); // input 1
pinMode(9,OUTPUT); // input 2

digitalWrite(13,HIGH); // enable motor


57
pinMode(7,INPUT);
}
void loop()
{
if(digitalRead(7)== 1)
{
analogWrite(11,10);
digitalWrite(9,LOW);
}
if(digitalRead(7)== 0)
{
analogWrite(9,10);
digitalWrite(11,LOW);
}
}
Result:

Exp. 8: PWM BASED SERVO MOTOR INTERFACING

Aim:
To interface a Servo Motor using PWM Signals.

Components Requirement:
Hardware components: (i) Desktop/ Laptop (Host)
(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable

Software Tools: Arduino IDE, Tinkercad online Virtual Lab (For simulation)

58
Theory:
A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear
position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position
feedback. It also requires a relatively sophisticated controller, often a dedicated module designed
specifically for use with servomotors.
Servomotors are not a specific class of motor, although the term servomotor is often used to refer to a
motor suitable for use in a closed-loop control system.
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.

Code Structure
void setup() { // put your setup
code here, to run once:
59
}
void loop() { // put your main code here, to run repeatedly:
}

Pre lab Questions:


1. Write about the construction of the Servo Motor.
2. List the applications of Servo Motor.

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Post lab Questions:


1. List the advantages and disadvantages of Servo Motor.

2. How PWM is used to control the Servo Motor?

CODE:

#include <Servo.h>
int pos = 0;
Servo servo_9;
void setup()
{
servo_9.attach(9);
}
void loop()
{
for (pos = 0; pos<= 180; pos += 1) {
servo_9.write(pos);
delay(15);
}
for (pos = 180; pos>= 0; pos -= 1) {

60
servo_9.write(pos);
delay(15);
}
}

CODE:
int sensorValue = 0;
int outputValue = 0;
void setup() {
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop(){
sensorValue = analogRead(A0);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(9, outputValue);
Serial.print("sensor =");
Serial.print(sensorValue);
Serial.print("\toutput =");
61
Serial.println(outputValue);
delay(2);
}

RESULT: Thus, the DC Motor was interfaced using H-Bridge and co

Lab 9: I2C Communication

Aim:
To interface two Arduino using I2C Communication

Components Requirement:
Hardware components: (i) Desktop/ Laptop (Host)
(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable

Software Tools: Arduino IDE, Tinkercad online Virtual Lab (For simulation)

Theory:

The I2C protocol involves using two lines to send and receive data: a serial clock pin (SCL) that the
Arduino or Genuino Master board pulses at a regular interval, and a serial data pin (SDA) over which
62
data is sent between the two devices. As the clock line changes from low to high (known as the rising
edge of the clock pulse), a single bit of information - that will form in sequence the address of a
specific device and a a command or data - is transferred from the board to the I2C device over the
SDA line. When this information is sent - bit after bit -, the called upon device executes the request
and transmits it's data back - if required - to the board over the same line using the clock signal still
generated by the Master on SCL as timing.

Code Structure

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Pre lab Questions:


1) Name the two lines of I2C protocol.

2) In Arduino board, which pins are used for I 2 C?

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B
USB cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.

63
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.
Post lab Questions:
1) List the functions done by Wire.beginTransmission(address).

2) What are the functions used to receive data over I2C?


Output:

CODE:
Arduino 1:

#include
<Wire.h> int
analogIN = 0; int
msg = 0;
void setup() {
pinMode(A0, INPUT);
// Start the I2C Bus as Master
Wire.begin();
Serial.begin(9600);
Serial.print("Welcome to I2C Demo. I am Arduino
1"); }

void loop(){
analogIN=analogRead(A0);
msg = map(analogIN, 0, 1023, 0, 255);
Wire.beginTransmission(9); // transmit to device #9
64
Wire.write(msg); // sends x
Wire.endTransmission(); // stop transmitting
Serial.println(msg);
delay(500);
}

Arduino 2:

#include
<Wire.h> int
LED = 13; int x
= 0; void
setup() {
// Define the LED pin as Output
pinMode (LED, OUTPUT);
Serial.begin(9600);
// Start the I2C Bus as Slave on address 9
Wire.begin(9);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}

void receiveEvent(int bytes) {


x = Wire.read(); // read one character from the I2C
Serial.println(x);
}
void loop() {
//If value received is 0 blink LED for 200
ms if (x ==0) {
digitalWrite(LED,
HIGH); delay(200);
digitalWrite(LED, LOW);
delay(200);

}
//If value received is 3 blink LED for 400
ms if (x ==4) {
digitalWrite(LED,
HIGH); delay(400);
digitalWrite(LED, LOW);
delay(400);
}
}

65
RESULT:

Lab 10: Interrupt Programming


Aim:
To run a buzzer and LED using Interrupt in Arduino.
Components Requirement:
Hardware components: (i) Desktop/ Laptop (Host)
(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable

Software Tools: Arduino IDE, Tinkercad online Virtual Lab (For simulation)

Theory:

An Interrupt's job is to make sure that the processor responds quickly to important events.
When a certain signal is detected, an Interrupt (as the name suggests) interrupts whatever the
processor is doing, and executes some code designed to react to whatever external stimulus is
being fed to the Arduino.

66
Code Structure

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Pre lab Questions:


1) What are the external interrupts in Arduino?

2) What are the USART related interrupts in Arduino?

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B
USB cable.
67
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Post lab Questions:


1) List the modes of interrupt.
2) Which pins are allocated for INT.0 and INT.1 in Arduino Uno board?

CODE:

const byte LED_Pin = 13;


const byte BUZZER_Pin = 12;

const byte interruptPin2 = 2;


const byte interruptPin3 = 3;

volatile byte LED_state = HIGH;


volatile byte BUZZER_state = HIGH;

void setup() {
pinMode(LED_Pin, OUTPUT);
pinMode(BUZZER_Pin, OUTPUT);

digitalWrite(LED_Pin, LED_state);
digitalWrite(BUZZER_Pin, BUZZER_state);

68
pinMode(interruptPin2, INPUT_PULLUP);
pinMode(interruptPin3, INPUT_PULLUP);

attachInterrupt(digitalPinToInterrupt(interruptPin2), blink2, CHANGE);


attachInterrupt(digitalPinToInterrupt(interruptPin3), blink3, CHANGE); Serial.begin(9600);
Serial.println("Welcome");
}

void loop() {
digitalWrite(LED_Pin, LED_state);
digitalWrite(BUZZER_Pin, BUZZER_state);
Serial.println("0");
}

void blink2() {
LED_state =
!LED_state;
Serial.println("2");
}

void blink3() {
BUZZER_state = !BUZZER_state;
Serial.println("4");
}

RESULT:

69
Exp. 5: SENSOR INTERFACING FOR TEMPERATURE MONITORING

Aim:
To indicate the temperature in “Red”, “Yellow”, “Green” LEDs and also
send the value to terminal in PC via serial port.

Components Requirement:

Hardware components: (i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable

Software Tools: Arduino IDE, Tinkercad online Virtual Lab (For simulation)

Theory:

The Temperature Sensor LM35 series are precision integrated-circuit temperature devices with an
output voltage linearly proportional to the Centigrade temperature.
The LM35 device has an advantage over linear temperature sensors calibrated in Kelvin, as the user is
not required to subtract a large constant voltage from the output to obtain convenient Centigrade
scaling. The LM35 device does not require any external calibration or trimming to provide typical
accuracies of ±¼°C at room temperature and ±¾°C over a full −55°C to 150°C temperature range. It
is a 3-terminal device that provides analog voltage proportional to the temperature. Higher the
temperature, higher is the output voltage. The output analog voltage can be converted to digital form
using ADC so that a microcontroller can process it.

70
Code Structure:

void setup()
{
// put your setup code here, to run once:
}

void loop()
{
// put your main code here, to run repeatedly:
}

Pre-Lab Questions:

1. What is temperature sensor?


2. What are the 2 types of serial communication?
Procedure:

1. Connect the Arduino Uno Development Board to the Desktop/Laptop through


Type B USB cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
71
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Note:
 Red LED should glow when temperature is greater than 70 degree
Celsius
 Yellow LED should glow when temperature is greater than 21 degree
Celsius and less than 70 degree Celsius.
 Green LED should glow when temperature is Less than 20 degree
Celsius

Post Lab:

1. Why temper sensor is connected to A0?


2. List few Arduino serial communications functions.

Output:

Paste your Screenshots here.

72
Code:

int sensorValue = 0;

int SerialValue = 0;

void setup()

pinMode(A0, INPUT);

pinMode(13, OUTPUT); //red

pinMode(12, OUTPUT); //green

pinMode(11, OUTPUT); //yellow

Serial.begin(9600);

void loop()

sensorValue = analogRead(A0);

73
SerialValue = (sensorValue-102)/2;

Serial.println(SerialValue);

if (SerialValue>70)

// ONLY RED GLOWS

digitalWrite(13,HIGH);

digitalWrite(12,LOW);

digitalWrite(11,LOW);

if (SerialValue>21 && SerialValue<70)

// ONLY YELLOW GLOWS

digitalWrite(13,LOW);

digitalWrite(12,LOW);

digitalWrite(11,HIGH);

if(SerialValue<20)

// ONLY GREEN GLOWS

digitalWrite(13,LOW);

digitalWrite(12,HIGH);

digitalWrite(11,LOW);

}
74
delay(2); // Wait for 2 millisecond(s)

Result:

Laboratory Report Cover Sheet

SRM Institute of Science and Technology


Faculty of Engineering and Technology
Department of Electronics and Communication Engineering
18ECO108J EMBEDDED SYSTEM DESIGN USING ARDUINO
Sixth Semester, 2020-21 (Even Semester)

Name :
Register No. :
Day / Session :
Venue :
Title of Experiment :
Date of Conduction :
Date of Submission :

Particulars Max. Marks Marks Obtained


Pre-lab questions 10
In-lab experiment 20
75
Post-lab questions 10
Total 40

REPORT VERIFICATION

Date :

Staff Name :

Signature :

Experiment 12: LCD INTERFACING

Aim:

1. To interface LCD to Arduino (Display text and characters on LCD screen using Arduino)

Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinkercad online Virtual Lab (For simulation)

Theory:

In this experiment, we’re learning how to interface LCD to Arduino and display text characters on
LCD screen. We’re interfacing 16×2 LCD to Arduino as a demonstration with circuit and code.

A Liquid Crystal Display commonly abbreviated as LCD is basically a display unit built
using Liquid Crystal technology. In order to build real life/real world electronics based projects, we
need a medium/device to display output values and messages. The most basic form of electronic
display available is 7 Segment display – which has its own limitations. The next best available option
is Liquid Crystal Displays which comes in different size specifications. Out of all available LCD
modules in market, the most commonly used one is 16×2 LCD Module which can display 32 ASCII
characters in 2 lines (16 characters in 1 line).

76
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(VEE):Contrast adjustment pin. This is done by connecting the ends of a 10K potentiometer 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 560 ohm resistor should be
connected in series to this pin. In arduino based projects the back light LED can be powered from the
3.3V source on the arduino board.
Pin16(LED-): Cathode of the back light LED.

Circuit diagram – Arduino to 16×2 LCD Module

77
Pre-lab Questions:
1) List and describe the important control signals of LCD?
2) Write the advantages of LCD over the LED display.

Code Structure (Arduino to LCD):

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // sets the interfacing pins
void setup( )
{
lcd.begin (16, 2); // initializes the 16x2 LCD
}
Void loop ( )
{
--
--
78
}

Post-Lab Questions:
1) Write an ATMega328P Arduino C program to send letters “SRMIST” to the LCD display. Test the
output in Tinkercad and paste the output result here.

RESULT:

79

You might also like