Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
256 views

2 - Sensors, Microcontrollers, and Their Interfacing

This chapter discusses sensors, microcontrollers, and interfacing between them. It introduces common sensors like gas, temperature, motion, and infrared sensors. The chapter explains how to select sensors based on factors like cost, accuracy, signal conditioning capabilities. It provides examples of interfacing gas, temperature, motion, and other sensors to microcontrollers. It also gives an overview of microcontrollers including the 8051 architecture and its features like registers, timers, and interrupts.

Uploaded by

YASH PRAJAPATI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
256 views

2 - Sensors, Microcontrollers, and Their Interfacing

This chapter discusses sensors, microcontrollers, and interfacing between them. It introduces common sensors like gas, temperature, motion, and infrared sensors. The chapter explains how to select sensors based on factors like cost, accuracy, signal conditioning capabilities. It provides examples of interfacing gas, temperature, motion, and other sensors to microcontrollers. It also gives an overview of microcontrollers including the 8051 architecture and its features like registers, timers, and interrupts.

Uploaded by

YASH PRAJAPATI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

CHAPTER 2

Sensors, Microcontrollers,
and Their Interfacing

HEMIL PATEL
1
CKPCET, SURAT
Outline
Sensor interfacing
Types of sensors
Controlling sensors
Microcontrollers
ARM

HEMIL PATEL
2
CKPCET, SURAT
Introduction to Sensors Interfacing
• There are numerous sensors available in the market and it is essential to know about these sensors to build a
complete/comprehensive IoT system.

• A sensor is a device that detects and responds to some type of input from the physical environment, The 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.

•The concept of interfacing sensors is giving input from sensors to microcontroller or input systems in a way which
they can understand and act accordingly.

HEMIL PATEL
CKPCET, SURAT 3
Types of sensors
• Gas Sensor (MQ2/MQ05)
• Temperature Sensor / Pressure / Humidity
• Motion Detection Sensor /PIR
• IR Sensor
• Chemical Sensor

HEMIL PATEL
4
CKPCET, SURAT
Selection of sensors
• Selection of sensors is difficult yet crucial and attention should be paid at this stage.
• Following are points one should consider before selecting any sensor:
1. Cost.
2. Precision and accuracy.
3. Understanding the environment.
4. Signal conditioning (removal of noise and other factors should be feasible).
5. ADC / DAC support availability.
6. Size of sensor

HEMIL PATEL
5
CKPCET, SURAT
Gas sensor – MQ-02/05
• In many places we find smoke sensors on the ceilings, which are designed to
detect smoke.
• This sensor is capable of detecting H2, LPG, CH4, Alcohol and smoke.
• Due to its high sensitivity and fast response time, measurements can be taken
as quick as desired.
• When any flammable gas flows through this sensor the coil inside this sensor
burns and so, the resistance of the coil decreases. Hence, the output voltage
starts increasing, which can be detected using a micro controller.
• MQ-05 is not sensitive to smoke. Hence, MQ-02 is preferred for smoke
detection applications, MQ-02 is not very good for detecting the low level LPG
presence.

HEMIL PATEL
6
CKPCET, SURAT
Contd.,
• The greater the gas concentration, the greater the output voltage.
• The lower the gas concentration, the lower the output voltage.
• The MQ-2 also has a potentiometer which helps to adjust the sensitivity to smoke.
• With POT, One can change how sensitive it is to smoke. This is called calibration.

HEMIL PATEL
CKPCET, SURAT 7
Connection Diagram

HEMIL PATEL
8
CKPCET, SURAT
MQ-05
• Most suitable for H2, LPG, Alcohol detection.
• Used in Home / Industry.
• Highly sensitive and can be tuned further as well. (With POT).
• Analog Sensor – So A0 of the MCU to be used. (Support for Digital Output is available in
few latest versions)
• The output voltage from the Gas sensor increases when the concentration of gas
increases.
• Suitable for LPG detection.

HEMIL PATEL 9
CKPCET, SURAT
Connection Diagram

HEMIL PATEL
10
CKPCET, SURAT
PIR SENSOR
• PIR motion sensor is SUITABLE TO DETECT THE HUMAN PRESENCE (MOTION
DETECTION).
• PIR is Passive Infrared Sensor.
• The PIR motion sensor measures infrared light from objects in its field of view.
• It can detect motion based on changes in infrared light in the environment.
• Normally used in human detection applications

