Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 36 ยท Sensors and Actuators

Sensor Basics

Learn how sensors work and the terms that describe them: range, resolution, accuracy, precision, sensitivity, response time and drift, with simulations.

A sensor converts a physical quantity, such as temperature, light, pressure or acceleration, into an electrical signal a circuit can read. Every IoT system begins here: if the measurement is wrong, nothing downstream, no cloud and no clever algorithm, can fix it. Choosing and using a sensor well means understanding a few terms that appear on every datasheet.

This lesson explains how sensors produce signals, what the specifications mean, and why real readings are never perfectly clean. You will simulate noise, offset and drift to see their effect.

From physics to numbers

A sensor exploits a physical effect that changes an electrical property:

  • A thermistor changes resistance with temperature.
  • A photodiode creates current in proportion to light.
  • A strain gauge changes resistance when it bends.
  • A Hall-effect sensor produces a voltage in a magnetic field.
  • A piezo element produces charge when squeezed.

The circuit around the sensor turns that change into a voltage or a digital value, which the microcontroller then reads (analog-to-digital conversion is its own lesson). Finally, your code converts the raw number back into units such as degrees or lux, using a formula from the datasheet or from calibration.

Analog and digital sensors

Type Output Example Notes
Analog A voltage that varies continuously TMP36 temperature, LDR light sensor Needs an ADC; sensitive to wiring noise
Digital A number sent over a bus BME280, DHT22, MPU6050 Often I2C or SPI; the conversion happens inside the sensor
Binary On or off Reed switch, PIR motion Read with a plain GPIO pin

Digital sensors are usually easier because calibration and conversion are done inside the chip. You read a register over I2C or SPI and get a ready number.

Reading a datasheet: the key specifications

Range, resolution, accuracy

Range Smallest to largest value measurable
Resolution Smallest change it can show
Accuracy How close to the true value
Precision How close repeated readings are

Accuracy and precision are different things.

1 / 2

Range is the span the sensor can measure; outside it the output saturates or the part is damaged. Resolution is the smallest step you can see (0.01 C versus 1 C). Accuracy is how far the reading is from the truth, often written as +/-0.5 C. Precision (repeatability) is how tightly repeated readings of the same quantity cluster. A sensor can be precise but inaccurate: it always reads 2 degrees too high.

Python Accuracy versus precision: bias and noise

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Averaging many readings reduces random noise (spread) but cannot remove a bias. Bias is fixed by calibration.

Sensitivity and sensor transfer functions

Most sensors are approximately linear: output = sensitivity * input + offset. For the common TMP36 analog sensor, the output is 10 mV per degree Celsius with 500 mV at 0 C, so temperature = (millivolts - 500) / 10. If the datasheet says 750 mV, the temperature is 25 C.

Some sensors are strongly non-linear. A thermistor follows an exponential-style curve and needs the Steinhart-Hart or beta equation. Others, such as an LDR, vary over orders of magnitude, so you often work in a logarithmic scale.

Python Linear transfer function and clipping at the range limits

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Noise, offset and drift

Real signals are messy:

  • Noise: random jitter from electronics, wiring and the environment. It averages out.
  • Offset (bias): a constant error, such as always +0.8 C. Fixed with calibration.
  • Gain error: the slope is slightly wrong, so error grows with the reading.
  • Drift: the offset slowly changes over weeks or months, from aging or temperature.
  • Hysteresis: the reading depends on whether the value is going up or down.
  • Self-heating: current through the sensor warms it. Read infrequently to avoid it.
Python Noise, offset and drift together

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Even after averaging away the noise, the error grows with drift. Long-lived installations plan for periodic recalibration or choose sensors with good long-term stability specifications.

Placement and environment

A perfect sensor in the wrong place gives wrong answers. A temperature sensor next to a voltage regulator measures the regulator. A humidity sensor in a sealed box measures the box. Keep sensors away from heat sources, shield them from direct sun, allow airflow and protect electronics from water while letting the sensing element reach the air. Also consider the sensor's warm-up time and response time: a sensor with a 30-second time constant cannot capture one-second changes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A sensor always reads 2 degrees too high but repeated readings agree closely. It is:

    Tight clustering means precise; the constant 2 degree error means it is not accurate.
  2. 2. Which error does averaging many readings NOT remove?

    Averaging reduces random error. A constant offset is the same in every reading, so it survives averaging.
  3. 3. A TMP36 outputs 10 mV per degree C with 500 mV at 0 C. What temperature is 750 mV?

    (750 - 500) / 10 = 25 C.
  4. 4. What is drift?

    Drift is gradual change due to aging, temperature or environment, and can be corrected by recalibration.

Summary

  • Sensors turn physical quantities into electrical signals using materials whose properties change.
  • Key specs: range, resolution, accuracy, precision, sensitivity, response time, drift.
  • Noise averages out; bias and drift do not, so calibrate and recalibrate.
  • Placement, warm-up and self-heating can matter as much as the part you choose.

Next: Common Sensor Types