Embedded HandbookApps
All sections › VIII. Electronics around the microcontroller
STM32F103, STM32G431 · level intermediate · 14 min read
Open in the interactive handbook

49е. Sensor physics: Hall effect, strain and piezo effect, thermo-EMF, photoeffect, capacitive and inductive sensing

The last section of the series "Physics for the developer". Sections 49а–49д covered field, induction, lines, noise and heat. Here: how a physical quantity turns into an electrical signal — field into Hall voltage, strain into a change of resistance, force into charge, a temperature difference into microvolts, light into current, a finger and a liquid level into picofarads, a piece of metal into a frequency shift. For each effect: where it comes from, what order of signal it gives and what follows for the circuit and the ADC.

Specific sensors have their own sections; their circuits and code are not repeated here: ACS712 — 101.4, load cell and HX711 — 102.1, ADS1220 — 15г, instrumentation amplifier — 176, thermocouple and MAX31855 — 104.1 and 104.6, RTD — 176б, photoresistor and BH1750 — 103, TSC touch sensing — 45.2, AS5600 magnetic encoder — 57и, magnetometer — 99г.

Sources: constants (k, q, h, c, μ0, ε0, Avogadro number) — CODATA 2022 from scipy.constants (scipy 1.18.1, numpy 2.3.3, image stm-ml:1); type K thermo-EMF — the ITS-90 (NIST) polynomials, the same as in the check of section 104. The bridge with the instrumentation amplifier and the photodiode transimpedance amplifier are repeated in ngspice 39 (image stm-lab:1, files bridge49f.cir and tia49f.cir). Material properties — copper density, gauge factor of constantan, piezo coefficients of quartz and ceramic, permittivity of water and oil, resistivity of aluminium — are handbook values with no document on disk; where a value is assumed, it says so. All numbers come from calc49f.py. There are no hardware measurements.

What it is called in the documentation

Original Meaning
Hall effect, Hall voltage Hall effect, Hall voltage
sensitivity, mV/mT; quiescent output sensitivity; output at zero field
strain gauge, gauge factor (GF) strain gauge, ratio of ΔR/R to strain
Wheatstone bridge, quarter / half / full bridge bridge with one, two or four active arms
microstrain (µε) µm/m of strain
piezoelectric charge coefficient (d33), pC/N charge per newton
charge amplifier op-amp with a capacitor in feedback
Seebeck effect, cold junction compensation thermo-EMF; measuring the reference junction
responsivity, A/W photocurrent per watt of light
photovoltaic / photoconductive mode no bias / reverse bias
dark current current without light
transimpedance amplifier (TIA) current-to-voltage converter
eddy current proximity sensor, LVDT proximity by induced currents; differential transformer

49е.1 From quantity to signal

Every sensor has the same chain: the quantity acts on a material, the material changes an electrical property, and the circuit turns that change into a voltage for the ADC. The weak link is almost always the signal size. The 12-bit STM32 ADC with a 3.3 V reference resolves 0.806 mV. Anything smaller does not exist for it without an amplifier.

Seven sensor principles: magnetic field via the Hall effect, strain via a strain gauge, force via the piezo effect, temperature via thermo-EMF, light via the photoeffect, level and finger via capacitance, metal via eddy currents — with the signal order and what the chain needs

The signals in the figure differ by four orders of magnitude: from tens of microvolts for a thermocouple and a Hall element to hundreds of millivolts after the photodiode transimpedance amplifier. Hence the different chains: amplifier, 24-bit ADC, charge amplifier, timer instead of ADC.


49е.2 Hall effect: the field deflects the carriers

Current in a plate is a flow of charge carriers with drift velocity v. In a field B each feels the Lorentz force q·v·B across the current. Carriers pile up at one edge until their field balances the force. A Hall voltage appears across the plate:

U = I · B / (n · q · d)

n is the carrier concentration, d the plate thickness along the field. The fewer the carriers, the faster they move at the same current and the more they are deflected.