HEMIL PATEL
11
CKPCET, SURAT
How PIR sensor works? (Passive Infrared Sensor)

Pyroelectric sensor generates energy when exposed to heat!

HEMIL PATEL
12
CKPCET, SURAT
Contd.,
• When a living organism (Say Human or a Horse) comes closer to the sensor (i.e. well within the
coverage), will emit heat as IR Radiation (This is natural).
• The white cover (shield) is named Fresnel Lens. Its work is to focus the IR signals on to the sensor.
(Which is the core component)

Fresnel Lens

HEMIL PATEL
13
CKPCET, SURAT
Connection Diagram

HEMIL PATEL
14
CKPCET, SURAT
Interfacing the Heartbeat Sensor
• Heartbeat Sensor is an electronic device that is used to measure the heart
rate i.e. speed of the heartbeat.

• Many application that use this sensor such as wearable applications that
monitor a person’s heartbeat accurately.

• A heartbeat sensor, which is usually very small.

• For interfacing we can use NodeMCU or Arduino version based on the


availability and feasibility.

HEMIL PATEL
15
CKPCET, SURAT
Interfacing Diagram

HEMIL PATEL
16
CKPCET, SURAT
Interfacing the Ultrasonic Sound Sensor
• Ultrasonic sound Sensor are generally used to measure the
distance of an object.
• This sensors emanate ultrasonic sound which travels and hits the
surrounding object.
• The received ultrasonic pulse is captured by the sensor, By
performing some math on the obtained value, we can get the
distance of the object from the sensor.
• This sensor can only measure the distance from the object and
cannot determine what type of object it is.

HEMIL PATEL
17
CKPCET, SURAT
Interfacing Diagram

HEMIL PATEL
18
CKPCET, SURAT
How Temperature Sensor Works? – DS18B20

HEMIL PATEL
19
CKPCET, SURAT
DHT 11 (Temperature and humidity)
• Working voltage 3.3 V-5 V
• Humidity measurement range 20 percent -95 percent,
humidity measurement error +-5 percent
• Temperature measurement range 0 -50, measurement
error +-2 degrees
• Same code for analog read, same method!!
• You should read the datasheet to interpret the output.

HEMIL PATEL
20
CKPCET, SURAT
DHT 11 (Temperature and humidity)

HEMIL PATEL
21
CKPCET, SURAT
DHT 11 (Temperature and humidity)
• IR Sensor interfacing

• Any chemical sensor interfacing

• Interfacing the pH Sensor

• Interfacing the Colour Sensor

• Interfacing the GPS

• Interfacing

HEMIL PATEL
22
CKPCET, SURAT
Microcontrollers
• There are many versions of microcontrollers form various manufacturers.

• It all started with Intel 8085 and Expanded to Intel 8086, 8088, 80186,
80188, 80286, Intel Pentium, Intel Celeron, and many more.

• For microcontrollers, it started with simple 8051 and now there are many
including 80151, 80251, MCS96, LPC2148, PIC microcontrollers, and many
more.

HEMIL PATEL
23
CKPCET, SURAT
8051: An Architectural View
• The 8051 Microcontrollers has got everything inbuilt, and this is the feature
which differentiate 8051 from other microprocessor such as 8085.

HEMIL PATEL
24
CKPCET, SURAT
Features of 8051
The following are the features supported by 8051:

1. 8-bit microcontroller supporting 8-bit operations.

2. Many general-purpose and few special function registers.

a. Two major 8-bit registers for arithmetical and other operations, A and B. A is accumulator and is a
bit addressable register.

b. 21 special function registers (SFRs). They perform a lot of dedicated functions.

c. Few registers are bit addressable and few are not.

d. Control registers for timer, serial communication and interrupts will fall under SFR category.

HEMIL PATEL
25
CKPCET, SURAT
Cont..
3. Four register banks having 8 registers in each bank.
a. 4 * 8 = 32 registers can be used by the programmers (stack finds a slot there).

b. Stack pointer register: Points to the stack; it is an 8-bit register.

4. Data pointer which is called a 16-bit register, but is a combination of two 8-bit registers, DPH and
DPL.

5. 16-bit program counter; no address for the same is allotted. A program counter is a helper for the
controller. It holds the address of the next instruction to be executed.

6. Eight bit program status word (PSW). It is the flag register and it helps in selection of register banks
as well.

