[go: up one dir, main page]

0% found this document useful (0 votes)
54 views78 pages

Embedded Systems Training Report

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

Embedded Systems Training Report

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

INDUSTRIAL TRAINING DOCUMENTATION REPORT ON

“EMBEDDED SYSTEMS”
At SPIRE SOFTWARE SOLUTIONS

In the partial fulfillment of the completion of VI SEM


Diploma Course for requirement of award in

DIPLOMA IN
ELECTRONICS AND COMMUNICATION ENGINEERING

Under the Esteemed Guidance of


Sri V. L. Prem Kumar Embedded Systems Trainer

Submitted by
THAMMARALA 19328-EC-049
GOPALA KRISHNA

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING


BEHARA POLYTECHNIC COLLEGE, NARAVA,
VISAKHAPATNAM, ANDHRA PRADESH
(2021-2022)
BEHARA POLYTEHNIC, NARAVA

DEPARTMENT OF ELETRONICS & COMMUNICATION ENGG.

CERTIFICATE

This is to certify that the FULFILLMENT work entitle EMBEDDED SYSTEMS


is a bonafide record of the work done by the students of BEHARA
POLYTECHNIC, NARAVA, VISAKHAPATNAM by THAMMARALA
GOPALA KRISHNA (19328-EC-049). It is in partial fulfillment of the
requirement for the award in diploma during the academic year 2021-2022
under our guidance and supervision in EMBEDDED SYSTEMS.

TRAINING INCHARGE PRINCIPAL HEAD OF DEPARTMENT


ACKNOWLEDGEMENT

I would like to take this opportunity to express my profound sense of gratitude to


Principal Mrs. V.SUKUNYA, M.E, PhD, Behara Polytechnic College for her refining
comments and Critical judgments of industrial training.

I would like to express my special thanks of gratitude to our Head of the Department
Mr. G.SRIKANTH, M.Tech, Electronics and Communication Engineering, Behara
Polytechnic College for providing all necessary Support for successful completion of
our training.

I have great pleasure in expressing my deep sense of gratitude to my Industrial Training


instructor Mr. V. L. PREM KUMAR, who helped me to learn so many new things,
Knowledge and Hands-on Experience.

I thank all the staff members of our department & the college administration who helped
me in carrying out this training successfully.

DEPARTMENT OF ECE i
ABSTRACT

Industrial training is the important phase of a student life. A well planned, properly
executed and evaluated industrial training helps a lot in developing a professional
attitude. It develops an awareness of industrial approach to gain practical knowledge
based on electronics, Embedded Systems, most of the practical knowledge that has been
gained during the course of studies is put to test.

The aim and motivation of this industrial training is to receive discipline, skills,
teamwork and technical knowledge through a proper training environment, which will
help me, as a student in the field of Electronics and communication, to develop a
responsiveness of the self-disciplinary nature of skills in electronics and
communication technology, During a period of five months training at Behara
Polytechnic college under Spire Software Solutions.

During the training period I have learnt about Number Systems, Microcontrollers,
Embedded C, Keil Software, Liquid Crystal Display, 4*4 Matrix Keypad, Motor
Drivers, Analog & Digital Sensors, Analog to Digital Converters, Arduino, Embedded
Systems, Circuit Simulation on Proteus, and PCB Designing on Proteus. After that we
have practically designed and simulated circuits on Proteus 8 Professional also have
done PCB design and made physical Printed Circuit Board of SMPS.

DEPARTMENT OF ECE ii
PREFACE

Practical training constitutes an integral part of engineering studies. The training gives
an opportunity to the students to express themselves to the industrial environment
which is quite different from the teaching classroom. The training enables the student
to work in the future. It enables the student to undergo those experiences which help
them later when they join an organization.

Industrial training is a major part of course. It is period in which we are introduced to


the industrial environment or in other words we can say that industrial training is
provided for the familiarization with the industrial environment, with the advancement
in computer technologies and increased automation in the industries for increasing their
production. In organization where Making Things Right in the first instance is the
driving motto, perfection and accuracy are inevitable.

It provides a linkage between the student and industry to develop an awareness of


industrial approach to problem solving, based on a broad understanding of process and
mode of operation of organization. The objective of training is to raise the level of
performance on one or more of its aspects and this may be achieved by providing new
knowledge and information relevant to a job.

During this period, the students get the real, first-hand experience for working in the
actual environment. Most of the theoretical knowledge that has been gained during the
course of their studies is put to test here. It covers all the remains uncovered in the
classroom i.e. without it our studies remains ineffective and incomplete. Apart from
this, the students get an opportunity to learn the latest technology, which immensely
helps them in building their carrier.

I had the opportunity to have a real experience on many ventures, which increased my
sphere of knowledge to a great extent. I was entrusted with a real life project, working
on which had finally made me step into the ongoing technology and gradually become
a part of it. And all the credit goes to Spire Software Solutions for providing me the
opportunity and facility for the making of this dissertation. I availed this instance in a
very satisfactory manner and think it will be very beneficial for me in building my
future.

DEPARTMENT OF ECE iii


CONTENTS

CONTENTS
ACKNOWLEDGEMENT........................................................................i
ABSTRACT..............................................................................................ii
PREFACE................................................................................................iii
CHAPTER 1
NUMBER SYSTEMS...........................................................................1-6
1.1 Introduction ............................................................................................................. 1
1.2 Units of Digital Information ................................................................................... 1
1.3 Types of Number System........................................................................................ 2
1.3.1 Decimal Number System ................................................................................. 2
1.3.2 Binary Number System .................................................................................... 2
1.3.3 Octal Number System ...................................................................................... 2
1.3.4 Hexadecimal Number System .......................................................................... 2
1.3.5 Comparison Table of Four Number Systems ................................................... 3
1.4 Conversions............................................................................................................. 3
1.4.1 Decimal to Binary ............................................................................................ 4
1.4.2 Decimal to Octal............................................................................................... 4
1.4.3 Decimal to Hexadecimal .................................................................................. 4
1.4.4 Binary to Decimal ............................................................................................ 4
1.4.5 Binary to Octal ................................................................................................. 5
1.4.6 Binary to Hexadecimal ..................................................................................... 5
1.4.7 Octal to Decimal............................................................................................... 5
1.4.8 Octal to Binary ................................................................................................. 5
1.4.9 Hexadecimal to Decimal .................................................................................. 5
1.4.10 Hexadecimal to Binary ................................................................................... 6

CHAPTER 2
INTRODUCTION TO EMBEDDED SYSTEMS…........................7-10
2.1 Definition ................................................................................................................ 7
2.2 History of Embedded System ................................................................................. 7
2.3 Characteristics of Embedded Systems .................................................................... 7
2.4 Advantages .............................................................................................................. 8

DEPARTMENT OF ECE iv
CONTENTS

2.5 Disadvantages ......................................................................................................... 8


2.6 Structure of Embedded System ............................................................................... 8
2.7 Classification......................................................................................................... 10
2.7.1 Based on generation ....................................................................................... 10
2.7.2 Based on complexity & performance requirements ....................................... 10
2.8 Applications .......................................................................................................... 10

CHAPTER 3
BASICS OF C LANGUAGE…........................................................11-14
3.1 Introduction ........................................................................................................... 11
3.2 Types of Sections .................................................................................................. 11
3.3 Keywords .............................................................................................................. 11
3.4 Data Types ............................................................................................................ 11
3.5 Functions ............................................................................................................... 11
3.5.1 Functions with argument ................................................................................ 11
3.5.2 Functions without argument ........................................................................... 12
3.6 Loops..................................................................................................................... 12
3.6.1 Entry Controlled Loops .................................................................................. 12
3.6.2 Exit Controlled Loops .................................................................................... 12
3.7 Keil Software ........................................................................................................ 12
3.7.1 How to download ........................................................................................... 12
3.7.2 How to install ................................................................................................. 12
3.7.3 Keil Setup for 8051 ........................................................................................ 13
3.7.4 Generate Hex Code ........................................................................................ 13
3.8 PROGRAMS......................................................................................................... 13
3.8.1 Program to blink the LEDs are connected to port 0 ....................................... 13
3.8.2 Program to blink the LEDs are connected to port 0, port 2, port 3 ................ 14

CHAPTER 4
INTRODUCTION TO 8051 MICROCONTROLLER.................15-22
4.1 Introduction ............................................................................................................ 15
4.2 Specifications ......................................................................................................... 15
4.3 Pin Description Of 8051 ........................................................................................ 15
4.4 Difference Between Microprocessor and Microcontroller .................................... 16
4.5 Advantages ............................................................................................................. 17

DEPARTMENT OF ECE v
CONTENTS

4.6 Disadvantages ........................................................................................................ 18


4.7 Architecture Of 8051 ............................................................................................. 18
4.8 Timers & Counters ................................................................................................. 19
4.9 Difference between a Timer and a Counter ........................................................... 19
4.10 Timers of 8051 and their Associated Registers ................................................... 19
4.10.1 Timer 0 Register ............................................................................................ 19
4.10.2 Timer 1 Register ............................................................................................ 20
4.11 TMOD (Timer Mode) Register ............................................................................ 20
4.11.1 GATE ............................................................................................................ 20
4.11.2 C/T (CLOCK / TIMER) ................................................................................ 21
4.11.3 M1 / M2......................................................................................................... 21
4.12 Different Modes of Timers .................................................................................. 21
4.12.1 Mode 0 (13-Bit Timer Mode)........................................................................ 21
4.12.2 Mode 1 (16-Bit Timer Mode)........................................................................ 22
4.12.3 Mode 2 (8 Bit Auto Reload) .......................................................................... 22
4.12.4 Mode 3 (Split Timer Mode) .......................................................................... 22