Why a semiconductor. In copper n = 8.49·10²⁸ m⁻³ (from density, molar mass and one free electron per atom). A 35 µm trace carrying 1 A in a 10 mT field gives 21.0 nV — nothing. In a semiconductor the concentration can be made small; assume 10²² m⁻³ — 8.5 million times less than in copper. A 10 µm plate at 1 mA gives 62.4 mV/T, that is 62.4 µV per 1 mT and 0.624 mV in a 10 mT field.

n_sc, d_sc, I_sc = 1e22, 10e-6, 1e-3                     # полупроводник: условно 10²² м⁻³, 10 мкм, 1 мА
k_sc = I_sc / (n_sc * QE * d_sc)                         # В/Тл

Field scale: the Earth gives about 50 µT, which is 3.12 µV on such an element; that is why a magnetometer (99г) is a chip with an amplifier and ADC inside, not a bare sensor. A wire with 5 A at 1 mm distance creates μ0·I/(2π·r) = 1.000 mT — 62.4 µV. To get 185 mV/A like the ACS712 (101.4) needs a gain of about 14.8 thousand. That is what Hall current sensors do: element, amplifier and processing in one package (how the ACS712 is built inside is not covered here — the geometry is assumed).

Zero offset. The sensing contacts are never exactly opposite each other, and the plate is not uniform. So at zero field there is a voltage drop from the current itself between them, comparable to the useful signal and dependent on temperature. Integrated sensors suppress it by switching the direction of the current and the contacts (current spinning). A residual remains: the ACS712 zero must be measured without current at every start (101.4). The carrier concentration in a semiconductor changes with temperature — so does the sensitivity.


49е.3 Strain gauge and bridge: fractions of a percent in microvolts

A stretched conductor gets longer and thinner, resistance rises. The ratio of ΔR/R to strain ε is the gauge factor GF; for constantan foil it is about 2.0. A strain of 1000 µm/m (the order of full load of a metal sensor) changes resistance by 0.200 %: for a 350 Ω gauge, by 0.700 Ω.

Such a difference is measured with a Wheatstone bridge: two dividers from one supply, the output is the difference of their midpoints. Without strain the bridge is balanced, the output is zero, and only the change is measured. With a 3.3 V supply and one active gauge (quarter bridge) the output is 1.648 mV, or 0.4995 mV/V; the quarter-bridge nonlinearity at this strain is 0.0999 %. Two active arms (half bridge) — 3.30 mV, four (full bridge, as in the load cell of 102.1) — 6.60 mV, 2 mV/V.

Why the built-in ADC is not enough: a full bridge at full load is 8.19 ADC steps, a quarter bridge 2.05 steps. For 3000 scale divisions the signal step is 2.20 µV. You need either an instrumentation amplifier (176) with a gain of about 100, or a 24-bit ADC: HX711 (102.1) or ADS1220 (15г). The floor is set by thermal noise (49г.2): the output of a 350 Ω bridge has 2.41 nV/√Hz, in a 10 Hz band 7.62 nV.

ngspice (bridge49f.cir): a 350 Ω bridge from 3.3 V and a three-op-amp instrumentation amplifier with gain 100. A strain of 1000 µm/m gives 164.8 mV at the output — the same 1.648 mV times 100.

Temperature. The gauge resistance changes both from heating and from the foil and the part expanding differently. Assume 20·10⁻⁶ per kelvin: heating by 10 K gives 0.0200 % — as much as a strain of 100 µm/m. In a quarter bridge that is 165 µV, 10.0 % of full scale. The cure is a second identical gauge on the same part in the adjacent arm (in a half bridge it may also be active, in compression). Both heat equally and their changes subtract: in the ngspice model the output under heating is 0 V, and strain plus heating gives 164.8 mV, as without heating.


49е.4 Piezo effect: charge per force, but only while it changes

In a crystal without a centre of symmetry (quartz, PZT ceramic) compression shifts positive and negative ions relative to each other, and a charge Q = d·F appears on the faces. Quartz has 2.3 pC/N, ceramic about 400 pC/N (for a particular element — from its datasheet). A force of 10 N: quartz 23 pC, ceramic 4.0 nC.

The element is a capacitor. On its own 1 nF the quartz charge gives 23 mV and the ceramic 4.0 V: a piezo buzzer (13б) hit by a shock outputs volts and can damage an input without a clamp. A 2 m cable at 100 pF/m adds 200 pF in parallel — 19.2 mV, the signal dropped by 16.7 % and depends on the cable.