7. Internal ROM or EPROM. It normally comes out with 4k ROM.

HEMIL PATEL
26
CKPCET, SURAT
Cont..
8. Internal user accessible RAM area of 128 bytes.

9. 40 pins package. There are four ports (P0, P1, P2, and P3) which can be configured as input or
output ports.

10. Two 16 bit timer/counters: T0 and T1.

11. Full duplex serial data receiver/transmitter: SBUF.

12. Support for interrupt programming.

13. Oscillator and clock circuits.

14. Easier and simpler instruction set.

HEMIL PATEL
27
CKPCET, SURAT
8051: Family Details
• Microcontrollers that fall in the family of 8081. these are 8052 and 8031, of which 8052 is regarded
as a developed version of 8051.

• In 8031 is not good as there is no in-built ROM available.

Feature 8031 8051 8052


ROM (Program Memory – On Chip) 0K 4K 8K
RAM (bytes) 128 128 256
Timers 2 2 3
I/O pins 32 32 32
Serial port 1 1 1
Interrupt sources 8 6 8

HEMIL PATEL
28
CKPCET, SURAT
Cont..
2. Data memory is useful when the data has to be stored
temporarily, during context switching. 8051 is organized
neatly with 256 bytes of memory, which are split as follow

a. Frist 128 bytes: 00h to 1Fh register banks.

b. 20h to 2Fh bit addressable RAM.

c. 30 to 7Fh general purpose RAM (To store general purpose


data).

d. Last 128 bytes: 80h to FFh SFRs.

HEMIL PATEL
29
CKPCET, SURAT
Cont..

HEMIL PATEL
30
CKPCET, SURAT
Special Function Registers (SFRs)
• Special Function Registers (SFRs) is
the term used to denote the most
important set of registers used in
8051.

• There are 21 SFRs available in the


8051 microcontrollers.

HEMIL PATEL
31
CKPCET, SURAT
Cont..
1. Accumulator (ACC): The Accumulator or Register A is the most important and most used 8051
Microcontroller SFRs. The Register A is located at the address E0H in the SFR memory space. The
Accumulator is used to hold the data for almost all the ALU Operations. operations where the
Accumulator is used are:

◦ Arithmetic Operations like Addition, Subtraction, Multiplication etc.

◦ Logical Operations like AND, OR, NOT etc.

◦ Data Transfer Operations (between 8051 and External Memory)

2. B (Register B): The B Register is used along with the ACC in Multiplication and Division operations. These two
operations are performed on data that are stored only in Registers A and B. During Multiplication Operation,
one of the operand is stores in B Register and also the higher byte of the result.

HEMIL PATEL
32
CKPCET, SURAT
Cont..
3. Program Status Word (PSW): The PSW or Program Status Word Register is also called as Flag Register
and is one of the important SFRs. The PSW Register consists of Flag Bits, which help the programmer in
checking the condition of the result and also make decisions. Flags are 1-bit storage elements that store
and indicate the nature of the result that is generated by execution of certain instructions. The following
image shows the contents of the PSW Register.

HEMIL PATEL
33
CKPCET, SURAT
Cont..
4. TCON, TMOD, TL1, TL0, TH1, and TH0: These register are all related to timer/counter operations.

5. P0, P1, P2 and P3: These functions registers are meant for accessing the available ports of 8051 and are
useful in interfacing with the peripherals.

6. IP and IE: These two function registers play a vital role in interrupt programming.

7. PCON: is used for controlling power consumption.

8. SCON and SBUF: Help in serial communications.

9. Data Pointer Register(DPH and DPL): The Data Pointer is a 16-bit Register and is physically the
combination of DPL (Data Pointer Low) and DPH (Data Pointer High) SFRs. The Data Pointer can be
used as a single 16-bit register (as DPTR) or two 8-bit registers (as DPL and DPH).

HEMIL PATEL
34
CKPCET, SURAT
Cont..
10. Stack Pointer (SP): SP or Stack Pointer points out to the top of the Stack and it indicates the next data
to be accessed. Stack Pointer can be accesses using PUSH, POP, CALL and RET Instructions. The Stack
Pointer is an 8-bit register and upon reset, the Stack Pointer is initialized with 07H.

11. Program Counter (PC): Purpose of PC is to keep a paper mark, the address of the next instruction to be
executed will be kept in PC.

HEMIL PATEL
35
CKPCET, SURAT
Advanced RISC (Reduced Instruction Set Computer) Machine