CHAPTER 5
MICROCONTROLLER PERIPHERALS………….....................23-41
5.1 Liquid Crystal Display .......................................................................................... 23
5.2 Specifications ........................................................................................................ 23
5.3 PIN description of 16x2 LCD ............................................................................... 23
5.4 LCD Commands ................................................................................................... 24
5.5 LCD Interfacing with 8051 ................................................................................... 25
5.5.1 Program to interface LCD to 8051 in 8-bit mode .......................................... 25
5.5.2 Program to interface LCD to 8051 in 4-bit mode .......................................... 27
5.6 Matrix Keypad ...................................................................................................... 28
5.7 Working of Matrix Keypad ................................................................................... 29
5.8 Interfacing Matrix Keypad with 8051................................................................... 30
5.9 Sensors .................................................................................................................. 34
5.9.1 Analog Sensors ............................................................................................... 34
5.9.2 Digital Sensors ............................................................................................... 35
5.10 Light Sensor ........................................................................................................ 35
5.11 IR Sensor............................................................................................................. 35
5.11.1 Active Infrared Sensors ................................................................................ 36

DEPARTMENT OF ECE vi
CONTENTS

5.11.2 Passive Infrared Sensor ................................................................................ 36


5.12 Ultrasonic Sensor ................................................................................................ 37
5.13 Motor Drivers...................................................................................................... 38
5.14 Features of L293D Motor Driver ........................................................................ 38
5.15 PIN diagram of L293D Motor Driver ................................................................. 38
5.16 Interfacing of L293D .......................................................................................... 40
5.17 Applications of L23D ......................................................................................... 41

CHAPTER 6
ANALOG TO DIGITALCONVERTERS...…………………......42-45
6.1 A-D Converter ...................................................................................................... 42
6.2 Characteristics of ADC ......................................................................................... 42
6.3 ADC 0804 ............................................................................................................. 43
6.3.1 PIN Diagram of ADC 0804 ............................................................................ 43
6.3.2 Features of 0804 ............................................................................................. 44
6.4 ADC 0808 ............................................................................................................. 44
6.4.1 PIN Diagram of ADC 0808 ............................................................................ 44
6.4.2 Features of ADC 0808.................................................................................... 45

CHAPTER 7
PROTEUS..........................................................................................46-49
7.1 Introduction ........................................................................................................... 46
7.2 Features ................................................................................................................. 46
7.3 How to download .................................................................................................. 46
7.4 PCB Designing...................................................................................................... 47
7.4.1 Schematic Capture.......................................................................................... 47
7.4.2 PCB Layout .................................................................................................... 47
7.5 SMPS .................................................................................................................... 48
7.6 Interfacing LED and Switch with 8051 Microcontroller ...................................... 48

CHAPTER 8
ARDUINO..........................................................................................50-58
8.1 Introduction ............................................................................................................ 50
8.2 Arduino History ..................................................................................................... 50
8.3 Arduino Family ...................................................................................................... 50

DEPARTMENT OF ECE vii


CONTENTS

8.4 Arduino UNO......................................................................................................... 51


8.5 Specifications of Arduino UNO............................................................................. 52
8.6 PIN Diagram of Arduino UNO .............................................................................. 52
8.7 Advantages of Arduino .......................................................................................... 54
8.8 Disadvantages of Arduino...................................................................................... 54
8.9 Applications of Arduino ........................................................................................ 54
8.10 Arduino IDE......................................................................................................... 55
8.10 Arduino Programming ......................................................................................... 55
8.11 LCD Interfacing with Arduino............................................................................. 56
8.12 Matrix Keypad Interfacing with Arduino ............................................................ 57

DEPARTMENT OF ECE viii


LIST OF FIGURES

LIST OF FIGURES
Fig 2.1 - Embedded System .......................................................................................... 7
Fig 2.2 - Block Diagram of Embedded System ............................................................ 9
Fig 4.1 - Pin Diagram Of 8051 .................................................................................... 16
Fig 4.2 - Architecture of 8051...................................................................................... 18
Fig 4.3 - Timer 0 .......................................................................................................... 20
Fig 4.4 - Timer 1 .......................................................................................................... 20
Fig 4.5 - TMOD Register ............................................................................................. 20
Fig 5.1 - PIN Diagram of 16x2 LCD .......................................................................... 23
Fig 5.2 - 4*4 Matrix Keypad....................................................................................... 29
Fig 5.3 - Schematic of 4*4 Matrix Keypad................................................................. 29
Fig 5.4 - Interfacing Matrix Keypad & LCD with 8051 ............................................. 30
Fig 5.5 - Sensor Block Diagram ................................................................................. 34
Fig 5.6 - LDR Sensor .................................................................................................. 35
Fig 5.7 - IR MODULE ................................................................................................ 36
Fig 5.8 - PIR Sensor .................................................................................................... 37
Fig 5.9 - Ultrasonic Sensor ......................................................................................... 37
Fig 5.10 - PIN Diagram of L293D Motor Driver ....................................................... 38
Fig 5.11 - L293D Interfacing with Motors ................................................................. 40
Fig 6.1 - Block Diagram of ADC................................................................................ 42
Fig 6.2 - PIN Diagram of ADC 0804 .......................................................................... 43
Fig 6.3 - PIN Diagram of ADC 0808 .......................................................................... 45
Fig 7.1 - SMPS Schematic Diagram ........................................................................... 48
Fig 8.1 - Arduino UNO ................................................................................................ 51
Fig 8.2 - PIN Diagram of Arduino UNO ..................................................................... 53
Fig 8.3 - Interfacing LCD with Arduino UNO ............................................................ 56
Fig 8.4 - Matrix Keypad Interfacing with Arduino UNO ............................................ 57

DEPARTMENT OF ECE ix
LIST OF TABLES

LIST OF TABLES
Table 1.1 - Units of Digital Information ....................................................................... 1
Table 2.2 - Number Systems ......................................................................................... 3
Table 4.1 - Difference between Microprocessor and Microcontroller ........................ 17
Table 4.2 - Difference between a Timer and a Counter ............................................... 19
Table 4.3 - Timer Modes ............................................................................................. 21
Table 5.1 - LCD Commands ....................................................................................... 25
Table 5.2 - PIN Diagram of L293D ............................................................................ 40

DEPARTMENT OF ECE x
CHAPTER 1

NUMBER SYSTEMS
NUMBER SYSTEMS

NUMBER SYSTEMS
1.1 Introduction
The number system is used for representing the information. In digital
electronics we use a positional number system which has different bases. The base or
radix of the number system is the total number of the digits used in the number system.
The most common used number systems in digital electronics are:
• Decimal Number System (base 10)
• Binary Number System (base 2)
• Octal Number System (base 8)
• Hexadecimal Number System (base 16)
The decimal system is the number system that we use every day to represent
any number, no matter how large or how small. The computers understand the binary
number system.
1.2 Units of Digital Information
Bit: A bit is a binary digit, the smallest increment of data on a computer. A bit can hold
only one of two values: 0 or 1, corresponding to the electrical values of off or on,
respectively.
Nibble: Group of 4 bits is called Nibble.
Byte: Group of 8 bits is called Byte. Byte is the basic unit in computers.
Computer count by base 2, so in computer jargon, the following units are used:

Unit Equivalent

1 kilobyte (KB) 1,024 bytes

1 megabyte (MB) 1,048,576 bytes

1 gigabyte (GB) 1,073,741,824 bytes

1 terabyte (TB) 1,099,511,627,776 bytes

1 petabyte (PB) 1,125,899,906,842,624 bytes

Table 1.1 - Units of Digital Information

DEPARTMENT OF ECE Page No 1


NUMBER SYSTEMS

1.3 Types of Number System


1.3.1 Decimal Number System
• The symbols in the decimal number system are 0,1,2,3,4,5,6,7,8,9.
• Decimal Number System radix value is 10.
• The right most binary digit has the least weightage and hence known as
‘Least Significant Digit’.
• As one goes from right to left, the positional value increases by 10 times.
The leftmost digit has the highest positional value and hence it is known as
‘Most significant Digit’.
Ex: 759.3 ⇒ 7*102 + 5*101 + 9*100 + 3*10-1

7 5 9 . 3

Most Significant Digit Least Significant Digit

1.3.2 Binary Number System


• The symbols in the binary number system are 0,1.
• Binary Number System radix value is 2.
• The right most binary digit (bit) has the least weightage and hence known
as ‘Least Significant Bit’.
• As one goes from right to left, the positional value increases by 2 times.
Hence leftmost bit is known as ‘Most Significant Bit.
Ex: 1011 ⇒ 1*23 + 0*22 + 1*21 + 1*20

1 0 1 1

Most Significant Bit Least Significant Bit

1.3.3 Octal Number System


• The symbols in the octal number system are 0, 1,2,3,4,5,6,7.
• Octal Number System radix value is 8.
Ex: 352 ⇒ 3*82 + 5*81 + 2*80

1.3.4 Hexadecimal Number System


• Hexadecimal Number System radix value is 16.
• The symbols in the hexadecimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, A, B, C, D, E, F.
Ex: 7C2A ⇒ 7*163 + C*162 + 2*161 + A*160

DEPARTMENT OF ECE Page No 2


NUMBER SYSTEMS

1.3.5 Comparison Table of Four Number Systems

Decimal Binary Octal Hexadecimal

0 0000 0 0

1 0001 1 1

2 0010 2 2

3 0011 3 3

4 0100 4 4

5 0101 5 5

6 0110 6 6

7 0111 7 7

8 1000 10 8

9 1001 11 9

10 1010 12 A

11 1011 13 B

12 1100 14 C

13 1101 15 D

14 1110 16 E

15 1111 17 F

Table 2.2 - Number Systems

1.4 Conversions
Here are the methods to convert the number from one number system into
another number system.

1.4.1 Decimal to Binary


i) (47)10 to (?)2

DEPARTMENT OF ECE Page No 3


NUMBER SYSTEMS

2 47

2 23 - 1

2 11 - 1

2 5 -1

2 2 -1

2 1 -0

0 -1
(47)10 ⇒ (101111)2

1.4.2 Decimal to Octal


i) (234)10 to (?)2

8 234

8 29 -2

8 3 -5

0 -3
(234)10 ⇒ (352)8

1.4.3 Decimal to Hexadecimal


i) (873)10 to (?)2

16 873

16 54 -9

16 3 -6

0 -3

(873)10 ⇒ (369)16

1.4.4 Binary to Decimal


i) (11011)2 to (?)10
11011 = 1*24 + 1*23 + 0*22 + 1*21+ 1*20
= 1*16 + 1*8 +0 + 1*2 + 1*1
= 16 + 8 + 0 + 2 + 1
= (27)10

DEPARTMENT OF ECE Page No 4


NUMBER SYSTEMS

1.4.5 Binary to Octal


i) (10010)2 to (?)8
The given number is first grouped into 3 bits as
10 010
This can be written as (by adding zeros)
010 010
Convert this binary number into an octal number by using table 1.
010 010 = 22
(10010)2 ⇒ (22)8

1.4.6 Binary to Hexadecimal


i) (11001001)2 to (?)16
Group the given binary number in 4 bits as
1100 1001
Convert this binary number into an octal number by using table 1.
1100 1001 = 2C
(11001001)2 ⇒ (2C) 16

1.4.7 Octal to Decimal


i) (352)8 to (?)10
352 = 3*82 + 5*81 + 2*80
= 3*64 + 5*8 + 2*1
= 192 + 40 + 2
= (234)10

1.4.8 Octal to Binary


To convert octal into binary, write each of the octal digits in as 3-bit binary
code by using table1.
i) (24)8 to (?)2
(24)8 ⇒ 010 100
⇒ (010100)2

1.4.9 Hexadecimal to Decimal


i) (3D)16 to (?)10
3D = 3*161 + D*160
= 3*16 + 13*1
= 48 + 13

DEPARTMENT OF ECE Page No 5


NUMBER SYSTEMS

= (61)10

1.4.10 Hexadecimal to Binary


To convert hexadecimal into binary, write each of the hexadecimal digits in as
4-bit binary code by using table1.
i) (8D)16 to (?)2
(8D) ⇒ 1000 1101
⇒ (10001101)2

DEPARTMENT OF ECE Page No 6


CHAPTER 2

INTRODUCTION TO EMBEDDED SYSTEM


INTRODUCTION TO EMBEDDED SYSTEMS

INTRODUCTION TO EMBEDDED SYSTEMS


2.1 Definition
An electronic/electro mechanical system which is designed to perform specific
functions, and it is a combination of both software and hardware. Embedded systems
may also function within a larger system. The systems can be programmable or have a
fixed functionality.
An embedded system has three components:
 Hardware.
 Application Software.
 Real Time Operating System (RTOS) though a small-scale embedded system
may not have RTOS.

Fig 2.1 - Embedded System

2.2 History of Embedded System


 Embedded systems were introduced in 1960.
 The first recognized modem embedded system is the Apollo guidance computer
(AGC).
 The first mass-produced embedded system is the Autonetics D-17 guidance
computer.

2.3 Characteristics of Embedded Systems


 Single-functioned − An embedded system usually performs a specialized
operation and does the same repeatedly. For example: A pager always functions
as a pager.

DEPARTMENT OF ECE Page No 7


INTRODUCTION TO EMBEDDED SYSTEMS

 Tightly constrained − All computing systems have constraints on design


metrics, but those on an embedded system can be especially tight. Design
metrics is a measure of an implementation's features such as its cost, size,
power, and performance. It must be of a size to fit on a single chip, must perform
fast enough to process data in real time and consume minimum power to extend
battery life.
 Reactive and Real time − Many embedded systems must continually react to
changes in the system's environment and must compute certain results in real
time without any delay. Consider an example of a car cruise controller; it
continually monitors and reacts to speed and brake sensors. It must compute
acceleration or de-accelerations repeatedly within a limited time; a delayed
computation can result in failure to control the car.
 Microprocessors based − It must be microprocessor or microcontroller based.
 Memory − It must have a memory, as its software usually embeds in ROM. It
does not need any secondary memories in the computer.
 Connected − It must have connected peripherals to connect input and output
devices.
 HW-SW systems − Software is used for more features and flexibility.
Hardware is used for performance and security

2.4 Advantages
 Less expensive.
 Easy for mass production.
 Very few interconnections.
 Fast operation.
 Highly reliable.
 Enhanced Performance.

2.5 Disadvantages
 No technological improvement.
 Less power supply durability, if it is battery operated.
 Hard to take backup of embedded files.
 Larger time to market.

2.6 Structure of Embedded System


Embedded systems vary in complexity but, generally, consist of three main elements:

DEPARTMENT OF ECE Page No 8


INTRODUCTION TO EMBEDDED SYSTEMS

Hardware: The hardware of embedded systems is based on microprocessors and


microcontrollers. Microprocessors are very similar to microcontrollers and, typically,
refer to a CPU (central processing unit) that is integrated with other basic computing
components such as memory chips and digital signal processors (DSPs).
Microcontrollers have those components built into one chip.
Software and Firmware: Software for embedded systems can vary in complexity.
However, industrial-grade microcontrollers and embedded IoT systems usually run
very simple software that requires little memory.
Real-Time Operating System: These are not always included in embedded systems,
especially smaller-scale systems. RTOS define how the system works by supervising
the software and setting rules during program execution.

Fig 2.2 - Block Diagram of Embedded System


In terms of hardware, a basic embedded system would consist of the following
elements:
 Sensors convert physical sense data into electrical signals. It measures the
physical quantity and converts it to an electrical signal which can be read by an
observer or by any electronic instrument like an A2D converter.
 Analog-to-digital (A-D) converters change an analog electrical signal into a
digital one.
 Processors process digital signals and store them in memory.
 Digital-to-analog (D-A) converters change the digital data from the processor
into analog data.
 Actuators compare actual output to memory-stored output and choose the
correct one.

DEPARTMENT OF ECE Page No 9


INTRODUCTION TO EMBEDDED SYSTEMS

 The sensor reads external inputs, the converters make that input readable to the
processor, and the processor turns that information into useful output for the
embedded system.

2.7 Classification
1. Based on generation
2. Based on complexity & performance requirements
3. Based on deterministic behaviour
4. Based on triggering

2.7.1 Based on generation


 First generation: The early embedded system built around 8-bit
microprocessor like 8085, Z80 and 4-bit microcontrollers
 Second Generation: Embedded systems built around 16-bit microprocessors
and 8-bit or 16-bit microcontrollers following the first-generation embedded
system.
 Third Generation: Build around high performance 16-bit or 32-bit
microprocessors or microcontrollers: Application specific instruction set
processors like digital signal processor (DSP) and other.
 Fourth Generation: Built around a system on chips (SOCS), re-configurable
processors and multicore processors.

2.7.2 Based on complexity & performance requirements


 Small Scale Embedded Systems: The early embedded system built around 8-
bit microprocessor like 8085, Z80 and 4-bit microcontrollers
 Medium Scale Embedded Systems: Embedded systems built around 16-bit
microprocessors and 8-bit or 16-bit microcontrollers following the first-
generation embedded system.
 Complex Embedded Systems: Build around high performance 16-bit or 32-
bit microprocessors or microcontrollers: Application specific instruction set
processors like digital signal processor (DSP) and other.

2.8 Applications
 Fitness devices
 Factory robot
 Traffic lights control system
 GPS system, etc.

DEPARTMENT OF ECE Page No 10


CHAPTER 3

BASICS OF C LANGUAGE
BASICS OF C LANGUAGE

BASICS OF C LANGUAGE
3.1 Introduction
• Low level language ⇒ Machine Language
• Mid-level language ⇒ Assembly Language
• High level language ⇒ Programmable Language
C language is a user-friendly language. C language is the high-level language.

3.2 Types of Sections


• Keywords
• Data types
• Boolean data types

3.3 Keywords
auto break case char unsigned
const continue default do void
double else enum extern volatile
float for goto if while
int long register return typedef
switch signed sizeof static union

3.4 Data Types


• int
• char
• float
• double
• boolean

3.5 Functions
In c, we can divide a large program into the basic building blocks known as
function. The function contains the set of programming statements enclosed by {}. A
function can be called multiple times to provide reusability and modularity to the C
program.

3.5.1 Functions with argument


1. Return Value
2. No return value
DEPARTMENT OF ECE Page No 11
BASICS OF C LANGUAGE

3.5.2 Functions without argument


1. Return Value
2. No return value

3.6 Loops
A loop statement allows us to execute a statement or group of statements
multiple times.

3.6.1 Entry Controlled Loops


• While loop is used for n-number of lines are first check the statement and after
executes the loop.
• For loop
i. Initialization
ii. Declaration
iii. Increment and repeat the process
Execution will be return only one statement

3.6.2 Exit Controlled Loops


• do while loop first executes the statement and after check the condition.

3.7 Keil Software


3.7.1 How to download
• Go to https://www.keil.com/download/product/ -> Download -> Product
Downloads -> Hit on C51 Setup. Enter your contact information with a valid
address, phone number and email. Fill in all fields of form.
• Then click on C51V954A.EXE and Download it on your computer

3.7.2 How to install


• Run setup file C51V954A.EXE and then we’ll get a pop-up box, hit on Next
and Proceed Installation.
• Read the license agreement, check I agree to all the terms…., and click Next.
• Select the Destination folder where you want to install Keil or default
destination is already there. And hit on Next.
• Fill up required fields with all relevant information and click on Next.
• Tick on show release notes, deselect remaining and click on Finish.
• That’s it. Installation is completed.

DEPARTMENT OF ECE Page No 12


BASICS OF C LANGUAGE

3.7.3 Keil Setup for 8051


• Open the Keil software and select the New Micro vision project from Project
menu and enter the project name.
• Once the project is saved a new pop up “Select Device for Target” opens, Select
the AT899C51 and click on OK.
• It asks to whether to copy the start-up code. Click on NO option to proceed.
• Create a New file by pressing ctrl + N to write the program code.
• Type the code and save the file with .c extension (Ex: code.c).
• Add the program file to the project by pressing Right Click on the Source Group
and click on “Add Existing File” and select the program file.
• Click on build project, fix the compiler errors or warnings if any.
• Code gets compiled successfully.

3.7.4 Generate Hex Code


• Click on “Options for Target”.
• Click on Output Tab.
• Check the “Create HEX File”.
• Click Ok & Rebuild the project to generate hex file.
• HEX file will be on the objects folder in the project folder.

3.8 PROGRAMS
3.8.1 Program to blink the LEDs are connected to port 0

#include <reg51.h>

void delay (int time);


void main ()
{
while (1)
{
P0 = 0x00;
delay (50);
P0 = 0xFF;
delay (50);
}
}

DEPARTMENT OF ECE Page No 13


BASICS OF C LANGUAGE

void delay (int time)


{
int i, j;
for (i=0; i<time; i++)
For (j=0; j<1275; j++);
}

3.8.2 Program to blink the LEDs are connected to port 0, port 2, port 3

#include <reg51.h>

void delay (int time);


void main ()
{
while (1)
{
P0 = 0xAA;
delay (50);
P2 = 0x28;
delay (100);
P3 = 0x16;
delay (150);
}
}
void delay (int time)
{
int i, j;
for (i=0; i<time; i++)
For (j=0; j<1275; j++);
}

DEPARTMENT OF ECE Page No 14


CHAPTER 4

INTRODUCTION TO 8051 MICROCONTROLLER


INTRODUCTION TO 8051 MICROCONTROLLER

INTRODUCTION TO 8051 MICROCONTROLLER


4.1 Introduction
Microcontroller is a special digital processor system and particularly used for
the real time control applications. It is a single chip VLSI unit. It is the most essential
part of a control or communication circuit having another special digital processor
system. It has limited computational capabilities and enhanced input output capabilities.
Microcontrollers are essentially simple miniature personal computers (PCs)
designed to control small features of a larger component, without a complex front-end
operating system (OS).

4.2 Specifications
1. 2.7v to 6v operating range.
2. 4 Kbytes of in-system programmable flash memory.
3. RAM is 128 bytes
4. 32 programmable I/O lines arranged four 8-bit ports.
5. Two 16-bit timer/counter
6. 6 interrupts
7. It works with EEPROM
8. 16-bit unidirectional address bus

4.3 Pin Description Of 8051


The 8051 is a 40pin IC available in dual in-line package (DIP). It is based on
N-channel HMOS technology and operates at +5v. Its maximum internal clock
frequency range is 12MHz.
Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other
functions. It is internally pulled up, bi-directional I/O port.
Pin 9 − It is a RESET pin. RST pin is used to reset the microcontroller to its initial
values.
Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like
interrupts, timer input, control signals, serial communication signals RxD and TxD, etc.
Pins 18 & 19 − These pins are used for interfacing an external crystal to get the system
clock.
Pin 20 − This pin provides the power supply to the circuit.
Pins 21 to 28 − These pins are known as Port 2. It serves as an I/O port. Higher order
address bus signals are also multiplexed using this port.

DEPARTMENT OF ECE Page No 15


INTRODUCTION TO 8051 MICROCONTROLLER

Fig 4.1 - Pin Diagram Of 8051


Pin 29 − This is a PSEN pin which stands for Program Store Enable. It is used to read
a signal from the external program memory.
Pin 30 − This is an EA pin which stands for External Access input. It is used to
enable/disable the external memory interfacing.
Pin 31 − This is the ALE pin which stands for Address Latch Enable. It is used to
demultiplex the address-data signal of a port.
Pins 32 to 39 − These pins are known as Port 0. It serves as an I/O port. Lower order
address and data bus signals are multiplexed using this port.
Pin 40 − This pin is used to provide power supply to the circuit.

4.4 Difference Between Microprocessor and Microcontroller

S. No Microprocessor Microcontroller

Microprocessor is the heart of Microcontroller is the heart of an


1.
Computer system. embedded system.

DEPARTMENT OF ECE Page No 16


INTRODUCTION TO 8051 MICROCONTROLLER

S. No Microprocessor Microcontroller

It is only a processor, so memory


It has a processor along with internal
2. and I/O components need to be
memory and I/O components.
connected externally

Memory and I/O has to be connected


Memory and I/O are already present,
3. externally, so the circuit becomes
and the internal circuit is small.
large.

Due to external components, the


As external components are low,
total power consumption is high.
total power consumption is less. So,
4. Therefore, it is not ideal for the
it can be used with devices running
devices running on stored power like
on stored power like batteries.
batteries.

It has no RAM, ROM, Input-Output It has a CPU along with RAM, ROM,
5. units, timers, and other peripherals and other peripherals embedded on a
on the chip. single chip.

It’s used for general purpose


It’s used for application-specific
6. applications that allow you to handle
systems.
loads of data.

Table 4.1 - Difference between Microprocessor and Microcontroller

4.5 Advantages
• The low time required for performing the operation
• It is easy to use, troubleshooting and system maintenance is simple
• At the same time, many tasks can be performed so the human effect can be
saved
• The processor chip is very small and flexibility occurs
• Due to their higher integration, cost and size of the system is reduced
• The microcontroller is easy to interface additional RAM, ROM, and I/O port
• Once microcontroller is programmed then they cannot be reprogrammed
• Without any digital parts, it can act as microcomputer
• It is easy to use, troubleshooting and system maintaining is simple

DEPARTMENT OF ECE Page No 17


INTRODUCTION TO 8051 MICROCONTROLLER

4.6 Disadvantages
• It is generally used in micro equipment
• It has a more complex structure as compared to microprocessor
• The microcontroller cannot interface a higher power device directly
• It only performed a limited number of executions simultaneously

4.7 Architecture Of 8051


It is an 8-bit microcontroller. It is built with 40 pins DIP (dual inline package),
4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit timers. It consists of are
four parallel 8-bit ports, which are programmable as well as addressable as per the
requirement. An on-chip crystal oscillator is integrated in the microcontroller having
crystal frequency of 12 MHz.

Fig 4.2 - Architecture of 8051


The system bus connects all the support devices to the CPU. The system bus
consists of an 8-bit data bus, a 16-bit address bus and bus control signals. All other
devices like program memory, ports, data memory, serial interface, interrupt control,
timers, and the CPU are all interfaced together through the system bus.

DEPARTMENT OF ECE Page No 18


INTRODUCTION TO 8051 MICROCONTROLLER

4.8 Timers & Counters


Timer: A timer is a specialized type of clock which is used to measure time intervals.
A timer that counts from zero upwards for measuring time elapsed is often called a
stopwatch. It is a device that counts down from a specified time interval and used to
generate a time delay, for example, an hourglass is a timer.

Counter: A counter is a device that stores (and sometimes displays) the number of
times a particular event or process occurred, with respect to a clock signal. It is used to
count the events happening outside the microcontroller. In electronics, counters can be
implemented quite easily using register-type circuits such as a flip-flop.

4.9 Difference between a Timer and a Counter


The points that differentiate a timer from a counter are as follows

S. No Timer Counter

The register is incremented considering


The register incremented for
1 1 to 0 transition at its corresponding to
every machine cycle.
an external input pin (T0, T1).

Maximum count rate is 1/12 of Maximum count rate is 1/24 of the


2
the oscillator frequency. oscillator frequency.

A timer uses the frequency of the


A counter uses an external signal to
3 internal clock, and generates
count pulses.
delay.

Table 4.2 - Difference between a Timer and a Counter

4.10 Timers of 8051 and their Associated Registers


The 8051 has two timers, Timer 0 and Timer 1. They can be used as timers or
as event counters. Both Timer 0 and Timer 1 are 16-bit wide. Since the 8051 follows
an 8-bit architecture, each 16 bit is accessed as two separate registers of low-byte and
high-byte.

4.10.1 Timer 0 Register


The 16-bit register of Timer 0 is accessed as low- and high-byte. The low-byte
register is called TL0 (Timer 0 low byte) and the high-byte register is called TH0 (Timer
0 high byte). These registers can be accessed like any other register.

DEPARTMENT OF ECE Page No 19


INTRODUCTION TO 8051 MICROCONTROLLER

Fig 4.3 - Timer 0


4.10.2 Timer 1 Register
The 16-bit register of Timer 1 is accessed as low- and high-byte. The low-byte
register is called TL1 (Timer 1 low byte) and the high-byte register is called TH1 (Timer
1 high byte). These registers can be accessed like any other register.

Fig 4.4 - Timer 1

4.11 TMOD (Timer Mode) Register


Both Timer 0 and Timer 1 use the same register to set the various timer
operation modes. It is an 8-bit register in which the lower 4 bits are set aside for Timer
0 and the upper four bits for Timers. In each case, the lower 2 bits are used to set the
timer mode in advance and the upper 2 bits are used to specify the location.

Fig 4.5 - TMOD Register


Gate − When set, the timer only runs while INT (0, 1) is high.
C/T − Counter/Timer select bit.
M1 − Mode bit 1.
M0 − Mode bit 0.

4.11.1 GATE
Every timer has a means of starting and stopping. Some timers do this by
software, some by hardware, and some have both software and hardware controls. 8051

DEPARTMENT OF ECE Page No 20


INTRODUCTION TO 8051 MICROCONTROLLER

timers have both software and hardware controls. The start and stop of a timer is
controlled by software using the instruction SETB TR1 and CLR TR1 for timer 1, and
SETB TR0 and CLR TR0 for timer 0.
The SETB instruction is used to start it and it is stopped by the CLR instruction.
These instructions start and stop the timers as long as GATE = 0 in the TMOD register.
Timers can be started and stopped by an external source by making GATE = 1 in the
TMOD register.

4.11.2 C/T (CLOCK / TIMER)


This bit in the TMOD register is used to decide whether a timer is used as a
delay generator or an event manager. If C/T = 0, it is used as a timer for timer delay
generation. The clock source to create the time delay is the crystal frequency of the
8051. If C/T = 0, the crystal frequency attached to the 8051 also decides the speed at
which the 8051 timer ticks at a regular interval.
Timer frequency is always 1/12th of the frequency of the crystal attached to the
8051. Although various 8051 based systems have an XTAL frequency of 10 MHz to
40 MHz, we normally work with the XTAL frequency of 11.0592 MHz. It is because
the baud rate for serial communication of the 8051.XTAL = 11.0592 allows the 8051
system to communicate with the PC with no errors.