Why it does not measure static force. The charge leaks through whatever is connected: a 10 MΩ input with 1.2 nF — time constant 12.0 ms, lower band edge 13.3 Hz. After a constant force is applied, 5.0 % of the signal is left after 3τ. A piezo sensor measures impact, vibration, sound, but not weight.

Charge amplifier. An op-amp with a 100 pF capacitor in feedback holds the input at zero potential, and all the charge goes into this capacitor: U = Q / Cf = 230 mV for 23 pC, and the cable capacitance no longer matters. A 1 GΩ resistor across Cf keeps the output from drifting with input current; it sets τ = 0.10 s and a lower edge of 1.59 Hz.


49е.5 Thermo-EMF: the voltage is born along the wire

If the ends of a conductor are at different temperatures, electrons diffuse from the hot end to the cold one more than back — an EMF appears along the wire (Seebeck effect). In one wire it cannot be measured: the wire to the voltmeter is also unevenly heated. One measures the difference of two different metals — a thermocouple. The voltage is E(hot) − E(cold) from the standard table of the type (104.1).

Type K slope from the ITS-90 polynomials:

Temperature Seebeck coefficient
0 °C 39.5 µV/°C
25 °C 40.5 µV/°C
100 °C 41.4 µV/°C
500 °C 42.6 µV/°C
1000 °C 39.0 µV/°C

The 12-bit ADC step is 19.5 °C, using the average slope up to 1000 °C. An amplifier or a dedicated converter (104) is needed.

Cold junction. A thermocouple at 300 °C gives 12.209 mV relative to 0 °C, but the cold end on the board at 25 °C subtracts 1.000 mV. Forget it, and the reading is 275.8 °C. Each degree at the cold junction is 40.5 µV, so its temperature is measured by a separate sensor next to the point where the thermocouple wire turns into copper.

A connector is a thermocouple too. Where the thermocouple wire meets the copper of a connector or trace, that is the cold junction. If the cold-junction sensor sits at the chip at 25 °C while the copper connector is heated to 35 °C, the same 300 °C hot junction reads 290.2 °C. So thermocouple wire of the same type is run to the converter itself, and the connector contacts are kept at one temperature (extension circuits — 104.1).


49е.6 Photoeffect, capacitance and induction

Photodiode. A photon with energy above the band gap creates an electron–hole pair in the p-n junction, the junction field separates them — a current flows, proportional to the number of photons. At quantum efficiency 1 the responsivity is R = q·λ / (h·c): 0.448 A/W at 555 nm, 0.686 A/W at 850 nm, 0.758 A/W at 940 nm. A real diode gives less. Silicon stops seeing light longer than 1107 nm — the photon energy is not enough (band gap 1.12 eV).

A lux is watts weighted by the eye: 683 lm/W at 555 nm by the definition of the candela. A 7 mm² diode at 1000 lx of green light receives 10.2 µW and gives at most 4.59 µA; at 1 lx, 4.59 nA.

Modes. Without bias (photovoltaic mode) there is no dark current driven by voltage, but the junction capacitance is larger — assume 50 pF. With reverse bias (photoconductive mode) the depletion layer is wider, capacitance smaller — assume 15 pF — the diode is faster, but dark current always flows.

Transimpedance amplifier. The op-amp holds both diode terminals at the same voltage, all current goes through the feedback resistor: U = I·Rf. Rf 100 kΩ at 1000 lx gives 0.459 V (−0.459 V in ngspice: the circuit inverts), the 3.3 V scale ends at 7193 lx. A dark current of 10 nA (assumed) shifts by 1.00 mV, and it grows with temperature.

ngspice (tia49f.cir, op-amp with 10 MHz bandwidth): without a feedback capacitor the response at 50 pF peaks 17.6 times — diode capacitance and Rf make the amplifier almost unstable (163). Cf 2.8 pF from √(Cd / (2π·Rf·GBW)) brings the peak down to 1.14 with a bandwidth of 692 kHz (estimate √(GBW / (2π·Rf·Cd)) — 564 kHz). At 15 pF without Cf the peak is 9.68, with Cf 1.00 at a bandwidth of 728 kHz.

