Skip to content
Home » Embedded Systems » Sensors » Analog vs Digital Sensors in Embedded Systems

Analog vs Digital Sensors in Embedded Systems

Sensors for Embedded Systems
Part 1 of 18View Full Path →

KEY TAKEAWAYS

  • Analog sensors output continuous voltage/current; digital sensors output processed data via I2C, SPI, or custom protocols
  • Analog sensors need an ADC and are susceptible to noise over long wires; digital sensors have built-in processing and noise immunity
  • Choose analog for lowest cost and simplicity; choose digital for accuracy, noise resistance, and multi-sensor I2C/SPI buses
  • Modern embedded designs increasingly favor digital sensors due to I2C/SPI ubiquity and shrinking per-unit cost differences

Part of the Complete Guide to Sensors for Embedded Systems series.

One of the first decisions in any embedded sensor project is choosing between analog and digital sensors. The choice affects your circuit design, wiring complexity, MCU pin usage, software effort, and the accuracy of your measurements. This article compares them side by side with practical examples, code snippets, and real-world trade-offs to help you make the right choice.

How Analog Sensors Work

An analog sensor produces an output signal — voltage or current — that varies continuously with the measured quantity. The relationship between the physical measurement and the output voltage is determined by the sensor’s transfer function.

Example: LM35 Temperature Sensor

The LM35 outputs exactly 10mV per degree Celsius. At 25°C, it outputs 250mV. At 100°C, it outputs 1.0V. The output is a continuous analog voltage that the microcontroller cannot read directly — it must be converted to a digital number using an ADC (Analog-to-Digital Converter).

// Reading LM35 on Arduino (10-bit ADC, 5V reference)
int raw = analogRead(A0);                    // 0-1023
float voltage = raw * (5.0 / 1023.0);        // Convert to voltage
float temperature = voltage / 0.01;           // 10mV per degree
// Or simplified:
float temperature = raw * (500.0 / 1023.0);  // Direct to Celsius

With a 10-bit ADC and 5V reference, each ADC step represents 4.88mV. Since the LM35 outputs 10mV/°C, the resolution is about 0.5°C per step. If you need better resolution, you can either use a lower ADC reference voltage (1.1V internal reference gives 0.1°C resolution) or use a higher-resolution ADC.

Example: Voltage Divider with Thermistor

A thermistor changes resistance with temperature. Paired with a fixed resistor in a voltage divider, it produces a variable voltage. Unlike the LM35, the relationship is non-linear — you need the Steinhart-Hart equation or a lookup table to convert resistance to temperature.

// Thermistor reading with voltage divider
// 10k NTC thermistor + 10k fixed resistor
int raw = analogRead(A0);
float resistance = 10000.0 * raw / (1023 - raw);  // Calculate thermistor R

// Steinhart-Hart equation
float logR = log(resistance);
float temp = 1.0 / (0.001129148 + 0.000234125 * logR
             + 0.0000000876741 * logR * logR * logR);
temp -= 273.15;  // Kelvin to Celsius

Common analog sensors: LM35 (temperature), LDR (light intensity), potentiometer (position/angle), MQ-series (gas), force-sensitive resistors (pressure/weight), piezoelectric elements (vibration/knock), current shunt resistors.

How Digital Sensors Work

Digital sensors contain their own ADC, signal conditioning circuitry, and digital communication interface. They do the analog-to-digital conversion internally and transmit the result as digital data over a bus protocol — typically I2C, SPI, or a vendor-specific protocol.

Example: DHT22 (Custom Protocol)

The DHT22 humidity and temperature sensor uses a custom single-wire protocol. The MCU sends a start pulse (pulling the data line low for 1ms), then the sensor responds with 40 bits of data: 16 bits of humidity, 16 bits of temperature, and 8 bits of checksum. No ADC configuration, no voltage reference — just parse the bits.

// DHT22 gives temperature in tenths of a degree
// Raw 16-bit value: 0x0191 = 401 = 40.1% humidity
// Raw 16-bit value: 0x0106 = 262 = 26.2 degrees C

// Using a typical DHT library:
float humidity = dht_read_humidity();      // Returns 40.1
float temperature = dht_read_temperature(); // Returns 26.2

Example: BME280 (I2C/SPI)

The BME280 measures temperature, pressure, and humidity in a single 2.5mm x 2.5mm chip. It communicates via I2C or SPI. You write to a control register to start a measurement, then read back calibrated data from result registers. The sensor handles all signal conditioning, compensation, and linearization internally.

// BME280 over I2C (pseudo-code)
i2c_write(BME280_ADDR, CTRL_MEAS_REG, 0x27);  // Start measurement