4.11.3 M1 / M2
M1 M2 Mode
0 0 13-bit timer mode.
0 1 16-bit timer mode.
1 0 8-bit auto reload mode.
1 1 Spilt mode.

Table 4.3 - Timer Modes

4.12 Different Modes of Timers


4.12.1 Mode 0 (13-Bit Timer Mode)
Both Timer 1 and Timer 0 in Mode 0 operate as 8-bit counters (with a divide-
by-32 prescaler). Timer register is configured as a 13-bit register consisting of all the 8
bits of TH1 and the lower 5 bits of TL1. The upper 3 bits of TL1 are indeterminate and
should be ignored. Setting the run flag (TR1) does not clear the register. The timer
interrupt flag TF1 is set when the count rolls over from all 1s to all 0s. Mode 0 operation
is the same for Timer 0 as it is for Timer 1.

DEPARTMENT OF ECE Page No 21


INTRODUCTION TO 8051 MICROCONTROLLER

4.12.2 Mode 1 (16-Bit Timer Mode)


Timer mode "1" is a 16-bit timer and is a commonly used mode. It functions in
the same way as 13-bit mode except that all 16 bits are used. TLx is incremented starting
from 0 to a maximum 255. Once the value 255 is reached, TLx resets to 0 and then THx
is incremented by 1. As being a full 16-bit timer, the timer may contain up to 65536
distinct values and it will overflow back to 0 after 65,536 machine cycles.

4.12.3 Mode 2 (8 Bit Auto Reload)


Both the timer registers are configured as 8-bit counters (TL1 and TL0) with
automatic reload. Overflow from TL1 (TL0) sets TF1 (TF0) and also reloads TL1 (TL0)
with the contents of Th1 (TH0), which is preset by software. The reload leaves TH1
(TH0) unchanged.
The benefit of auto-reload mode is that you can have the timer to always contain
a value from 200 to 255. If you use mode 0 or 1, you would have to check in the code
to see the overflow and, in that case, reset the timer to 200. In this case, precious
instructions check the value and/or get reloaded. In mode 2, the microcontroller takes
care of this. Once you have configured a timer in mode 2, you don't have to worry about
checking to see if the timer has overflowed, nor do you have to worry about resetting
the value because the microcontroller hardware will do it all for you. The auto-reload
mode is used for establishing a common baud rate.

4.12.4 Mode 3 (Split Timer Mode)


Timer mode "3" is known as split-timer mode. When Timer 0 is placed in mode
3, it becomes two separate 8-bit timers. Timer 0 is TL0 and Timer 1 is TH0. Both the
timers count from 0 to 255 and in case of overflow, reset back to 0. All the bits that are
of Timer 1 will now be tied to TH0.
When Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be set
in modes 0, 1 or 2, but it cannot be started/stopped as the bits that do that are now linked
to TH0. The real timer 1 will be incremented with every machine cycle.

DEPARTMENT OF ECE Page No 22


CHAPTER 5

MICROCONTROLLER PERIPHERALS
MICROCONTROLLER PERIPHERALS

MICROCONTROLLER PERIPHERALS
5.1 Liquid Crystal Display
The LCD is the combination of two states of matter, the solid and liquid. It uses
liquid crystal to produce a visible image. LCDs are super thin technology display
screens that are generally used in laptops, computers.
1. 16x2 LCD
2. 20x4 LCD

5.2 Specifications
• Operating voltage is 4.7v to 5.3v.
• Current consumption is 1mA without backlight.
• Alphanumeric LCD display module.
• It consists of two rows and each row can print 16 characters.
• Each character is built by a 5x8 pixel box.
• Available in green and blue backlight.
• It can also display any custom generated characters.
• It can work in both 8-bit and 4-bit mode.

5.3 PIN description of 16x2 LCD

Fig 5.1 - PIN Diagram of 16x2 LCD


• Vss : Ground pin
• Vcc : +5v supply is used to display the dotted lines and these +5v are also used
for backlight
• Vee : It is used to control the brightness
• Register Select (RS) :
i. When the RS pin is low then it takes the input as command.
ii. When the RS pin is high then it takes the input as data
DEPARTMENT OF ECE Page No 23
MICROCONTROLLER PERIPHERALS

• Read/Write (RW) :
i. When the R/W pin is low then it performs a write operation.
ii. When the R/W pin is high then it performs a read operation.
• Enable :
i. When the enable pin is high, it allows the commands and data.
ii. When the enable pin is low, it doesn’t allow the commands and data.
• D0 - D7: These are the data input pins.
• Anode & Cathode: These two pins are used for ON and OFF of the LED.
Note:
• When the RS = 0 then the enable pin gets high to receive the commands. After
receiving commands, the enable pin gets low.
• When the RS = 1 then the enable pin gets high to receive the data. After
receiving data, the enable pin gets low.

5.4 LCD Commands

Hex Code Commands

01 Clear display screen

02 Return home

04 Decrement Cursor (Shift cursor to left)

06 Increment Cursor (Shift cursor to right)

05 Shift display to right side

07 Shift display to left side

08 Display off cursor off

0A Display off cursor on

0C Display on cursor off

0E Display on cursor blinking

0F Display off cursor constant

10 Shift cursor position to left

DEPARTMENT OF ECE Page No 24


MICROCONTROLLER PERIPHERALS

Hex Code Commands

14 Shift cursor position to right

18 Shift entire display to left

1C Shift entire display to right

80 Force cursor to begin in 1st line

C0 Force cursor to begin in 2nd line

38 Two lines and 5*7 matrix activate

Table 5.1 - LCD Commands


Mainly in general purpose the applicable codes are:
• (0x38)
• (0x01)
• (0x0E)
• (0x80)

5.5 LCD Interfacing with 8051


5.5.1 Program to interface LCD to 8051 in 8-bit mode
#include<reg51.h>
#define LCD P1

sbit rs = P2^0;
sbit en = P2^1;

void lcdcmd (unsigned char cmd);


void lcddata (unsigned char dat);
void msg (unsigned char g[])
void delay (unsigned int time);
void main()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);

DEPARTMENT OF ECE Page No 25


MICROCONTROLLER PERIPHERALS

lcdcmd(0x06);
lcdcmd(0x80);
msg(“Good Boy Gopal”);
}
void lcdcmd (unsigned char cmd);
{
LCD = cmd;
rs = 0;
en = 1;
delay (10);
en = 0;
}
void lcddata (unsigned char dat);
{
LCD = dat;
rs = 1;
en = 1;
delay (10);
en = 0;
}
void msg(unsigned char g[])
{
unsigned char k;
for (k=0; g[k]!='\0'; k++)
{
lcddata(g[k]);
}
}
void delay (unsigned int time)
{
int i, j;
for (i=0; i<time; i++)
For (j=0; j<1275; j++);
}

DEPARTMENT OF ECE Page No 26


MICROCONTROLLER PERIPHERALS

5.5.2 Program to interface LCD to 8051 in 4-bit mode

#include <reg51.h>
#define port1 P1
sbit rs = P2^2;
sbit en = P2^3;

void lcdcmd(unsigned char value);


void lcddata(unsigned char value);
void msg(unsigned char b[]);
void delay(unsigned int value);

void main()
{
lcdcmd(0x28);
lcdcmd(0x0e);
lcdcmd(0x01);
lcdcmd(0x80);
msg("GOOD BOY GOPAL");
}

void lcdcmd(unsigned char value)


{

port1=value&(0xf0); //send msb 4 bits


rs=0; //select command register
en=1; //enable the lcd to execute command
delay(3);
en=0;
port1=((value<<4)&(0xf0)); //send lsb 4 bits
rs=0; //select command register
en=1; //enable the lcd to execute command
delay(3);
en=0;
}

DEPARTMENT OF ECE Page No 27


MICROCONTROLLER PERIPHERALS

void lcddata(unsigned char value)


{
port1=value&(0xf0);
rs=1;
en=1;
delay(3);
en=0;
port1=((value<<4)&(0xf0));
rs=1;
en=1;
delay(3);
en=0;
}

void msg(unsigned char b[]) // send string to lcd


{
unsigned char s,count=0;
for(s=0;b[s]!='\0';s++)
{
lcddata(b[s]);
}
}

void delay(unsigned int value)


{
unsigned int x,y;
for(x=0;x<value;x++)
for(y=0;y<1275;y++);
}

5.6 Matrix Keypad


• The keypad is used as an input device to read the key pressed by the user and
to process it.
• 4x4 keypad consists of 4 rows and 4 columns. Switches are placed between
the rows and columns. A keypress establishes a connection between the
corresponding row and column between which the switch is placed.

DEPARTMENT OF ECE Page No 28


MICROCONTROLLER PERIPHERALS

Fig 5.2 - 4*4 Matrix Keypad

• To read the keypress, we need to configure the rows as outputs and columns
as inputs.
• Columns are read after applying signals to the rows in order to determine
whether or not a key is pressed and if pressed, which key is pressed.

5.7 Working of Matrix Keypad


To detect the key that’s pressed, two ports of the microcontroller are connected
to the rows and columns of the matrix respectively. The port which is connected to the
rows of the matrix is configured as an output port, hence making each row logic 0. On
the contrary, the port which is connected to the columns is configured as an input port,
making the column at logic 1.

Fig 5.3 - Schematic of 4*4 Matrix Keypad

DEPARTMENT OF ECE Page No 29


MICROCONTROLLER PERIPHERALS

To detect the key that’s pressed, two ports of the microcontroller are connected
to the rows and columns of the matrix respectively. The port which is connected to the
rows of the matrix is configured as an output port, hence making each row logic 0. On
the contrary, the port which is connected to the columns is configured as an input port,
making the column at logic 1.
To find the row which has the pressed key, the microcontroller grounds the
rows one by one and checks in which case the column is logic zero. This helps the
microcontroller to find which key was pressed.

5.8 Interfacing Matrix Keypad with 8051

Fig 5.4 - Interfacing Matrix Keypad & LCD with 8051


Program:
#include <reg51.h>
void MSDelay(unsigned int );
void LCDtransfer(unsigned char );
void send_command(unsigned char);
void send_data(unsigned char);
sfr COL = 0x90;
sfr ROW = 0xB0;
sfr ldata = 0xA0; //P1 = LCD dat pins
sbit rs = P0^5;

DEPARTMENT OF ECE Page No 30


MICROCONTROLLER PERIPHERALS

sbit rw = P0^6;
sbit en = P0^7;
unsigned char keypad[4][4] = {'7','8','9','/',
'4','5','6','x',
'1','2','3','-',
'e','0','=','+'};
void main()
{
unsigned char collocation,rowlocation;
COL = 0xFF;// Sents port 3 as output port
while(1)
{
do
{
ROW =0X00; //sets the row matrix as an input port
collocation = COL;
collocation &= 0x0F;
}while(collocation != 0x0F);// waits for one of the coloumns to be logic 0
do
{
do
{
MSDelay(20);
collocation = COL;
collocation &= 0x0F;
}while(collocation == 0x0F);
MSDelay(20); // delay fucntion to prevent debouncing
collocation = COL;
collocation &=0x0F;
}while(collocation == 0x0F);
while(1) // finds which row the key belong to
{
ROW = 0XFE;
collocation = COL;
collocation &=0x0F;

DEPARTMENT OF ECE Page No 31


MICROCONTROLLER PERIPHERALS

if(collocation != 0x0F)
{
rowlocation = 0;
break;
}
ROW = 0XFD;
collocation = COL;
collocation &=0x0F;
if(collocation != 0x0F)
{
rowlocation = 1;
break;
}
ROW = 0XFB;
collocation = COL;
collocation &=0x0F;
if(collocation != 0x0F)
{
rowlocation = 2;
break;
}
ROW = 0XF7;
collocation = COL;
collocation &=0x0F;
rowlocation = 3;
break;
}
send_command(0x38); // 16_bit mode; Enable 5x7 dot matrix for each character
MSDelay(250);
send_command(0x0E); // Display ON & cursor ON
MSDelay(250);
send_command(0x01); // Clear the Display
MSDelay(250);
send_command(0x06); // To shift the cursor right
MSDelay(250);

DEPARTMENT OF ECE Page No 32


MICROCONTROLLER PERIPHERALS

send_command(0x83); // Set the cursor at line 1, position 3


MSDelay(250);
if(collocation ==0x0E)
LCDtransfer(keypad[rowlocation][0]);
else if(collocation == 0x0D)
LCDtransfer(keypad[rowlocation][1]);
else if(collocation == 0x0B)
LCDtransfer(keypad[rowlocation][2]);
else
LCDtransfer(keypad[rowlocation][3]);
}
}
void MSDelay(unsigned int value)
{
unsigned int x, y;
for(x=0;x<1275;x++)
for(y=0;y<value;y++);

}
void LCDtransfer(unsigned char keypress)
{
ldata = keypress;
rs = 1;
rw = 0;
en = 1;
MSDelay(10);
en = 0;
return;
}

void send_command(unsigned char value)


{
ldata = value;
rs = 0;
rw = 0;

DEPARTMENT OF ECE Page No 33


MICROCONTROLLER PERIPHERALS

en = 1;
MSDelay(10);
en = 0;
return;
}

5.9 Sensors
A sensor is a device that detects and responds to some type of input from the
physical environment. The specific input could be light, heat, motion, moisture,
pressure, or any one of a great number of other environmental phenomena. The output
is generally a signal that is converted to human-readable display at the sensor location
or transmitted electronically over a network for reading or further processing.

Fig 5.5 - Sensor Block Diagram


There are two types of sensors:
• Analog Sensors
• Digital Sensors

5.9.1 Analog Sensors


There are different types of sensors that produce continuous analog output
signal and these sensors are analog sensors. This continuous output signal produced by
the analog sensors is proportional to the measured. Generally, there are various types
of analog sensors; practical examples of various types of analog sensors are as follows:
accelerometers, pressure sensors, light sensors, sound sensors, temperature sensors, and
so on.

DEPARTMENT OF ECE Page No 34


MICROCONTROLLER PERIPHERALS

So, the Analogue sensor senses the external parameters (wind speed, solar
radiation, light intensity, etc.) and gives analog voltage as an output. Thus, the output
voltage may be in the range of 0 to 5V. Moreover, Logic High is “1” (3.5 to 5V) and
Logic Low is “0” (0 to 3.5 V).

5.9.2 Digital Sensors


Digital sensors are the kind of electrochemical or electrical sensors where the
information is converted to digital form and then transmitted. The output of a digital
sensor is the distinct digital signal of the quantity which is being measured. And the
measured quantities might be of conductivity, pH value, redox potentials, and many
others. The output is in the form of 1’s and 0’s where ‘1’ represents ON condition and
‘0’ represents OFF condition. This corresponds that a digital signal generates distinct
(non-continuous) values and the output is considered either as a single “bit”, (serial
transmission) or the combination of multiple bits called “byte” and is called (parallel
transmission).

5.10 Light Sensor


There are different types of light sensors available such as photo-resistors,
photo-diodes, photovoltaic cells, photo-tubes, photo-multiplier tubes, photo-
transistors, charge-coupled devices, and so on. But, LDR (Light Dependent Resistor or
photo-resistor) is a light sensor in this light sensor circuit. These LDR sensors are
passive and don’t produce any electrical energy.

Fig 5.6 - LDR Sensor


But, the resistance of the LDR changes with the change in the (light illuminated
on the LDR) daylight intensity. LDR sensor is a terrain in nature, even in dirty and
rough external environments. Hence, LDR is preferable to other light sensors as it can
be used even in the outdoor lighting of homes and in automatic street lights as well.

5.11 IR Sensor
The IR sensor or infrared sensor is one kind of electronic component, used to
detect specific characteristics in its surroundings through emitting or detecting IR
radiation. These sensors can also be used to detect or measure the heat of a target and

DEPARTMENT OF ECE Page No 35


MICROCONTROLLER PERIPHERALS

its motion. In many electronic devices, the IR sensor circuit is a very essential module.
This kind of sensor is similar to human’s visionary senses to detect obstacles.

Fig 5.7 - IR MODULE

Types of IR Sensor
The classification of IR sensors can be done based on the application which
includes the following.
• Active Infrared Sensors
• Passive Infrared Sensors

5.11.1 Active Infrared Sensors


This type of sensor includes both the emitter & the receiver which are also
known as transmitter & receiver. In most situations, a laser diode or LED is used as a
source. For non-imaging infrared sensors, LED is used whereas laser diode is used for
imaging infrared sensors.
The working of an infrared sensor can be done through radiating energy,
detected and received through the detector. Further, it is processed through a signal
processor to fetch the required data. The best examples of active infrared sensors are
reflectance & break beam sensors.

5.11.2 Passive Infrared Sensor


Passive Infrared Sensor (PIR) includes detectors only and this kind of sensor
uses targets like infrared transmitters or sources. Here, the object will radiate the energy
& detects it through infrared receivers. After that, a signal processor is used to
understand the signal to obtain the required data.
The best examples of PIR sensors are bolometer, Pyro-Electric Detector,
Thermocouple-Thermopile, etc. PIR sensors are available in two types like thermal IR
sensor and quantum IR sensor.

DEPARTMENT OF ECE Page No 36


MICROCONTROLLER PERIPHERALS

Fig 5.8 - PIR Sensor

5.12 Ultrasonic Sensor


An ultrasonic sensor is an electronic device that measures the distance of a
target object by emitting ultrasonic sound waves, and converts the reflected sound into
an electrical signal. Ultrasonic waves travel faster than the speed of audible sound (i.e.
the sound that humans can hear). Ultrasonic sensors have two main components: the
transmitter (which emits the sound using piezoelectric crystals) and the receiver (which
encounters the sound after it has travelled to and from the target).

Fig 5.9 - Ultrasonic Sensor

In order to calculate the distance between the sensor and the object, the sensor
measures the time it takes between the emissions of the sound by the transmitter to its
contact with the receiver. The formula for this calculation is D = ½ T x C (where D is
the distance, T is the time, and C is the speed of sound ~ 343 meters/second).

DEPARTMENT OF ECE Page No 37


MICROCONTROLLER PERIPHERALS

5.13 Motor Drivers


L293D is a typical Motor driver or Motor Driver IC which allows DC motor to
drive on either direction. L293D is a 16-pin IC which can control a set of two DC
motors simultaneously in any direction. It means that you can control two DC motor
with a single L293D IC.

5.14 Features of L293D Motor Driver


• 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

5.15 PIN diagram of L293D Motor Driver

Fig 5.10 - PIN Diagram of L293D Motor Driver

DEPARTMENT OF ECE Page No 38


MICROCONTROLLER PERIPHERALS

PIN DESCRIPTION:

Pin Name Description


Pin1
Pin 1 is known as the enable pin.
(Enable)
Pin2 Mostly input means where we provide the input to give the output.
(Input 1) But here Input 1 means which polarity we want to give at Output 1.
Pin3 Output 1 is the input of the first motor/Motor 1. It attaches to its one
(Output 1) end.
Pin4
The ground pin will attach to the ground of the circuit.
(Ground)
Pin5 The ground pin will be attached to the ground, and it will remain
(Ground) common with the previous ground.
Pin6 Output 2 will attach to the input of the first motor/Motor 1. It will
(Output 2) attach to its second end.
Pin7 (Input Input 2 will attach to the control button or device to control the Output
2) 2 just like Input 1.
Pin8 is the voltage pin for Motor. It will device how much power we
Pin8 (Vcc) are going to attach the Motor. This Power should not be more than 36
volts and should not be less than 4.5 volts.
Pin 9 is also the same as Pin 1. It controls the input and output signals.
Pin9 Pin 9 Controls the connection between Input 3, Input 4, Output 3 and
(Enable) Output 4. It also enables the connection when the logic signal will be
High (1).
Pin10 Input 3 will control the output polarity of the Pin 11 (Output 3) by
(Input 3) logic signals.
Pin11
Output 3 will be connected to the one end of the second motor.
(Output 3)
Pin 12
Pin 12 will attach to the common ground with all other grounds.
(Ground)
Pin13 Pin 13 will also be attached to the common ground with all other
(Ground) grounds.
Pin14
Pin 14 will attach to the second end of the second motor.
(Output 4)

