A refresher course in sensor design using microcontrollers: Part 2 - Embedded.com

A refresher course in sensor design using microcontrollers: Part 2


In Part 1, we covered the basics ofsensors and the characteristics youmust keep in mind when using them in designs. However, there  isan enormous range of specialist sensors developed for specificapplications in the engineering field.

Some of the more commonly used sensors are outline here and fall intoseveral categories: position and distance sensors, speed sensors,temperature sensors, strain sensors, humidity sensors and lightsensors.

Position  and distance sensors
Apotentiometer can be used as a simple position sensor. The voltageoutput represents the angular setting of the shaft. It has limitedrange (about 300°) and is subject to noise and unreliability due towear between the wiper contact and the track. There are therefore arange of more reliable position transducers, which tend to be moreexpensive.


LVDT. Alinear variable differential transformer (LVDT) uses electromagneticcoils to detect the position of a mild steel rod which forms a mobilecore. The input coils are driven by an AC signal, and the rod positioncontrols the amount of flux linked to the output coil, giving avariable peak”to-peak output. It needs a high-frequency AC-supply, andis relatively complex to construct, but reliable and accurate.


Capacitor. The capacitor principle provides opportunities to measure distanceand level. If considered as a pair of flat plates, separated by an airgap, a small change in the gap will give a large change in thecapacitance, since they are inversely proportional; if the gap isdoubled, the capacitance is halved. If an insulator is partiallyinserted, the capacitance also changes.

Capacitorplate separation

This can make a simple but effective level sensor for insulatingmaterials such as oil, powder and granules. A pair of vertical platesis all that is required. However, actually measuring resulting smallchanges in capacitance is not so straightforward. A high-frequencysensing signal may need to be converted into clean direct voltage forinput to a digital controller.


Ultrasonic. Ultrasonic ranging is another technique for distance measurement.The speed of sound travelling over a few metres and reflecting from asolid object gives the kind of delay, in milliseconds, which issuitable for measurement by a hardware timer in a microcontroller. Ashort burst of high-frequency sound (e.g. 40 kHz) is transmitted, andshould be finished by the time the reflection returns, avoiding thesignals being confused by the receiver.

Speed sensors
Digital. The speed or position ofa DC motor cannot be controlled accurately without feedback. Digitalfeedback from the incremental encoder described above is the mostcommon method in processor systems, since the output from theopto-detector is easily converted into a TTL signal. The positionrelative to a known start position is calculated by counting theencoder pulses, and the speed can then readily be determined from thepulse frequency. This can be used to control the dynamic behaviour ofthe motor, by accelerating and decelerating to provide optimum speed,accuracy and output power.


Analogue. Foranalogue feedback of speed, a tachogenerator can be used; this isessentially a permanent magnet DC motor run as a generator. An outputvoltage is generated which is proportional to the speed of rotation.The voltage induced in the armature is proportional to the velocity atwhich the windings cut across the field.

If the tachometer is attached to the output shaft ofa motor controlled using PWM, the tachometer voltage can be convertedby the MCU and used to modify the PWM output to the motor, givingclosed loop speed control. Alternatively, an incremental encoder can beused, and the motor output controlled such that a set input frequencyis obtained from the encoder.

Temperature sensors
Temperature is another commonly required measurement, and there isvariety of temperature sensors available for different applications andtemperature ranges. If measurement or control is needed in the range ofaround room temperature, an integrated sensor and amplifier such as theLM35 is a versatile device which is easy to interface.

Metalresistance temperature sensor

It produces a calibrated output of 10 mV/°C,starting at 0°C with an output of 0 mV, that is, no offset. Thiscan be fed directly into the PIC analogue input if the full range of-50°C to +150°C is used.

This will give a sensor output rangeof 2.00 V, or 0.00 V ” 1.00 V over the range 0″100°C. For smallerranges, an amplifier might be advisable, to make full use of theresolution of the ADC input. For example, to measure 0″50°C:

Temp range = 50° C
Input range used =
0-2.56 V (8-bit conversion, VREF = 2.56 V)
Let maximum =
2.56X 20 = 51.2° C
Then conversion factor =
2.56/5.12 = 50 mV/°C
Output of sensor =
10 mV/°C
Gain of amplifier required =
50 mV/ 10 mV = 5.0

A non-inverting amplifier with a gain of 5 will beincluded in the circuit. Note that if a single supply amplifier isused, the sensor will only go down to about +2°C.

Diode. Theforward volt drop of a silicon diode junction is usually estimated as0.6 V. However, this depends on the junction temperature; the voltagefalls by 2 mV/°C as the temperature rises, as the charge carriersgain thermal energy, and need less electrical energy to cross thejunction.

Silicondiode sensor

The temperature sensitivity is quite consistent, sothe simple signal diode can be used as a cheap and cheerful alternativeto the specialist sensors, especially if a simple high/low operationonly is needed. A constant current source is advisable, since theforward volt drop also depends on the current.