// Read 8 bytes of raw data
uint8_t data[8];
i2c_read(BME280_ADDR, DATA_REG, data, 8);

// Apply compensation formulas (from datasheet)
float temp = bme280_compensate_temperature(data);
float pres = bme280_compensate_pressure(data);
float hum  = bme280_compensate_humidity(data);

The key advantage: you get three calibrated measurements from two wires (I2C SDA and SCL), and the same two wires can connect to dozens of other I2C sensors.

Common digital sensors: DHT11/DHT22 (temp/humidity), BME280/BMP280 (pressure/temp/humidity), MPU6050 (6-axis IMU), DS18B20 (1-Wire temperature), SHT31 (precision temp/humidity), ADXL345 (accelerometer), MAX31855 (thermocouple interface).

Side-by-Side Comparison

Here is how analog and digital sensors compare across the factors that matter most in embedded design:

FactorAnalogDigital
OutputContinuous voltage/currentDigital data via I2C/SPI/custom
ADC needed?Yes, on the MCUNo, built into sensor
Noise immunityLow — signal degrades with cable length and EMIHigh — digital bits are noise-immune
Cable lengthShort (<30cm ideal)Longer runs OK (I2C up to ~1m, RS-485 to 1km)
MCU pins used1 ADC pin per sensor2 shared pins (I2C) for up to 128 devices
Cost per sensor$0.10 – $1$1 – $10
CalibrationManual (your responsibility)Factory-calibrated
SpeedImmediate (limited by ADC sample rate)Conversion delay (DHT22: 2s between reads)
PowerMicroamps (passive sensors like thermistors)Milliamps (active processing circuitry)
Software effortADC config + calibration mathProtocol driver + register reads

When to Choose Analog Sensors

Analog sensors are the right choice when:

  • Cost is critical: In a product with thousands of units, saving $2 per sensor matters. A 10-cent thermistor does the job of a $3 digital temperature sensor.
  • Speed matters: Analog sensors respond instantly. There is no conversion delay, no protocol overhead. For vibration sensing or audio sampling, analog is often the only option.
  • Your MCU has available ADC pins: Most MCUs have 6-16 ADC channels. If you are using only a few, there is no reason to add I2C complexity.
  • The sensor is close to the MCU: Under 30cm of wire, noise is manageable with a simple RC filter.
  • Ultra-low power: A passive sensor like a thermistor or LDR draws essentially zero current. The only power consumed is through the voltage divider resistor, which you control.

When to Choose Digital Sensors

Digital sensors are the right choice when:

  • You need multiple sensors: I2C lets you connect dozens of sensors on two wires. An analog approach would quickly run out of ADC pins.
  • Accuracy is critical: Factory-calibrated digital sensors provide guaranteed accuracy without per-unit calibration in manufacturing. The BME280 provides ±0.5°C accuracy out of the box.
  • The sensor is far from the MCU: Digital signals survive longer cable runs without degradation. An analog signal over 2 meters of unshielded cable will be noisy; I2C over the same cable is clean.
  • You want combined measurements: A single BME280 replaces three analog sensors (thermistor + barometer + humidity sensor) plus their individual conditioning circuits.
  • You want to minimize PCB complexity: No op-amps, no precision resistors, no analog layout constraints. Just power, ground, and two data wires.

Mixing Both in One Design

Many real-world designs use both types. A typical weather station might use:

  • BME280 (digital, I2C) for calibrated temperature, humidity, and pressure
  • LDR (analog) for ambient light — because a $0.05 photoresistor is cheaper than a $2 digital light sensor when you only need a rough light level
  • Analog rain gauge with a simple voltage divider — because no digital rain sensor exists at this price point
  • Wind speed anemometer generating digital pulses — counted with a timer/counter peripheral

The decision is per-sensor, not per-project. Use the right type for each measurement based on the factors above.

Practical Tip: Start Digital, Go Analog Only When Needed

For prototyping and learning, digital sensors are easier to get working. An I2C sensor with a library gets you calibrated readings in minutes. An analog sensor requires understanding voltage dividers, ADC configuration, reference voltages, and calibration math.

Once your prototype works, evaluate whether switching specific sensors to analog saves enough cost or power to justify the additional engineering effort. For hobby projects and one-off builds, digital almost always wins on development speed.

📖 Related: LM35 Temperature Sensor: Working, Circuit, and Arduino CodeSignal Conditioning for Sensors: Amplification, Filtering, and Level Shifting

Leave a Reply

Your email address will not be published. Required fields are marked *