DEPARTMENT OF ECE Page No 39


MICROCONTROLLER PERIPHERALS

Pin Name Description

Pin15 Pin 15 will control the output polarity of the Pin 14 (Output 4) by
(Input 4) logic signals.
Pin16 Pin 16 will the Power we will provide to the L293D to activate it or
(Vcc) to turn it on. The power level of Pin 16 should be 4.5 – 7Volts.

Table 5.2 - PIN Diagram of L293D

5.16 Interfacing of L293D


All the Ground pins should be grounded. There are two power pins for this IC,
one is the Vss (Vcc1) which provides the voltage for the IC to work, this must be
connected to +5V. The other is Vs (Vcc2) which provides voltage for the motors to
run, based on the specification of your motor you can connect this pin to anywhere
between 4.5V to 36V, here I have connected to +12V.

Fig 5.11 - L293D Interfacing with Motors


The Enable pins (Enable 1, 2 and Enable 3, 4) are used to Enable Input pins for
Motor 1 and Motor 2 respectively. Since in most cases we will be using both the motors
both the pins are held high by default by connecting to +5V supply. The input pins
Input 1,2 are used to control the motor 1 and Input pins 3,4 are used to control the
Motor 2. The input pins are connected to the any Digital circuit or microcontroller to
control the speed and direction of the motor.

DEPARTMENT OF ECE Page No 40


MICROCONTROLLER PERIPHERALS

5.17 Applications of L23D


• Used to drive high current Motors using Digital Circuits
• Can be used to drive Stepper motors
• High current LED’s can be driven
• Relay Driver module (Latching Relay is possible)

DEPARTMENT OF ECE Page No 41


CHAPTER 6
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS


6.1 Introduction
A converter that is used to change the analogue signal to digital is known as an
analog to digital converter or ADC converter.
(ADCs) allow micro-processor controlled circuits, Arduinos, Raspberry Pi, and
other such digital logic circuits to communicate with the real world. In the real world,
analogue signals have continuously changing values which come from various sources
and sensors which can measure sound, light, temperature or movement, and many
digital systems interact with their environment by measuring the analogue signals from
such transducers.
Basically an analogue to digital converter takes a snapshot of an analogue
voltage at one instant in time and produces a digital output code which represents this
analogue voltage. The number of binary digits, or bits used to represent this analogue
voltage value depends on the resolution of an A/D converter.

6.2 Characteristics of ADC


The following are the characteristics of the ADC.
• Resolution
• Conversion time
• Vref
• Digital data output
• Parallel versus serial ADC
• Analog input channels
• Start-conversion and end-of-conversion signals

Fig 6.1 - Block Diagram of ADC


DEPARTMENT OF ECE Page No 42
ANALOG TO DIGITAL CONVERTERS

6.3 ADC 0804


The ADC0804 is a commonly used ADC module, for projects were an external
ADC is required. It is a 20-pin Single channel 8-bit ADC module. Meaning it can
measure one ADC value from 0V to 5V and the precision when voltage reference (Vref
–pin 9) is +5V is 19.53mV (Step size). That is for every increase of 19.53mV on input
side there will be an increase of 1 bit at the output side.

6.3.1 PIN Diagram of ADC 0804

Fig 6.2 - PIN Diagram of ADC 0804


Pin Description of ADC804:
Pin 1: It is a chip select pin and activates ADC, active low
Pin 2: It is an input pin; high to low pulse brings the data from internal registers to the
output pins after conversion
Pin 3: It is an input pin; low to high pulse is given to start the conversion
Pin 4: It is a clock input pin, to give the external clock
Pin 5: It is an output pin, goes low when the conversion is complete
Pin 6: Analog non-inverting input
Pin 7: Analog inverting input, it’s normally ground

DEPARTMENT OF ECE Page No 43


ANALOG TO DIGITAL CONVERTERS

Pin 8: Ground (0V)


Pin 9: It is an input pin, sets the reference voltage for analog input
Pin 10: Ground (0V)
Pin 11 - Pin 18: It is an 8-bit digital output pin
Pin 19: Is used with Clock IN pin when internal clock source is used
Pin 20: Supply voltage: 5V

6.3.2 Features of 0804


• Easy to interface with all Microprocessors or works Stand alone.
• Single channel 8-bit ADC module
• On chip Clock available, no need of external Oscillator (Clock)
• Digital output various from 0 to 255
• When Vref = 5V, for every 19.53mV of analog value there will be rise of one
bit on digital side (Step size)
• Available in 20-pin PDIP, SOIC packages

6.4 ADC 0808


ADC0808 is an 8 bit analog to digital converter with eight input analog
channels, i.e., it can take eight different analog inputs. The input which is to be
converted to digital form can be selected by using three address lines. The step size is
decided based on set reference value. Step size is the change in analog input to cause a
unit change in the output of ADC. The default step size is 19.53mV corresponding to
5V reference voltage.
ADC0808 needs an external clock to operate unlike ADC0804 which has an
internal clock. The ADC needs some specific control signals for its operations like start
conversion and bring data to output pins. When the conversion is complete the EOC
pins goes low to indicate the end of conversion and data ready to be picked up.

6.4.1 PIN Diagram of ADC 0808


Pin 1 – Pin 5, Pin 27, and Pin 28: These 7 pins are the input pins for Analog voltage
(sensor)
Pin 6: This is an input pin which is made high to start conversion
Pin 7: This is an output pin which goes high once the conversion is over
Pins 8, 14, 15, 18, 19, 20, 21: Output digital pins which gives the result of the ADC
conversion
Pin 9: Has to be made high to get output on output pins

DEPARTMENT OF ECE Page No 44


ANALOG TO DIGITAL CONVERTERS

Pin 10: Has to be given clock signals (0V-5V) 20Mhz approx.

Fig 6.3 - PIN Diagram of ADC 0808


Pin 11: Powers the IC typically with 5V
Pin 12: Reference voltage pin, typically +5V is used normally
Pin 13: Connect to ground of the circuit
Pin 16: Vref is connected to ground normally
Pin 22: This pin is should be temporarily made high to select ADC channel
Pin 23 – Pin 25: These three pins are used to select the channel

6.4.2 Features of ADC 0808


• Easy to interface with all Microprocessors or works Stand alone.
• Eight channel 8-bit ADC module
• Can measure up to 8 Analog values seamlessly
• On chip Clock not available, external Oscillator is needed (Clock)
• Digital output various from 0 to 255, Operating power is 15mW, conversion
time 100us
• When Vref = 5V, for every 19.53mV of analog value there will be rise of one
bit on digital side (Step size)

DEPARTMENT OF ECE Page No 45


CHAPTER 7

PROTEUS
PROTEUS

PROTEUS
7.1 Introduction
The Proteus Design Suite is a proprietary software tool suite used primarily for
electronic design automation. The software is used mainly by electronic design
engineers and technicians to create schematics and electronic prints for manufacturing
printed circuit boards.
It was developed in Yorkshire, England by Labcenter Electronics Ltd and is
available in English, French, Spanish and Chinese languages.

7.2 Features
Schematic Capture:
Schematic capture in the Proteus Design Suite is used for both the simulation of designs
and as the design phase of a PCB layout project. It is therefore a core component and
is included with all product configurations.
Microcontroller Simulation:
The micro-controller simulation in Proteus works by applying either a hex file or a
debug file to the microcontroller part on the schematic. It is then co-simulated along
with any analog and digital electronics connected to it.
PCB Design:
The PCB Layout module is automatically given connectivity information in the form
of a netlist from the schematic capture module. It applies this information, together
with the user specified design rules and various design automation tools, to assist with
error free board design. PCB's of up to 16 copper layers can be produced with design
size limited by product configuration.
3D Verification:
The 3D Viewer module allows the board under development to be viewed in 3D
together with a semi-transparent height plane that represents the board’s enclosure.

7.3 How to download


• Proteus 8 Professional cracked version download link:
https://drive.google.com/file/d/0BzFNvqXQA8j6eXgzZjJLbGFXdzg/view
• Open the above link and click on download.
• Open the folder where software is downloaded.
• After that double click on proteus software setup file.
• After that click next and finish.

DEPARTMENT OF ECE Page No 46


PROTEUS

• Proteus 8 installation is completed.

7.4 PCB Designing


7.4.1 Schematic Capture
• First open proteus.
• Click on schematic capture (ISIA) section.
• Click on the ports option on the left-hand side.
• Pick the suitable components by entering keywords on search bar.
• After adding components, close the device section.
• Design a schematic diagram by using the picked components.

7.4.2 PCB Layout


• After getting the output of schematic capture, click on PCB layout (ARFS).
• Check whether the packages are assigned to all the components.
• If packages are missing go back to schematic capture.
• Right click on the components and select packaging tools.
• Click on the add button.
• Search for the package in the keyword’s sections and close picked packages.
• Assign the pins to the components respectively.
• Close the packaging tool section.
• Again, check for the packages if assign to the components or not.
• Place the components on the work space in schematic capture order.
• When the components are placed two of colour lines will appear.
• Green colour line indicates wiring/connections.
• Yellow colour line indicates the components place.
• Pick a designable manager from the top toolbar.
• Select net classes and assign the value of trackstile and nextile and make sure
to use only bottom copper.
• Now click on the track mode from the left toolbar.
• After completing the routing click on the 2D graphic box from the left toolbar.
• Select the layer to the board edge.
• Draw the outer box to the board edge.
• Click on 3D visualizer.

Design Role Management:


• In PCB section at top last option is design role management.

DEPARTMENT OF ECE Page No 47


PROTEUS

• Track style is depended up on given supply.


• Should avoid sharp edges.
• Red colour indicates the SMT devices (top copper).
• Blue colour indicates the through hole devices (bottom copper).

7.5 SMPS
Required Components:
• Step down transformer (6v)
• AC Source – 230v
• Bridge rectifier
• Capacitor
• Voltage regulator – 5V
• Voltage regulator – 12V
• DC Motor
• LED