• An Advanced RISC Machine (ARM) processor is a family of CPUs based on


the RISC architecture.

• The ARM processor is a 32-bit processor meant particularly for high-end


applications that involve more complex computations and calculations.

HEMIL PATEL
36
CKPCET, SURAT
ARM Features

1. ARM processor has a large uniform register file. It is basically a LOAD-STORE architecture, where data
processing operations are only between registers and do not involve any memory operations.

2. It is a 32-bit processor and also has variants of 16-bit and 8-bit architectures. So, there are 16-bit and 8-bit
variants embedded into a 32-bit processor. This offers flexibility for the users to choose based on the
requirement.

3. ARM has got a very good speed versus power consumption ratio and high code density as required by
embedded applications.

HEMIL PATEL
37
CKPCET, SURAT
Cont.

4. It has got barrel shifter in the data path which can maximize the hardware usage available on the chip.
It has also got auto-increment and auto-decrement addressing modes to optimize program loops; this
is not very common with RISC processor. Also ARM supports LOAD and STORE of multiple data
elements through a single instruction.

5. ARM has also got a feature named “conditional execution”, where an instruction gets executed only
when a condition is being met, which maximizes the execution throughput.

These enhanced features make the ARM more suitable for embedded applications and all these distinguish
the ARM from other typical RISC processors.

HEMIL PATEL
38
CKPCET, SURAT
ARM Organisation Core Data Flow Model

HEMIL PATEL
39
CKPCET, SURAT
ARM Register Organisation

• ARM processors provide general-purpose and special-purpose registers. Some additional registers are
available in privileged execution modes.

• In all ARM processors, the following registers are available and accessible in any processor mode:

• 13 general-purpose registers R0-R12.

• One Stack Pointer (SP).

• One Link Register (LR).

• One Program Counter (PC).

HEMIL PATEL
40
CKPCET, SURAT
Cont.

1. Stack Pointer (SP, r13): Every microcontroller or processor will have a stack area for temporary
storage purpose, you can access the stack through stack pointer. It will hold the address of the top of
stack.

2. Link pointer (LP, r14): When a subroutine is called, the return address will be stored in this register,
when the subroutine execution is over, this register will be used for fetching the address from where
the control of execution was initiated.

3. Program Counter (PC, r15): PC is a special register. It has no address. Purpose of PC is to keep a
paper mark, the address of the next instruction to be executed will be kept in PC.

HEMIL PATEL
41
CKPCET, SURAT
Current Program Status Register
• CPSR is one of the most important registers available with ARM architecture. Figure below illustrates how CPSR
looks like as well as its components.

• This is a status register or a flag register. It can be compared to PSW (program status word) of 8051. One major
difference is that CPSR is a 32-bit register whereas PSW is an 8-bit register.

• In Fig. below there are four flags: Negative flag, Zero flag, Carry flag and Overflow flag. Since there is a lot of room
for extension, few bits are reserved and kept for future usage or for the moment they can be referred to be as
unused.

• There are two fields which are meant for interrupt masking purpose, where with I, one can mask or unmask the
IRQ interrupts. Then comes the THUMB field which helps in enabling or disabling the THUMB mode. Mode
switching can be done only with CPSR.

HEMIL PATEL
42
CKPCET, SURAT
Cont..

HEMIL PATEL
43
CKPCET, SURAT
ARM Family: A Comparison
• There are many processor that have been released with ARM core such as ARM7, ARM9, ARM10 and
ARM11.As the number increases, the number of features also increase along with more special
attributes.

Feature ARM7 ARM9 ARM10 ARM11

Pipeline Three Stage Five Stage Six Stage Eight Stage


MHz 80 150 260 335
MIPS/MHZ 0.97 1.1 1.3 1.2
Architecture (Harvard / Von Neumann) V.N Harvard Harvard Harvard

Multiplier 8 * 32 8 * 32 16 * 32 16 * 32

HEMIL PATEL
44
CKPCET, SURAT
Assignment Questions

1. Mention the importance of sensors in IoT applications with appropriate examples.

2. Mention clearly the procedure to interface the heartbeat sensor with Arduino.

3. Draw the architecture of 8051, Write down all the features.

4. Explain the architectural details of ARM7.

5. Explain usage of CPRS.

HEMIL PATEL
45
CKPCET, SURAT

You might also like