3.2 Sensor Technology
3.2.1 Sensor Operating Principles and Classification
An autonomous delivery vehicle pulls out of a logistics warehouse, passes through the automatic gate, and merges onto the highway. On board are an ambient-temperature sensor, a barometer, an IMU (Inertial Measurement Unit), a lidar, and cameras — each device captures a fragment of the outside world's information through a different physical principle. Temperature relies on the thermoelectric effect, pressure on the piezoresistive effect, distance on time of flight. These fragments are integrated into judgments such as "the path is passable," "tire grip is normal," and "there is construction ahead" — and the reliability of the latter depends directly on the sensing accuracy of the former.
Sensors are the starting point of the sensing layer and the foundation of the entire IoT system's chain of trust. Once the underlying physical quantities are distorted or lost, no algorithm further up can recover them. To choose the right sensor and use it well, we must first be clear about how sensors perceive the world and how they are classified and evaluated.
Classification by measurand — the physical quantity being measured — is the most common scheme in engineering. Temperature, pressure, light, sound, magnetism, acceleration, gas concentration — behind each physical quantity stands a different transduction mechanism. The most common temperature sensors are thermocouples and thermistors: a thermocouple exploits the Seebeck effect at the junction of two dissimilar metals, generating an electromotive force from a temperature difference, while a thermistor relies on the drastic change of a semiconductor's resistivity with temperature. Pressure sensors make extensive use of the piezoresistive effect — a diaphragm formed by silicon micromachining deforms under pressure, and the resistance of the piezoresistors diffused on its surface changes accordingly. Among optical sensors, a photodiode converts incident photons into photocurrent, while CCD (Charge-Coupled Device) and CMOS (Complementary Metal-Oxide-Semiconductor) image sensors go further and turn the spatial distribution of light intensity into a pixel array. Accelerometers are based on capacitive sensing: micromachined movable electrodes and fixed electrodes form a differential capacitor, and inertial force changes the electrode spacing, thereby changing the capacitance.
Once a sensor type has been chosen, understanding its sensing principle thoroughly lets you anticipate its strengths and its pitfalls. A piezoelectric accelerometer outputs a voltage signal without external power, which suits it to high-frequency shock measurement, but its response attenuates severely in the very low frequency band. A thermocouple spans a temperature range from -200 °C to 2,000 °C, yet its output voltage is only at the microvolt level and must be paired with a high-precision amplifier. A capacitive humidity sensor offers extremely high sensitivity and extremely low power consumption, but it fails once its film is covered by oil.
Key performance metrics are the standard language that elevates a sensor from a mere component to a basis for engineering selection. They mainly include the following:
- Sensitivity: the ratio of the change in output to the change in input. For an accelerometer the unit is mV/g; for a temperature sensor, common units are mV/°C or Ω/°C. With the output range of the same chip fixed, the higher the sensitivity, the smaller the minimum physical change that can be resolved.
- Resolution: the smallest input change that can be detected. Limited by the noise floor, resolution cannot be infinitely high. It is directly tied to sensitivity — sensitivity amplifies the noise along with the signal — so engineering practice often needs to distinguish ideal resolution from effective resolution, the latter measured by the input quantity corresponding to the root-mean-square value of the noise.
- Linearity: the degree to which the actual output curve deviates from the ideal straight line over the full-scale range, usually expressed as a percentage of full scale (%FS, Percent of Full Scale) or as the maximum deviation. A sensor with poor linearity needs piecewise calibration, or lookup-table compensation in the data-processing stage. The fitted straight line a sensor vendor provides has different definitions — end-point method, best-straight-line method, and so on — so always confirm the baseline method when selecting.
- Response time: the time required from a sudden change in the measured quantity until the sensor output reaches a specified proportion of its steady-state value. A common expression is the time constant τ; for example, a temperature sensor's τ can range from a few seconds to several minutes. Response time must match the sampling rate — using a second-level sensor to monitor millisecond-level vibration will only miss every frame of the shock.
These four metrics are not isolated. Sensitivity set too high may saturate outright on strong signals, clipping the output; a response time that is too short amplifies the noise amplitude, and resolution drops instead. Selection calls for repeated trade-offs.
The table below aligns the most common sensor types by measurand, sensing principle, and typical application for quick reference. Performance metrics have already been described qualitatively in the text and are not repeated in the table — actual selection should follow the datasheet of the specific model.
Table 3-1 Common Sensor Types, Principles, and Typical Pitfalls
| Measurand | Sensing principle | Typical applications | Common selection pitfalls |
|---|---|---|---|
| Temperature | Thermoelectric effect, temperature coefficient of resistance | Cold-chain monitoring, industrial process control, HVAC | Thermocouples output microvolt-level signals; over long lead lengths, common-mode interference can swamp the signal |
| Pressure | Piezoresistive effect, capacitive effect | Hydraulic systems, barometric measurement, tire-pressure monitoring | Choosing the wrong reference among absolute, gauge, and differential pressure biases the measurement by a full atmosphere |
| Acceleration | Capacitive sensing, piezoelectric effect | Vibration monitoring, attitude sensing, structural health monitoring | Piezoelectric types do not respond to the DC component and cannot be used for tilt measurement |
| Humidity | Capacitive, resistive | Agricultural greenhouses, data centers, weather stations | The capacitive film is extremely sensitive to oil and condensation; humid, dusty environments require periodic cleaning |
| Light intensity | Photoelectric effect | Ambient-light adaptation, reflective detection on sorting lines, flame detection | A photodiode's wavelength response curve is narrow; selection must match the target light source's spectrum |
| Gas concentration | Electrochemical, catalytic combustion, infrared absorption | Toxic-gas alarms, VOC monitoring | Cross-sensitivity is severe — the same sensor responds to multiple gases |
One point easily overlooked in engineering selection: as noted in Section 3.1, datasheet figures should be taken with a discount — sensitivity, resolution, and linearity usually refer to data measured under "ideal reference conditions," and the interference stacked up in the field will pull the actually achievable accuracy down markedly; the experienced approach is to reserve a safety margin for the worst case.
Sensing principles differ wildly, but at the level of engineering decisions, what engineers actually wrestle with are those few basic questions: Is the accuracy sufficient? How often does it need calibration? Will it fail under temperature and power fluctuations? Can its power consumption carry it to the next maintenance cycle? A thorough grasp of principles and metrics makes for cleaner choices among the many sensor options. That choice finally lands in the thing model's point definitions — sensor readings are abstracted into uniformly named points, so upper-layer applications no longer care whether the underlying element is a thermocouple or a platinum resistance element; they care only about "the current temperature value" and its range and accuracy band. Section 3.7 continues with how the thing model accomplishes this abstraction.
3.2.2 Sensor Interfaces and Signal Conditioning
A sensor turns the physical quantity into an electrical signal, but that is often only the first step. A Type K thermocouple, under a tiny temperature difference, outputs a signal amplitude far below the full-scale range of a microcontroller's ADC (Analog-to-Digital Converter) — an input range of 0 to 3.3 V or 0 to 5 V is usually expected. The gap can reach more than three orders of magnitude. Without amplification and filtering, the digital values read back can hardly reflect the true physical quantity.
From an engineering perspective, sensor-to-microcontroller interfaces come in two paths: analog interfaces and digital interfaces. The dividing line between them is who performs signal conditioning — amplification, filtering, level matching — and how deeply the engineer has to get involved.
Analog Interfaces: Every Step of Signal Conditioning Is Yours to Control
An analog sensor outputs nothing but a continuously varying voltage or current, mapping the physical quantity onto an electrical signal. The MCU translates this analog voltage into a digital value through its ADC. This seemingly simple process breaks open into four problems: amplification, filtering, sampling, and interference rejection.
Amplification and level matching. The sensor's output amplitude can be several orders of magnitude smaller than the ADC's reference voltage. One rule of engineering experience: the maximum amplitude of the amplified signal should come close to, but not exceed, the ADC's reference voltage. Take a 12-bit ADC with a 3.3 V reference — the theoretical value of each LSB (Least Significant Bit) is (3.3V / 4096 \approx 0.8mV), and the actual value depends on the reference-voltage accuracy and the circuit noise. If a thermocouple output were connected directly, the temperature change per LSB could exceed tens of degrees Celsius — completely unusable. The solution is an instrumentation amplifier that brings the signal up close to the reference voltage. When selecting one, confirm that the gain-bandwidth product covers the signal's highest frequency — when the signal carries superimposed 50 Hz mains interference, choose the amplifier bandwidth with margin based on the signal's own highest frequency, and leave the mains interference to the downstream filtering stage to suppress.
Filtering. The most common interference on an industrial site is 50 Hz (the grid frequency in mainland China) or 60 Hz mains noise. For slow physical quantities like temperature, a first-order RC low-pass filter is enough to press the mains noise down. Engineering practice generally sets the cutoff frequency at several times the signal's highest frequency. For example, if room temperature changes at most 1 °C per second, take 1 Hz as the highest signal frequency and set the cutoff around 5 Hz. Cutoff frequency formula: ( f_c = 1/(2\pi RC) ). Design: choosing R = 33 kΩ and C = 1 μF gives a cutoff frequency of about 4.8 Hz. Actual values should be adjusted to the signal bandwidth and the noise environment.
Sampling rate and quantization bits. The ADC sampling rate should be far above the signal's highest frequency component, generally with several times the margin. To reconstruct a 50 Hz vibration waveform, the sampling rate needs at least several hundred S/s. The quantization bit count depends on the smallest detectable change required. Suppose the sensor sensitivity is 10 mV per unit of physical quantity: with a 3.3 V reference, a 12-bit ADC's LSB is about 0.8 mV, corresponding to 0.08 physical units per LSB, which satisfies most common scenarios. If the resolution falls short, switch to a 16-bit ADC (LSB about 0.05 mV) or add a second amplifier stage ahead of the ADC.
The engineering checks for analog signal conditioning come down to four decision points:
- Is the sensor output amplitude clearly below the ADC's full scale? — If yes, choose an instrumentation amplifier.
- Is there 50/60 Hz mains interference or high-frequency noise on site? — If yes, add a first-order RC low-pass filter, with the cutoff frequency set near the signal's highest frequency.
- Do multiple channels need synchronous acquisition? — If yes, use a multi-channel synchronous ADC or a dedicated sample-and-hold per channel; otherwise poll the channels one by one (mind the channel-switching settling time).
- Does the ADC sampling rate meet the signal-reconstruction requirement? Does the quantization LSB meet the sensitivity? — If not, adjust the ADC bit count, the gain configuration, or the sampling rate.
Each decision point must be judged against the sensor datasheet and the system requirements; there is no fixed formula to copy.
Digital Interfaces: The Sensor Vendor Has Packaged the Conditioning
Digital sensors integrate the complete signal-conditioning chain internally: amplifier, filter, temperature compensation, and linearization algorithms. Over an I²C (Inter-Integrated Circuit), SPI (Serial Peripheral Interface), or 1-Wire bus, they output values that are directly usable. Take a digital temperature-humidity sensor (the Si7021 or SHT21, for example): the MCU need not care about the internal ADC's bit count or the amplifier's gain — following the datasheet timing, it sends the slave address and the register number and reads back the temperature data.
A typical read sequence is as follows:
/* Arduino reads an I²C digital temperature sensor (illustrative code; rely on the actual datasheet for addresses and data) */
#include <Wire.h>
#define SENSOR_ADDR 0x40 // 7-bit I²C address (illustrative value; check the datasheet)
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
uint16_t rawTemp = 0;
float temperature = 0.0;
/* 1. Start communication and trigger the sensor's internal ADC conversion */
Wire.beginTransmission(SENSOR_ADDR);
Wire.write(0xE3); // command register that triggers a temperature measurement (illustrative)
Wire.endTransmission();
delay(20); // wait for the internal ADC to finish converting (see the datasheet)
/* 2. Read two bytes of raw data */
Wire.requestFrom(SENSOR_ADDR, 2);
if (Wire.available() >= 2) {
rawTemp = (Wire.read() << 8) | Wire.read();
/* 3. Convert to Celsius using the formula from the datasheet (illustrative) */
temperature = -46.85 + (175.72 * rawTemp / 65536.0);
}
Serial.print("Temperature: ");
Serial.println(temperature);
delay(1000);
}If the returned temperature is constantly 0 or out of range, check first: whether the I²C address is correct, whether the SCL/SDA pull-up resistors are installed (typically 4.7 kΩ), and whether the power supply is stable. A digital interface simplifies the hardware, but the debugging effort shifts to the correctness of the bus and the timing.
Engineering Trade-offs Between the Two Interfaces
| Consideration | Analog interface | Digital interface |
|---|---|---|
| Development cycle | Long — requires tuning amplification, filtering, and ADC sampling parameters | Short — reading parameters from the datasheet is enough |
| PCB area and parts | Large — each channel needs its own conditioning circuit | Small — the bus can be shared |
| Accuracy controllability | High — the designer can optimize the signal-to-noise ratio stage by stage | Low — determined by the sensor's internal integration |
| Scaling flexibility | Each channel independent; wiring grows complex as channels multiply | Limited by bus addresses and capacitance (the 7-bit address space contains 16 reserved addresses, with 112 commonly usable addresses, i.e. 0x08–0x77; theoretical maximum 127) |
| Total cost | Sensors are cheap, but conditioning-circuit parts and test costs are high | Sensors are expensive, but parts are few and production testing is quick |
Selection judgment: where sensors are few and signals change slowly, the digital interface's convenience wins. Where channels are many or signal bandwidth is high, the analog interface has the advantage in overall cost and signal fidelity.
The quality of signal conditioning directly determines how credible the sensor readings are. How a digital temperature sensor rated "±0.5 °C" in its datasheet behaves when placed next to a motor and a variable-frequency drive can only be verified through on-site testing. Understanding every link behind the analog interface is not a turn toward complexity — it is so that, when a digital interface cannot meet the accuracy or cost requirements, the engineer can confidently build the signal chain personally.
Practice boundary: Sensor interface selection is rarely completed independently in the laboratory. After being connected to a device management platform, analog sensors need additional configuration of range mapping and calibration coefficients, while digital sensors need their bus address and sampling interval configured. This part is covered in Chapter 5, "The Platform Layer and Data Processing."
3.2.3 Engineering Practice in Sensor Selection
Selection is not flipping through catalogs to pick the part with the highest figures. The "typical values" in a datasheet are mostly measured under laboratory conditions; the field environment — temperature fluctuation, supply noise, mechanical vibration, electromagnetic interference — presses the actual accuracy down. The engineer's task is not to add up optimal parameters but to make trade-offs under project constraints. Selection needs a repeatable screening method, not reliance on intuition or "whatever the last project used."
Core Dimensions of Selection
Accuracy and resolution are often conflated. Accuracy is the range of deviation between the sensor's output and the true value; resolution is the smallest change it can distinguish. A high-accuracy sensor does not necessarily have high resolution, and vice versa. In practice, first fix the error the application tolerates, then work backward to the sensor accuracy requirement, then check whether the ADC bit count is sufficient. Note — as noted in Section 3.1, datasheet figures should be taken with a discount: field-measured accuracy often falls below the datasheet rating, by as much as several times, so reserve margin for the real environment during selection.
Cost must be judged over the life cycle. An agricultural digital temperature-humidity sensor may cost a few dozen yuan, and an industrial temperature probe may be an order of magnitude more expensive — but the latter runs stably for years in harsh environments, while the former may drift out of spec within a few months. Selection must count in replacement cost, maintenance labor, and downtime losses. For large-scale deployments, maintenance cost often exceeds the sensor purchase cost itself.
Power consumption is strongly tied to the supply arrangement. Battery-powered devices must account for every microamp; industrial production lines have a stable 24 V supply and low sensitivity to power consumption. The power budget should be drawn up at the system level, counting in the MCU's wake-up current and the RF transmit pulse current. Watch the sleep current in particular — many sensors, when not working, consume far more than the "ideal sleep current," because the on-chip regulator and the pull-up resistors keep drawing power. In real projects, cases of missing the battery-life target because sleep current was overlooked are not rare.
Environmental adaptability comes down to the essentials: ingress-protection rating, operating temperature range, corrosion resistance, and vibration resistance. Datasheets often mark these in small print, yet they are precisely the number-one cause of field failures. High humidity, dust, pesticide vapors, oil contamination, electromagnetic interference — each one shortens the sensor's effective life. The endurance of temperature-humidity sensors in high-humidity environments needs particular attention — after a humidity-sensitive capacitor has spent a year in high humidity, its humidity readings may read clearly high.
The four dimensions constrain one another: high accuracy usually comes with high cost and higher power consumption; packages with stronger environmental adaptability are larger. There is no "all-purpose sensor" — only "a sensor matched to the scenario."
Example: Choosing a Temperature-Humidity Sensor for a Smart Greenhouse
The following is an entirely hypothetical scenario. All figures it lists — sensor model parameters, environmental conditions, battery-life estimates — are assumed values used only to illustrate the selection decision logic; they do not reflect any real product, real project, or measured data.
Scenario requirements: A medium-sized greenhouse (about 1,000 square meters, a hypothetical figure) needs temperature and humidity monitoring, with data reported every 5 minutes through a LoRa gateway. Power comes from two AA batteries, with a target battery life of at least one year. In summer the greenhouse interior can reach about 45 °C; in winter it can drop below 0 °C; relative humidity stays above 80% over the long term.
Step 1: Set the accuracy requirement. Crop-management experience indicates that temperature control must stay within ±1 °C and humidity within ±5% RH. At this accuracy level, common consumer-grade temperature-humidity sensors are sufficient.
Step 2: Draw the power budget. For intermittent reporting, the main energy consumption comes from the long-term sleep quiescent current of the MCU and the sensor. If the sleep current is at the microamp level, its accumulation over a full year will dominate. A real budget must estimate sleep current × seconds per year, report count × energy per wake-up, RF transmit peak current, and battery self-discharge. The specific figures must be set from the chosen chips' datasheets and measurements; what is given here is illustrative only.
Step 3: List the candidates. The candidate sensors cover mainstream interfaces and package forms; the models are as follows:
- Candidate 1: digital single-bus interface, temperature range -40~80 °C, humidity range 0~100% RH.
- Candidate 2: I2C interface, operating temperature -40~125 °C, with a configurable alarm pin.
- Candidate 3: I2C/SPI interface, operating temperature -40~85 °C, with an integrated barometric sensor.
Step 4: Screen and decide. All candidates' temperature ranges cover the greenhouse requirement. Candidate 1's single-bus protocol is strict about timing and is easily disturbed over long cable runs — greenhouse sensor wiring may exceed 5 meters, a high signal-integrity risk. Candidate 2's I2C interface can use shielded cable, and its programmable alarm pin can trigger an alarm independently while the MCU sleeps, reducing the number of MCU wake-ups. Candidate 3's extra barometric sensor benefits ventilation control, but draws slightly more power and adds system complexity. The final choice is Candidate 2: its interference immunity fits field wiring better, and the programmable alarm feature helps extend battery life.
Step 5: Calibrate and deploy. Perform single-point calibration before leaving the factory, recording the offset value for each sensor ID. During field deployment, hang a reference instrument (a higher-accuracy commercial temperature-humidity logger) at the greenhouse center, and use two-point calibration to correct offset and gain together — the offset corrects the systematic bias introduced by installation, and the gain corrects the sensor's own slope drift.
Error Sources and Calibration Methods
By nature, sensor errors divide into systematic error, random error, and gross error.
Systematic error is directional, repeatable deviation caused by manufacturing tolerances, aging drift, or improper installation. Single-point calibration can correct offset, while two-point calibration can estimate both offset and gain. No universal six-month calibration interval applies: regulations, sensor stability, environmental stress, historical drift, and the consequences of error must determine the interval together. Self-compensation also cannot replace traceable calibration.
Random error appears as scattered jitter in the measurement results, arising from thermal noise and electromagnetic interference. Taking a sliding average over multiple measurements suppresses it effectively. Where temperature changes slowly, the window can be widened appropriately; fast-changing signals need a smaller window to preserve detail.
Gross error is abnormal points that clearly deviate from normal values, possibly caused by transient hardware faults, interference spikes, or known environmental upsets (such as spraying starting). Use threshold judgment combined with two-dimensional voting across redundant sensors for gross-error rejection. For known interference sources (such as spraying), add "spray lockout" logic in the firmware and mark the humidity readings during that period as invalid data — more reliable than relying on threshold judgment alone.
Smart sensors have self-diagnosis and self-compensation capabilities: at the firmware level they perform temperature compensation and automatic calibration, and can even recognize sensor aging and raise an alarm proactively. For large-scale deployments, this self-diagnostic capability can markedly reduce the number of manual inspection rounds. But self-diagnosis covers only a limited set of failure modes: when a sensor is completely obscured or poisoned, misjudgment is still possible. Position self-diagnosis as an auxiliary measure; it cannot fully replace physical calibration.
Practice Checklist
- Before selection, fix the application's minimum tolerable accuracy threshold, work backward from that threshold to the sensor accuracy requirement, and reserve margin for environmental fluctuation.
- Build a requirements checklist: accuracy, power-source type, communication distance, ingress-protection rating, operating temperature range, cost of ownership.
- Physically test the candidate sensors, focusing on the "corner cases" the datasheet does not mark — high-temperature limits, high-humidity environments, and the impact of long-distance wiring on signal integrity.
- Before volume deployment, perform single-point or two-point calibration, record each sensor's calibration parameters, save them to the cloud, and associate them with the device ID.
- Establish a risk-driven calibration plan: record the reference standard, environmental conditions, pre- and post-calibration error, and uncertainty, then adjust the interval dynamically from historical drift.
- Add sensor health monitoring to the system, using the smart sensor's self-diagnostic features, or discovering early drift through trend analysis of historical data.
Further reading: Once selection is complete, the sensor's output signal must be interfaced with the MCU. The details of signal conditioning — amplification, filtering, ADC matching — directly determine whether the accuracy fixed at selection time can be honored; Section 3.2.2 covers them in detail. Management of calibration parameters is closely tied to this subsection's practice and connects with the data management and device configuration features of Chapter 5; readers are advised to revisit the full implementation of the calibration workflow after finishing Chapter 5.