Fig 7.1 - SMPS Schematic Diagram

7.6 Interfacing LED and Switch with 8051 Microcontroller


Program:
#include <reg51.h>
sbit S1 = P1^2;
sbit led = P2^2;
Void delay (unsigned int time);
void main()
{
DEPARTMENT OF ECE Page No 48
PROTEUS

S1 = 1;
led = 0;
if (S1 == 0)
{
led = 1;
delay (500);
}
else
{
led = 0;
}
}
void delay (unsigned int time)
{
unsigned int a,b;
for (a=0; a<time; a++)
for (b=0; b<1275; b++);
}

DEPARTMENT OF ECE Page No 49


CHAPTER 8
ARDUINO
ARDUINO

ARDUINO
8.1 Introduction
Arduino is an open-source platform used for building electronics projects.
Arduino consists of both a physical programmable circuit board (often referred to as a
microcontroller) and a piece of software, or IDE (Integrated Development
Environment) that runs on your computer, used to write and upload computer code to
the physical board.
The Arduino platform has become quite popular with people just starting out
with electronics, and for good reason. Unlike most previous programmable circuit
boards, the Arduino does not need a separate piece of hardware (called a programmer)
in order to load new code onto the board -- you can simply use a USB cable.
Additionally, the Arduino IDE uses a simplified version of C++, making it easier to
learn to program. Finally, Arduino provides a standard form factor that breaks out the
functions of the micro-controller into a more accessible package.

8.2 Arduino History


The Arduino project began in 2005 as a tool for students at the Interaction
Design Institute Ivrea, Italy, aiming to provide a low-cost and easy way for novices and
professionals to create devices that interact with their environment using sensors and
actuators. Common examples of such devices intended for beginner hobbyists include
simple robots, thermostats and motion detectors.
The name Arduino comes from a bar in Ivrea, Italy, where some of the founders
of the project used to meet. The bar was named after Arduin of Ivrea, who was the
margrave of the March of Ivrea and King of Italy from 1002 to 1014.

8.3 Arduino Family


Arduino makes several different boards, each with different capabilities. In
addition, part of being open source hardware means that others can modify and produce
derivatives of Arduino boards that provide even more form factors and functionality.
• Arduino UNO (R3)
• LilyPad Arduino.
• Red Board.
• Arduino Mega (R3)
• Arduino Leonardo.

DEPARTMENT OF ECE Page No 50


ARDUINO

• Arduino Nano
• Arduino Micro
• Arduino Bluetooth
• Arduino Ethernet
• NodeMcu Board
• Arduino Diecimila
• Arduino Zero

8.4 Arduino UNO


The Arduino UNO is the best board to get started with electronics and coding.
The UNO is the most used and documented board of the whole Arduino family.

Fig 8.1 - Arduino UNO

The board is equipped with sets of digital and analog input/output (I/O) pins
that may be interfaced to various expansion boards (shields) and other circuits. The
board has 14 digital I/O pins (six capable of PWM output), 6 analog I/O pins, and is
programmable with the Arduino IDE (Integrated Development Environment), via a
type B USB cable. It can be powered by the USB cable or by an external 9-volt battery,
though it accepts voltages between 7 and 20 volts. It is similar to the Arduino Nano and
Leonardo.
The word "uno" means "one" in Italian and was chosen to mark the initial
release of Arduino Software. The Uno board is the first in a series of USB-based

DEPARTMENT OF ECE Page No 51


ARDUINO

Arduino boards; it and version 1.0 of the Arduino IDE were the reference versions of
Arduino, which have now evolved to newer releases. The ATmega328 on the board
comes preprogrammed with a bootloader that allows uploading new code to it without
the use of an external hardware programmer.

8.5 Specifications of Arduino UNO


• Microcontroller: Microchip ATmega328P
• Operating Voltage: 5 Volts
• Input Voltage: 7 to 20 Volts
• Digital I/O Pins: 14 (of which 6 can provide PWM output)
• PWM Pins: 6 (Pin # 3, 5, 6, 9, 10 and 11)
• UART: 1
• I2C: 1
• SPI: 1
• Analog Input Pins: 6
• DC Current per I/O Pin: 20 mA
• DC Current for 3.3V Pin: 50 mA
• Flash Memory: 32 KB of which 0.5 KB used by bootloader
• SRAM: 2 KB
• EEPROM: 1 KB
• Clock Speed: 16 MHz
• Length: 68.6 mm
• Width: 53.4 mm
• Weight: 25 g
• ICSP Header: Yes
• Power Sources: DC Power Jack & USB Port

8.6 PIN Diagram of Arduino UNO


Vin: This is the input voltage pin of the Arduino board used to provide input supply
from an external power source.
5V: This pin of the Arduino board is used as a regulated power supply voltage and it is
used to give supply to the board as well as onboard components.
3.3V: This pin of the board is used to provide a supply of 3.3V which is generated from
a voltage regulator on the board

DEPARTMENT OF ECE Page No 52


ARDUINO

Fig 8.2 - PIN Diagram of Arduino UNO


GND: This pin of the board is used to ground the Arduino board.
Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the
microcontroller.
Analog Pins: The pins A0 to A5 are used as an analog input and it is in the range of 0-
5V.
Digital Pins: The pins 0 to 13 are used as a digital input or output for the Arduino
board.
Serial Pins: These pins are also known as a UART pin. It is used for communication
between the Arduino board and computer or other devices. The transmitter pin number
1 and receiver pin number 0 is used to transmit and receive the data respectively

DEPARTMENT OF ECE Page No 53


ARDUINO

External Interrupt Pins: This pin of the Arduino board is used to produce the External
interrupt and it is done by pin numbers 2 and 3.
PWM Pins: This pins of the board is used to convert the digital signal into an analog
by varying the width of the Pulse. The pin numbers 3, 5, 6, 9, 10 and 11 are used as a
PWM pin.
SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintain SPI
communication with the help of the SPI library. SPI pins include:
SS: Pin number 10 is used as a Slave Select
MOSI: Pin number 11 is used as a Master Out Slave In
MISO: Pin number 12 is used as a Master In Slave Out
SCK: Pin number 13 is used as a Serial Clock
LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only
when the digital pin becomes high.
AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide
a reference voltage from an external power supply

8.7 Advantages of Arduino


• Not much knowledge required to get started
• Fairly low cost, depending on shields you need
• Lots of sketches and shields available
• No external programmer or power supply needed

8.8 Disadvantages of Arduino


• No understanding of the AVR microcontroller
• Sketches and shields can be difficult to modify
• No debugger included for checking scripts
• You get no experience of C or professional development tools

8.9 Applications of Arduino


• Weighing Machines.
• Traffic Light Count Down Timer.
• Parking Lot Counter.
• Embedded systems.
• Home Automation.
• Industrial Automation.

DEPARTMENT OF ECE Page No 54


ARDUINO

• Medical Instrument.
• Emergency Light for Railways.

8.10 Arduino IDE


The Arduino integrated development environment (IDE) is a cross-platform
application (for Microsoft Windows, macOS, and Linux) that is written in the Java
programming language. It originated from the IDE for the languages Processing and
Wiring. It includes a code editor with features such as text cutting and pasting,
searching and replacing text, automatic indenting, brace matching, and syntax
highlighting, and provides simple one-click mechanisms to compile and upload
programs to an Arduino board. It also contains a message area, a text console, a toolbar
with buttons for common functions and a hierarchy of operation menus. The source
code for the IDE is released under the GNU General Public License, version 2.

The Arduino IDE supports the languages C and C++ using special rules of code
structuring. The Arduino IDE supplies a software library from the Wiring project,
which provides many common input and output procedures. User-written code only
requires two basic functions, for starting the sketch and the main program loop, that are
compiled and linked with a program stub main() into an executable cyclic executive
program with the GNU toolchain, also included with the IDE distribution. The Arduino
IDE employs the program avrdude to convert the executable code into a text file in
hexadecimal encoding that is loaded into the Arduino board by a loader program in the
board's firmware.

8.10 Arduino Programming


Once Arduino IDE is installed on the computer, connect the board with
computer using USB cable. Now open the Arduino IDE and choose the correct board
by selecting Tools>Boards>Arduino/Genuino Uno, and choose the correct Port by
selecting Tools>Port. Arduino Uno is programmed using Arduino programming
language based on Wiring.

To get it started with Arduino Uno board and blink the built-in LED, load the
example code by selecting Files>Examples>Basics>Blink. Once the example code
(also shown below) is loaded into your IDE, click on the ‘upload’ button given on the
top bar. Once the upload is finished, you should see the Arduino’s built-in LED
blinking.

DEPARTMENT OF ECE Page No 55


ARDUINO

Example code for blinking:


// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

8.11 LCD Interfacing with Arduino

Fig 8.3 - Interfacing LCD with Arduino UNO


Program:
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
void setup() {
lcd.begin(16, 2);
lcd.clear();

DEPARTMENT OF ECE Page No 56


ARDUINO

lcd.setCursor(0, 0);
lcd.print("Who is Goodboy?");
delay(500);
lcd.setCursor(0, 1);
lcd.print("The GopalKrishna!");
}
void loop() {
}

8.12 Matrix Keypad Interfacing with Arduino

Fig 8.4 - Matrix Keypad Interfacing with Arduino UNO


Program:
#include <Keypad.h>
#include <LiquidCrystal.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'7','8','9','/'},
{'4','5','6','X'},
{'1','2','3','-'},

DEPARTMENT OF ECE Page No 57


ARDUINO

{'.','0','=','+'}
};
byte rowPins[ROWS] = {7,6,5,4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3,2,1,0}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins,
ROWS, COLS);
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
void setup()
{
lcd.begin(16, 2);
lcd.print("TheGopalKrishna!");
lcd.setCursor(0, 1);
}
void loop()
{
char customKey = customKeypad.getKey();
if (customKey)
{
lcd.print(customKey);
}
if (customKey=='.')
{
lcd.clear();
lcd.begin(16, 2);
lcd.print("TheGopalKrishna");
lcd.setCursor(0, 1);
}
}

DEPARTMENT OF ECE Page No 58

You might also like