IoT Unit 2
IoT Unit 2
Sensors, Microcontrollers
and their
Interfacing
Overview of Microcontrollers
� Microcontroller is a digital device consisting of CPU, peripheral I/Os, memories,
interrupts, etc. in a single chip or IC.
� Microcontroller is a compact integrated circuit designed for a specific operation
in an embedded system.
� The examples of various microcontrollers are given as:
5 4 1
Sensors and Their Interfacing
Definition of Sensor
� Sensor is a device that detects or measures a physical property and records,
indicates, or otherwise responds to it.
� A sensor is a device that measures physical input from its environment and
converts it into data that can be interpreted by either a human or a machine.
� Normally, the sensors are input devices and there are two types of sensors.
� Analog Sensors
� Digital Sensors
List of Sensors
� The list of sensors which is to be covered in the chapter is as follows:
Latitude
Longitude
GPS device with antenna Returns latitude and longitude Tracked Location
for communication as output
GPS Sensor – Interfacing with Arduino
� The interfacing of GPS Sensor with
Arduino Uno is as shown in figure.
� Here, Vcc and Gnd pins of GPS Sensor
are connected to 5V and Gnd of
Arduino board.
� As the GPS communicates with
Arduino serially, we need to connect
Tx and Rx pin of GPS with serial pins
of Arduino.
� But, we want the data received from
the GPS sensor in serial monitor also
to read the current location.
� Therefore, we need to use any digital
pins of Arduino as serial transmit and
� Here, the Txpins
receive and Rxwhich
pins of GPS
is are connected
done by with pins 3 and 2 respectively.
software serial.
GPS Sensor – Output
Gyro Sensor
� The Gyro sensor is very useful in wearable devices.
� It is used to find the position or angle of rotation of
the body.
� It mainly senses
� Rotational motion
� Changes in orientation
� The Gyro sensor communicates with microcontroller
with I2C (Inter-Integrated Communication).
� I2C is the most sophisticated two-wire
communication protocol.
� It works with the device address and its respective
data frames.
� Normally, I2C is used when more numbers of
devices are connected.
Gyro Sensor (Cont.)
� The pin out of Gyro sensor MPU6050 are as
following.
� Vcc – connected to 5V
� GND – connected to ground
� SCL – Serial Clock Line
� SDA – Serial Data Line
� XDA – Auxiliary Serial Data
� XCL – Auxiliary Serial Clock
� AD0 – This pin can be used to vary the address
incase of multiple sensors used
� INT – Interrupt pin available for certain
application
MPU-6050 Gyro Sensor – working principle
� The MPU 6050 senses the gravitational force applied to it.
� Place the sensor in device whose inclination is to be measured.
� Obtain the values of x, y and z coordinates.
� Determine the elevation angle by performing mathematical caluculations
CPU
Bus
Oscillator I/O Ports Serial Port
Control
P P P P
0 1 2 3
Features of 8051 Microcontroller
1. 8- bit microcontroller.
2. Many general purpose and few special function registers (SFRs).
� Two major 8 bit registers. A and B. Both are used in arithmetic operations mainly.
� A is accumulator and it addressable.
� There are 21 SFRs among them few are bit addressable. SFRs perform various dedicated
operations.
� Also, some control registers for timer, counter and interrupt fall in category of SFRs.
3. Four register banks having 8 registers in each bank.
4. Data pointer register which is 16 bit made from combinations of two 8 bit
registers – DPH and DPL.
5. 16 bit Program Counter.
6. 8 bit Program Status Word(PSW) and used as Flag register.
7. Internal ROM and EPROM.
8. Internal user accessible RAM of 128 Bytes
Features of 8051 Microcontroller
9. There are four ports P0, P1, P2 and P3 that can be configured as input and
output.
10.Two 16 bit timer/counter – T0 and T1.
11.Full duplex serial communication and dedicated serial buffer register SBUF.
12.Supports interrupt programming.
13.Oscillator and Clock circuits are built in.
14.Easier and simpler instruction set.
Memory organization in 8051
� There are two categories of memory – program
memory and data memory.
FFh
1. Program memory
� In 8051, 4K bytes of program memory is available.
� It is normally referred as ROM and non volatile in nature. Special function registers
� It is used to store following:
(80 – FFh)
1. Boot up programs
2. Interrupt Service Routines (ISR)
3. Macro Functions
2. Data memory
� Data memory is used to store temporary data.
� 8051 has 256 byte data memory neatly organized for Internal RAM
various operations.
� The 256 byte data memory is divided into two parts (00 – 7Fh)
1. First 128 Bytes – Internal user accessible RAM
2. Last 128 Bytes – Special Function Registers (SFRs).
00h
R7 1Fh
.
Register Bank 3 .
. Data Memory Organization
R0 18h
► The first 32 Bytes 00h to 1Fh FFh
R7 17h are allocated for register
. banks.
Register Bank 2 . Special function registers
.
► There are four register banks –
R0 10h register bank 0,1,2 and 3. (80 – FFh)
R7 0Fh
► Each register bank has 8
. registers R0 to R7.
Register Bank 1 .
.
R0 08h
R7 07h Internal RAM
.
Register Bank 0 .
(00 – 7Fh)
. 1Fh
R0 00h 00h 00h
Bit b7 b6 b5 b4 b3 b2 b1 b0
Addresses
7F 78 2Fh
77 70 2Eh Data Memory Organization
6F 68 2Dh
67 60 2C h ► 20h to 2Fh are bit FFh
addressable RAM.
5F 58 2Bh
57 50 2Ah ► Each bit of each Special function registers
register can be set or
4F 48 29h
reset. (80 – FFh)
Bit 47 40 28h
Addressable 3F 38 27h ► The bits have also
different address.
37 30 26h
2F 28 25h
27 20 24h
2Fh Internal RAM
1F 18 23h
20h (00 – 7Fh)
17 10 22h
0F 08 21h
07 00 20h 00h
► The last 80 bytes of Internal RAM that is 30h to 7Fh are used as Data Memory Organization
General purpose RAM Area.
FFh
► Any general purpose data is stored in this area.
General Purpose
RAM Area 7Fh
80 Bytes
30h
Internal RAM
30h
(00 – 7Fh)
00h
Special Function Registers
� There are 21 SFRs in 8051microcontroller.
� They are important set of registers used for dedicated operations in 8051
microcontroller.
� Some of the SFRs are bit addressable while others are not.
� The following list explains the register and their function. The bracket is
representing its address in RAM.
1. Accumulator – A (E0h)
� It is 8 bit register used in each Arithmetic and Logical operation.
� It is bit addressable.
� All the results of arithmetic or logical operations are stored in Accumulator
� One operand in all operations such as addition, subtraction, division and multiplication will
be accumulator.
2. Register B (F0h)
� It is 8 bit register used in multiplication and division mainly.
� It is bit addressable.
Special Function Registers (Cont.)
3. PSW Register (D0h)
� PSW (Program Status Word) is consisting various flags of 8051.
� These flags indicate whether the microcontroller works as expected or something is going
wrong.
� The format of PSW register is as shown in figure.
� It is 8 bit register.
� Also PSW is bit addressable and its bits are represented by PSW.X, where X represents bit
number.
� Bit 0 is LSB
MSBand bit 7 is MSB. LSB
PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0
CY AC F0 RS1 RS0 OV - P
D7 D6 D5 D4 D3 D2 D1 D0
CY AC F0 RS1 RS0 OV - P
D7 D6 D5 D4 D3 D2 D1 D0
CY AC F0 RS1 RS0 OV - P
D7 D6 D5 D4 D3 D2 D1 D0
� CY – Carry (PSW.7)
▪ Carry flag is set to one when the arithmetic operation has carry generated from D7 bit. It is also used
in shift operations.
CY AC F0 RS1 RS0 OV - P
D7 D6 D5 D4 D3 D2 D1 D0
buses.
Control
� The important blocks Register file (r0 – r15)
can be explained as Rm Rn B
Result Rd
following. A
ACC
Instruction
� Instruction Decoder Barrel shifter MAC Decoder
� It decodes the N and
instruction before Control
execution. ALU
� There are three kinds
of instruction set
supported
1. ARM Instruction set Data Out Data In
2. Jazelle Instruction
set
ARM Core Data Flow Model
Address
� Rm, Rn and Rd
� ARM has two source Address Register
registers Rm and Rn
Incrementer
and one destination PC-r15
register Rd.
� A and B buses Register file (r0 – r15)
Control
31 30 29 28 27 8 7 6 5 4 0
N Z C V Unused I F T Mode
31 30 29 28 27 8 7 6 5 4 0
N Z C V Unused I F T Mode