Metals. Metalshave a reasonably linear temperature coefficient of resistance overlimited ranges. Metal film resistors are produced which operate up toabout 150°C, with platinum sensors working up to 600°C. Thetemperature coefficient is typically around 3″4000 ppm (parts permillion), which is equivalent to 0.3%/°C. If the resistance at thereference temperature is, say, 1 kohm, the resistance change over100°C would be 300″400 ohms.

A constant current is needed to convert theresistance change into a linear voltage change. If a 1 kohmtemperature-sensing resistor is supplied with a constant 1 mA, thevoltage at the reference temperature, 25°C, would be 1.00 V, andthe change at 125°C would be 370 mV, taking it to 1.37 V. Anaccuracy of around 3% may be expected.

Integratedtemperature sensor

Thermocouple. Higher temperatures may be measured using a thermocouple. This issimply a junction of two dissimilar metals, which produces a batteryeffect, producing a small EMF. The voltage is proportional totemperature, but has a large offset, since it depends on absolutetemperature. This is compensated for by a cold junction, connected inseries, with the opposite polarity, and maintained at a known lowertemperature (say 0°C). The difference of voltage is then due to thetemperature difference between the cold and hot junctions.


Thermistor. Thermistorsare made from a single piece of semiconductor material, where thecharge carrier mobility, therefore the resistance, depends ontemperature. The response is exponential, giving a relatively largechange for a small change in temperature, and a particularly highsensitivity. Unfortunately, it is non-linear, so is difficult toconvert for precise measurement purposes.


The thermistor therefore tends to be used as a safetysensor, to detect if a component such as a motor or transformer isoverheating. The bead type could be used with a comparator to providewarning of overheating in a microcontroller output load.

Strain sensors.
The strain gauge is simple in principle. A temperature-stable alloyconductor is folded onto a flexible substrate which lengthens when thegauge is stretched (strained). The resistance increases as theconductor becomes longer and thinner.

This can be used to measure small changes in theshape of mechanical components, and hence the forces exerted upon them.They are used to measure the behaviour of, for example, bridges andcranes, under load, often for safety purposes. The strain gauge canmeasure displacement by the same means.


The change in the resistance is rather small, maybeless than 1%. This sits on top of an unstrained resistance of typically120 ohms. To detect the change, while eliminating the fixed resistance,four gauges are connected in a bridge arrangement and a differentialvoltage is measured.

The gauges are fixed to opposite sides of themechanical component, such that opposing pairs are in compression andtension. This provides maximum differential voltage for a given strain.All the gauges are subject to the same temperature, eliminating thisincidental effect on the metal conductors. A constant voltage issupplied through the bridge, and the difference voltage fed to a highgain, high input impedance amplifier.


Care must be taken in arranging the inputconnections, as the gauges will be highly susceptible to interference.The amplifier should be placed as near as possible to the gauges, andconnected with screened leads, and plenty of signal decoupling. Theoutput must then be scaled to suit the MCU ADC input.

Pressure can be measured using an array of straingauges attached to a diaphragm, which is subjected to the differentialpressure, and the displacement measured. Measurement with respect toatmosphere is more straightforward, with absolute pressure requiring acontrolled reference. Laser-trimmed piezoresistive gauge elements areused in low-cost miniature pressure sensors.

Humidity sensors
There are various methods of measuring humidity, which is theproportion of water vapour in air, quoted as a percentage. Theelectrical properties of an absorbent material change with humidity,and the variation in conductivity or capacitance, can be measured.


Low-cost sensors tend to give a small variation incapacitance, measured in a few picofarads, so a high-frequencyactivation signal and sensitive amplifier are needed.

Light sensors
There are numerous sensors for measuring light intensity:phototransistor, photodiode, light-dependent resistor (LDR, or cadmiumdisulphide cell), photovoltaic cell and so on. The phototransistor iscommonly used in digital applications, in opto-isolators, proximitydetectors, wireless data links and slotted wheel detectors. It hasbuilt-in gain, so is more sensitive than the photodiode.

Lightdependent resistor


Infra-red (IR) light tends to be used to minimiseinterference from visible light sources, such as fluorescent lights,which nevertheless, can still be a problem.

The LDR is more likely tobe used for visible light, as its response is linear (when plotted logR vs. log L) over a wide range, and it has a high sensitivity in thevisible frequencies.

The CdS cell is widely used in photographic lightmeasurement, for these reasons. Conversion into a linear scale isdifficult, because of the wide range of light intensity levels betweendark and sunlight.

Next, in Part 3: Implementinga sensor/MCU interface .
To read Part 1, go to Anintroduction to sensors and theircharacteristics

Usedwith the permission of the publisher, Newnes/Elsevier, this series ofthree articles is based on copyrighted material from “ InterfacingPIC Microcontrollers: Embedded Design by Interactive Simulation,” by Martin Bates. The book can bepurchased on line.

Martin Bates is a lecturer intechnology at the Hastings College of Arts and Technology, UnitedKingdom

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.