teoria-sensores-transductores-ruido-filtrado

Sensors: The Art of Measuring the Real World

  • 5 min

A sensor is a device that responds to a physical quantity and converts it into a usable signal. It allows a circuit to measure light, temperature, pressure, position, and many other variables.

However, some believe a sensor is a “truth machine.” They think if the sensor says “25.0ºC,” it is exactly 25.0ºC. False. A sensor doesn’t give you absolute truth; it delivers an estimate contaminated by noise, delays, and physical errors.

Let’s see what really happens when we take an analog reading.

What is a Sensor?

Strictly speaking, what we use are transducers. A transducer is a device that converts one type of energy into another. In our case, it transforms a physical quantity (light, heat, pressure, sound) into an electrical quantity (voltage, resistance, capacitance).

  • Physical: A photon strikes a plate (light).
  • Chemical/Mechanical: That impact releases electrons (photoelectric effect).
  • Electrical: The material’s resistance drops.
  • Data: The microcontroller reads that resistance drop as a voltage.

Output Types: Analog or Digital

This is the first major division you encounter when choosing a component.

Sensors with analog output. These are the “purest.” The output is a continuously varying voltage (from 0V to 5V) proportional to what they measure.

  • Examples: LDR (Light), NTC (Temperature), Potentiometer (Position), LM35.
  • The problem: The microcontroller doesn’t understand continuous voltages. It needs an ADC (Analog-to-Digital Converter) to translate that voltage into a number (e.g., 0 to 1023).
  • Advantage: Infinite resolution (theoretically) and instantaneous response.

These are intelligent modules. Inside, they have the analog sensor, an amplifier, and their own small microchip that handles the ADC conversion.

  • Examples: DHT11, DS18B20, I2C/SPI Sensors.
  • How they work: You don’t read a voltage. You ask them via protocol: “What’s the temperature?” and they reply with ones and zeros: “00101101”.
  • Advantage: They are immune to noise in the cable (a 1 is a 1).
  • Disadvantage: They are slower (they need to process) and more expensive.

The Enemies of Measurement

This is where real-world projects often fail.

You will never have a clean signal. If you measure a 3V battery with an oscilloscope, you’ll see the line isn’t straight; it trembles. There is electrical “grass”. This noise comes from:

  • The switching power supply.
  • Nearby motors starting up.
  • Radio waves (EMI) that sneak into the cables as if they were antennas.

Effect: Your distance sensor reads: 10cm, 10cm, 150cm, 10cm. That “150” is a noise spike.

Physics is not instantaneous. If you take a temperature sensor out of the fridge (5ºC) and put it in boiling water (100ºC), it won’t read 100ºC instantly. Heat must travel through the plastic, thermal paste, metal, and into the chip. This is characterized by a time constant ().

  • If your control system reacts too quickly to a slow sensor, you will get oscillations.
  • Resolution: The smallest change you can detect. (E.g., My ruler measures millimeter by millimeter).
  • Sensitivity: How much the voltage changes per physical unit. (E.g., 10 millivolts per degree Celsius). If you use a low-sensitivity sensor with a poor ADC, the temperature will jump in steps: 20.0, 20.5, 21.0… (you can’t see 20.3).

They are not the same thing.

  • Accuracy: How close you are to the real value. (If it’s 20ºC, the sensor reads 20.1ºC).
  • Precision: How repeatable the value is. (If you measure 10 times, does it always give the same number or does it vary greatly?).

A sensor can be very precise but not very accurate (it always reads 22ºC when it’s 20ºC → it has an “Offset” or systematic error). This can be fixed by calibrating.

Signal Conditioning

Since the raw signal is poor, we must process it.

If you have a lot of electrical noise, place a capacitor (e.g., 100nF) between the signal and GND, as close to the sensor as possible. The capacitor “absorbs” fast voltage spikes (high-frequency noise) and lets the slow signal (temperature) pass through. It’s a physical low-pass filter.

Once you have the data in the code, never trust a single reading. We use mathematical techniques:

  1. Average: Take 10 measurements and average them. Eliminates random noise.
  2. Median: Sort the 10 measurements and take the middle one. Ideal for eliminating crazy peaks (outliers).
  3. Exponential Moving Average (EMA): Value = (New_Value * 0.1) + (Previous_Value * 0.9). It gives “weight” to past history to smooth the graph.

Linearity and Calibration

If only all sensors were linear (like a rule of three: double light = double voltage). Most are NOT.

  • An NTC thermistor has a complex logarithmic curve (Steinhart-Hart equation).
  • Many cheap sensors saturate at their extremes.

Calibration: Sometimes the sensor is poorly calibrated from the factory. For serious projects, you must compare your cheap sensor to a “Standard” (a professional thermometer) and adjust the formula in your code: