Sensors and Microcontroller PDF
Sensors and Microcontroller PDF
All system has an input device, control unit and output device as
shown in figure 1. Once the system is set, it controls the input data and
observes the resulting effects on the output that relate to the input.
Figgure 8: The
T two types
t volltage diviider circu
uits
If Rbottom >>
> Rtop, then
t .
If Rbottom = Rtop theen .
If Rbottom <<
< Rtop, then 0. Moost of th he input voltagee
will be across
a Rtop.
Thhe choice is deteermined d by wheen we wantw largge value for thee
output Voltage
V Vout:
1- If we want
w a larrge Vout when thhe sensorr has a ssmall ressistance,,
we put the
t sensoor at thee top (Rtoop).
2- If we want
w largge Vout when
w the sensorr has a llarge ressistance,,
we put the
t sensoor at thee bottom m (Rbottom
m).
Thhe abovee points play im mportantt role while
w maaking daark/lightt
sensor.
1. Variable resistoors sensoors:
Foorce-senssitive resistors, and thermistorss are vaariable resistors,,
also ph hotocell is a vaariable resistor,
r which producces a reesistancee
proporttional too the am mount off light iti sensess. The vvariable resistorr
(Light-DDependeent Resisstor LDR R) which has a high rresistancce when n
dark an nd a low resistan nce when n brightlly lit willl enable us to ad
djust thee
output voltage
v Vout for a given resistance of thee sensor to set th he exactt
brightnness levell in dark and liight senssor circu uits. If oone of th
he fixed
d
resistorrs in figure (8) circuit is repla aced with h a varriable reesistancee
(Light-DDependeent Resistor LDR R), the ouutput vooltage is proporttional too
the chaange in resistan nce of the
t variiable resistor. A As the level off
illuminaation on LDR increases, its resistance falls.
W
With Rtop variablee and Rbottom fix xed, we note that the equation
e n
given foor outpu ut voltagge Vout iss not a linear
l fu
unction. For verry smalll
changess in resiistance, this
t equuation appproaches linearr, and fo or largee
changess in resisstance haas more curvatu ure.
Figure 9: Automatic dark and light sensor
1- If the LDR is at the top (near +VS), Vout will be low in the dark
and high in bright light. As the light level increases and LDR meets the
lowest threshold resistance the output voltage is large when the
resistance of LDR is low. This voltage would enough for a transistor to
turn on a LED. Hence, this circuit automatically turns on the LED D1
and works as Automatic Light sensor.
2- If the LDR is at the bottom (near 0V), Vout will be high in the
dark and low in bright light. As the light level decreases and LDR
meets the maximum threshold resistance the output voltage is large
when the resistance of LDR is high. This voltage would enough for a
transistor to turn on a LED. Hence, this circuit automatically switches
on the LED D1 and works as Automatic Dark sensor.
It is most linear at the point where Rtop = Rbottom. If we know
Rbottom, Vin and Vout, we can derive Rtop using the following formula:
2. Temperature sensors:
A sensor used in a fire alarm wants a circuit which will deliver a
high voltage when hot conditions are detected. We need a voltage
divider with the Negative temperature coefficient NTC resistor in the
Rtop position. Thermistor (Temperature - Sensitive Resistor) has a
(NTC), decreases as the temperature rises. The output voltage depends
upon the temperature and the resistance of a thermistor is given by
1/T = A + B x lnRtop + C x ln3top (2)
he constaants, A, B and C can be determiined from experrimentall
Th
measurements of resisttance, or they canc be calculate
c ed from tabularr
data. They
T aree called the Steiinhart–H
Hart parrameterrs, and must
m bee
specified for eaach devicce. T is the
t tempperaturee in Kelvvin and R is thee
resistan
nce in oh
hms.
Magnetic flux
b- Analogue: For analogue feedback of speed, a tacho-generator
can be used; this is essentially a permanent magnet dc motor run as a
generator. An output voltage is generated which is proportional to the
speed of rotation. The voltage induced in the armature is proportional
to the velocity at which the windings cut across the field.
If the tachometer is attached to the output shaft of a motor
controlled using PWM, the tachometer voltage can be converted by
the MCU and used to modify the PWM output to the motor, giving
closed loop speed control. Alternatively, an incremental encoder can
be used, and the motor output controlled such that a set input
frequency is obtained from the encoder.
3) Temperature sensors
a- Diode: The forward voltage drop of a silicon diode junction is
usually estimated as 0.6 V.
Vd=Vh-Vc
Thermocouple
The temperature range of a thermocouple depends on the type
of metals that make up the thermocouple. There are some industry
standard types as shown in the table:
Type Range (Celsius) Range (Fahrenheit) Features
E 95-900°C 200-1650°F Highest Output
J 95-760°C 200-1400°F
K 95-1260°C 200-2300°F
T 0-350°C 32-660°F
Thermocouples give out voltages in the range of micro volts so
the output of a thermocouple must be amplified before it can be
converted into a digital value.
Thermistor
d- Thermistor: Temperature dependant semiconductor resistors
(Thermistors) are thermally sensitive resistors and have, according
to type, a negative (NTC), or positive (PTC) resistance / temperature
coefficient. They are made from a single piece of semiconductor
material, where the charge carrier mobility, therefore the resistance,
depends on temperature. The response is exponential, giving a
relatively large change for a small change in temperature, and a
particularly high sensitivity. Unfortunately, it is non-linear, so is
difficult to convert for precise measurement purposes.
The thermistor therefore tends to be used as a safety sensor, to
detect if a component such as a motor or transformer is overheating.
e- RTD’s: Also called Platinum RTD, because it is typically made
of platinum. A change in temperature causes a change in resistance of
platinum. Within a limited range, the resistance of metals increases in
proportion to the temperature as defined by the formula:
Rt = Ro[1+α(t-to)]
where:
Rt = resistance at temperature t
Ro = resistance at a standard temperature to
α = temperature coefficient of resistance (Cº-1)
Typical readings for platinum are 100 Ω at 0 Celsius and 139 Ω
at 100.
Strain Guage
The change in the resistance is rather small, maybe less than 1%.
This sits on top of an unstrained resistance of typically 120 Ω. To
detect the change, while eliminating the fixed resistance, four gauges
are connected in a bridge arrangement and a differential voltage is
measured.
The gauges are fixed to opposite sides of the mechanical
component, such that opposing pairs are in compression and tension.
This provides maximum differential voltage for a given strain. All the
gauges are subject to the same temperature, eliminating this
incidental effect on the metal conductors. A constant voltage is
supplied through the bridge, and the difference voltage fed to a high
gain, high input impedance amplifier.
Pressure sensor
Care must be taken in arranging the input connections, as the
gauges will be highly susceptible ( )ﺣﺴﺎسto interference. The amplifier
should be placed as near as possible to the gauges, and connected with
screened leads, and plenty of signal decoupling. The output must then
be scaled to suit the MCU ADC input.
A pressure sensor is generally a variable resistor that changes
resistance based on how hard it is pressed. They are also known as
Force Sensing Resistors or FSRs. often we use an FSR as the variable
resistor in a voltage divider circuit. By using one FSR and one fixed
resistor and hooking Vout to an A/D converter we can give the
microcontroller some idea of how much pressure is being put on the
FSR. If we don't have an A/D converter handy, there's a simple RC
time circuit that you can use to do more-or-less the same thing.
5) Humidity sensors
There are various methods of measuring humidity, which is the
proportion of water vapour in air, quoted as a percentage. The
electrical properties of an absorbent material change with humidity,
and the variation in conductivity or capacitance, can be measured.
Humidity sensor
6) Light sensors
There are numerous sensors for measuring light intensity:
phototransistor, photodiode, light-dependent resistor (LDR, or
cadmium disulphide cell), photovoltaic cell and so on. The
phototransistor is commonly used in digital applications, in opto-
isolators, proximity detectors, wireless data links and slotted wheel
detectors. It has built-in gain, so is more sensitive than the photodiode.
The most common light sensor is the photo sensor. It works like
a variable resistor with a value that changes based on how much light
it receives.
Figu
ure 16: Touch
T Sw
witch Cirrcuit
n the inteerface beetween a sensor and thee µC, wee
In order too design
need too specifyy the performaance of a linearr ampliifier which willl
translate the output of the sensor into a suitable input for the µC,
which is in the right range for the amplifier to handle and allows a
convenient conversion factor to be used in the ADC.
1- Inputs/Outputs Interfacing
Note that the L293D will become warm with continuous use. A
heat sink bonded onto the top of the chip will help keep it cool.
One way to prevent electrical noise affecting the microcontroller
is to use separate power supplies for the ‘control’ electronics and the
motor. For example, a PP3 battery may be chosen to power the
microcontroller and 4xAA cells to power the motors. Naturally it will
be necessary to ‘link’ the two circuits so that the motor can be
controlled. A relay is an ideal component to do this.
The above circuit will only switch the motor on and off. If the
motor is required to run in both directions (forwards and reverse),
two relays can be used as shown.
6. Output Device 6 - Unipolar stepper motor
Stepper motors are very accurate motors that are commonly
used in computer disk drives, printers and clocks. Unlike dc motors,
which spin round freely when power is applied, stepper motors
require that their power supply be continuously pulsed in specific
patterns. For each pulse, the stepper motor moves around one ‘step’,
often 7.5 degrees (giving 48 steps in a full revolution).
Notice that as the coils create a back EMF when switched off 8
suppression diodes (4 on each coil) are also required.
The table below show the four different steps required to make
the motor turn.
Step Q 1 Q 2 Q 3 Q 4
1 1 0 1 0
2 1 0 0 1
3 0 1 0 1
4 0 1 1 0
1 1 0 1 0
Fortunately the motor driver L293D has been specifically
designed to provide this transistor switching circuit. The L293D
contains all 8 transistors and diodes within one 16 pin package.
With this circuit the input pin is low when the switch is open and
high when the switch is closed.
This system requires just three wires between the computer and
the microcontroller. Strictly speaking RS232 serial voltages should be
at ±15V, but the standard 5V from the on-board 5V regulator will be
used here. This is not the industry standard, but works perfectly OK
with the majority of computers. This is the circuit that will be used use
for serial communication.
To provide true RS232 voltages another integrated circuit is
required. The most common IC used is the MAX232, which has on-
board voltage boosters to create the required voltage swing. If this
setting is used it is necessary to change the N2400 (negative) in all the
serial software commands to T2400 (true positive). ONLY USE ONE
OF THESE TWO CIRCUIT OPTIONS!
VI) Practical application
1) Interfacing of temperature Sensor LM 35:
The LM35 series sensors are precision integrated-circuit
temperature sensors, whose output voltage is linearly proportional to
the Centigrade temperature. It gives 10mV of output voltage for every
1 Cº. The LM35 does not require any external calibration or trimming
to provide typical accuracies of ±¼ Cº at room temperature and ±¾ Cº
over a full -55 to +150 Cº temperature range. The LM35's low output
impedance, linear output, and precise inherent calibration make
interfacing to readout or control circuitry especially easy. It can be
used with single power supplies, or with dual supplies. As it draws
only 60 µA from its supply, it has very low self-heating, less than 0.1
Cº in still air. The LM35 is rated to operate over a -55° to + 150 Cº
temperature ranges. LM35 is a three terminal IC with Vcc, Ground
and Vout.
The LM 35 IC gives a 10 mV analog output voltage for every
degree Celsius change in temperature. The Output of the temperature
sensor is analog in nature. So, with proper circuitry an ADC chip is
used as shown below.
As shown in the circuit ADC 0809 (8-input channel system) is
used to convert the analog voltage into its equivalent digital voltage.
For this necessary signal conditioning circuit is developed using an
operational amplifier. A clock signal of 100 KHz is applied. The
voltage drop across the LM Zener is buffered by an op-amp LM 741
to produce a Vcc and Vref of around 5V to 12V for the A/D converter.
With this reference voltage the A/D converter will have 256 steps of 20
mV each. Since the temperature sensor signal is amplified by 2, each
degree Celsius of temperature change will produce an output change
of 20 mV, or one step on the A/D converter. This gives us a resolution
of 1 Cº, which is about the typical accuracy of the sensor. The
advantage of using Vref as Vcc for the device is that this voltage will not
have the switching noise that the digital Vcc lines have. The control
inputs and data outputs of the ADC are connected to the Ports of the
Microcontroller as shown in the circuit.
A relay is used to control the temperature. When the
temperature of the bath is reached a set temperature, the
microcontroller sends a High bit to the relay so that the Relay will
switch off the power supply to the heater and automatically the
temperature starts decreasing. The vice-versa takes place when the
temperature falls below the set value.
A 2x16 LCD module is interfaced to the Microcontroller to
display the temperature. Suitable program is developed to control and
measure the temperature. The temperature at which the water bath is
to be maintained is set as (TS). The measured temperature is
compared with this TS and if measured temperature is higher than the
set temperature, a signal is sent to the relay to switch-off the power.
Otherwise the power is switched on. This temperature is displayed on
the LCD module.
2) Interfacing of Humidity Sensor:
A humidity sensor measures the relative humidity and expressed
as a percent (RH %). It is the ratio of actual moisture in the air to the
highest amount of moisture in air can hold at that temperature.
Humidity sensors are of three types, Resistive, Capacitive, and
Thermal Conductivity sensing. The most common type of humidity
sensor used is the “capacitive sensor.” The sensor is composed of two
metal plates with a non-conductive polymer film between them. The
film collects moisture from the air, and the moisture causes minute
changes in the voltage between the two plates. The changes in voltage
are used to know the amount of moisture in the air.
The SY-HS-220 series Humidity sensor is based on capacitive
technology. This module converts relative humidity to output voltage.
Its operating voltage is 5V dc.
The circuit details of the humidity sensor are given in Fig. below.
This is a three pin IC sensor. Among the three pins one is (B)
connected to ground, (R) is to +5 V and (W) gives the analog output
voltage based on the humidity levels.
The interfacing of Humidity sensor with 8051 microcontroller
using ADC0809 is shown below.
•
type, pressure sensors can be divided into five categories.
Absolute pressure sensor
This sensor measures the pressure relative to perfect vacuum
pressure (0 PSI or no pressure). Atmospheric pressure is 101.325 kPa
•
(14.7 PSI) at sea level with reference to vacuum.
Gauge pressure sensor
It can be calibrated to measure the pressure relative to a given
atmospheric pressure at a given location. A tire pressure gauge is an
example of gauge pressure indication. When the tire pressure gauge
•
reads 0 PSI, there is really 14.7 PSI (atmospheric pressure) in the tire.
Vacuum pressure sensor
This sensor is used to measure pressure less than the
atmospheric pressure at a given location. This has the potential to
cause some confusion as industry may refer to a vacuum sensor as one
which is referenced to either atmospheric pressure (i.e. measure
•
Negative gauge pressure) or relative to absolute vacuum.
Differential pressure sensor
This sensor measures the difference between two or more
pressures introduced as inputs to the sensing unit, for example,
measuring the pressure drop across an oil filter. Differential pressure
•
is also used to measure flow or level in pressurized vessels.
Sealed pressure sensor
This sensor is the same as the gauge pressure sensor except that
it is previously calibrated by manufacturers to measure pressure
relative to sea level pressure.
The NPC-1220 is a solid state IC Pressure Sensor used to
measure pressure. It is intended for printed circuit board mounting
and available as an 8-pin DIP chip. The circuit connections of this
pressure sensor are given below.
To interface the pressure sensor with a microcontroller, a signal
conditioning circuit is necessary. The signal conditioning of the
pressure sensor consists of LM324 operational amplifiers, which are
high gain, internally frequency compensated amplifiers designed
specifically to operate from a single power supply over a wide voltage
range. The analog output voltage of the sensor is given to ADC. The
pressure sensor generates 0 to 50 mV of output voltage for a 0 to 15
psi pressure range.
Where
A1 = Area of pipe upstream from restriction
A2 = Flow area of pipe at restriction
p1 = pressure upstream from restriction
p2 = pressure at restriction
ρ = density of fluid
C = correction factor for energy losses
The differential pressure sensors
The SDPx108 series sensors are a high-performance sensors,
specially designed for air flow measurements. The SDPx108 sensor
provides an analog output signal with a range of 0 - 4 V. The simple
differential pressure sensor used to measure flow rate is shown below.
It is a 3-pin CMOS IC, whose output is at the pin 3. It has on
chip ADC and on chip DAC.
Interfacing Circuit: The output of the sensor is applied to the
ADC 0809 and this digital output is given to the ports of the
Microcontroller.
The analog output of the sensor is applied to channel 0 (IN0) of
the ADC and the output of the ADC is given to the Port 1 of the
microcontroller as shown in the diagram. A 2X16 LCD module is
interfaced to the microcontroller to display the flow rate.