Photodiode noise (49г.3). Shot noise of a 4.59 µA photocurrent is 1212 fA/√Hz, the thermal current of Rf 100 kΩ 407 fA/√Hz: in bright light the light itself sets the limit. At 1 lx shot noise is 38.3 fA/√Hz, and the resistor is noisier; they become equal at Rf 11.3 MΩ. In general shot noise exceeds the Rf noise when the photocurrent is above 2kT/(q·Rf) = 517 nA.

Capacitance. A finger through a 1 mm panel adds 0.443 pF per unit of panel εr (49а.6) to a background of about 20 pF (45.2). A liquid level uses the same formula C = ε0·εr·S/d: plates 20 × 100 mm with a 2 mm gap give 8.85 pF in air, 19.5 pF in oil (εr 2.2), 708 pF in water (εr 80). Oil adds 0.106 pF, water 6.99 pF per millimetre of level. Water conducts, so the electrodes are insulated, and then the insulation capacitance is in series — compute from its thickness.

Picofarads can be measured two ways. RC time: charge the capacitance from a pin through 1 MΩ to the input threshold 0.7·VDD and time it with a timer: t = R·C·ln(1/(1 − 0.7)) = 24.08 µs for 20 pF, a finger adds 0.533 µs — 91 timer ticks at 170 MHz. Charge transfer (TSC, 45.2): the number of transfers into 47 nF drops by 61 with a finger.

Induction. A coil with alternating current near metal induces eddy currents in it (49б.6). Their field opposes the coil field, inductance falls and losses rise. A 10 µH coil with 1 nF is a 1.592 MHz tank; if a target lowers L by 5 % (assumed), the frequency rises by 2.6 %, by 41.3 kHz. A timer counting periods in a 1 ms window gets 1591 counts without the target and 41 more with it. The skin depth at this frequency is 52.4 µm in copper and 64.9 µm in aluminium: a target thinner than that works worse; steel behaves differently because of its magnetic properties. Differential transformer (LVDT): a primary winding and two opposing secondaries, a moving core redistributes the coupling between them (mutual induction — 49б.5). The output is an AC voltage whose amplitude is proportional to displacement and whose phase gives the direction; it is rectified synchronously with the excitation.

Summary.

Principle Typical signal What the chain needs
Hall effect 62.4 µV per 1 mT for a bare element ready sensor with amplifier; measure zero
strain bridge 0.4995 mV/V (quarter), 2 mV/V (full) ×100 amplifier or 24-bit ADC, 50 Hz filter
piezo element 23 pC per 10 N (quartz) charge amplifier, only changing force
type K thermocouple 40.5 µV/°C cold junction, amplifier, filter
photodiode 4.59 µA at 1000 lx transimpedance amplifier, Cf
capacitance 0.443 pF on a 20 pF background TSC or RC time with a timer
eddy currents 2.6 % of tank frequency frequency count with a timer

49е.7 Pitfalls

The Hall sensor shows current that is not there. Zero offset and its drift with supply and temperature. Measure zero without current at start, stabilise the sensor supply (101.4).

The scale drifts with nobody on it. Bridge heating: 10 K at an assumed 20·10⁻⁶ per kelvin in a quarter bridge is 10.0 % of full scale. A compensating gauge in the adjacent arm or a full bridge is needed.

The piezo sensor "loses" the weight. Not a fault: the charge leaks with a time constant of 12.0 ms at a 10 MΩ input. A piezo element does not measure static force.

The thermocouple is 10 degrees off. The cold junction is not where its temperature sensor is: a copper connector 10 °C warmer than the board — 290.2 °C instead of 300.

The photodiode amplifier rings. No feedback capacitor: at 50 pF the response peaks 17.6 times. Cf of about 2.8 pF at Rf 100 kΩ (163).

A capacitive level gauge in water always shows "full". Water conducts and shorts bare electrodes; through insulation it is the insulation capacitance that is measured.


49е.8 Summary

Next: section 49ж "Electrostatics and ESD" — where kilovolts come from, the HBM and CDM models and how a microcontroller input is protected: diodes, TVS, resistor and layout.

Open in the interactive handbook