Analog and Digital Sensors
After understanding what a sensor is, the next important concept is how sensors provide their output.
Sensors are commonly classified based on their output into:
- Analog Sensors
- Digital Sensors
1. Analog Sensors
An analog sensor produces a continuous electrical signal that changes according to the physical quantity being measured.
The output can have many different values within a particular range.
For example, an analog temperature sensor might produce:
Temperature Output Voltage 10°C 0.10 V 20°C 0.20 V 30°C 0.30 V 40°C 0.40 V
The output continuously changes as the temperature changes.
Simple representation
Physical Quantity ↓ Analog Sensor ↓ Continuous Signal ↓ Microcontroller ADC ↓ Digital Value
Example: LDR
An LDR (Light Dependent Resistor) changes its resistance according to the amount of light.
More Light ↓ LDR Resistance Changes ↓ Voltage Changes ↓ Arduino / ESP32 reads voltage
For example:
Dark → Low/High voltage depending on circuit Dim Light → Different voltage Bright → Different voltage
The exact voltage depends on how the LDR is connected in the circuit.
Example: LM35
The LM35 is an analog temperature sensor.
Its output voltage changes approximately linearly with temperature.
Conceptually:
Temperature ↑ ↓ Output Voltage ↑
An Arduino or ESP32 reads the voltage through an ADC (Analog-to-Digital Converter).
What is ADC?
A microcontroller works internally with digital values, but an analog sensor produces a continuous voltage.
Therefore, we need a conversion:
Analog Voltage ↓ ADC ↓ Digital Number
ADC = Analog-to-Digital Converter
For example, suppose an ADC has a range from:
0 V → 3.3 V
and produces values:
0 → 4095
Then:
0 V → 0 1.65 V → approximately 2048 3.3 V → 4095
This is typical of a 12-bit ADC over a 0–3.3 V range, although the exact usable range and behavior depend on the microcontroller.
ADC Resolution
ADC resolution determines how many digital levels can represent the analog input.
8-bit ADC
2⁸ = 256 levels 0 → 255
10-bit ADC
2¹⁰ = 1024 levels 0 → 1023
12-bit ADC
2¹² = 4096 levels 0 → 4095
Therefore:
Higher ADC resolution allows the input voltage to be represented using more digital levels.
However, higher nominal resolution does not automatically mean higher real-world measurement accuracy.
2. Digital Sensors
A digital sensor provides data in a digital form.
For simple digital sensors, the output may be:
LOW → 0 HIGH → 1
For example, a digital motion sensor may provide:
No Motion → LOW Motion → HIGH
Example: PIR Sensor
A PIR motion sensor can detect human movement.
Its digital output might behave like:
No motion ↓ LOW Motion detected ↓ HIGH
The microcontroller reads this using a digital input pin.
PIR ↓ Digital GPIO ↓ ESP32
Digital Sensors Can Also Send Data
Not every digital sensor simply outputs HIGH or LOW.
Many modern sensors communicate using digital communication protocols.
Common protocols include:
- I²C
- SPI
- UART
- 1-Wire
For example:
BME280 ↓ I²C ↓ ESP32
The BME280 can provide digital measurements such as:
- Temperature
- Humidity
- Atmospheric pressure
Analog vs Digital
| Feature | Analog Sensor | Digital Sensor |
|---|---|---|
| Output | Continuous signal | Digital signal/data |
| Typical output | Voltage/current/resistance | HIGH/LOW or digital data |
| ADC required | Usually yes | Usually no for digital interface |
| Noise sensitivity | Can be more affected by analog noise | Often better suited to digital processing |
| Examples | LDR, LM35, potentiometer | DHT22, BME280, digital PIR |
| Interface | ADC pin/circuit | GPIO, I²C, SPI, UART, etc. |
Important: Sensor vs Output Type
A sensor itself isn't always permanently "analog" or "digital" in every implementation.
For example, the same physical quantity, such as temperature, can be measured using:
Analog temperature sensor
LM35 ↓ Analog voltage ↓ ADC ↓ Temperature value
Digital temperature sensor
DS18B20 ↓ Digital data ↓ Microcontroller ↓ Temperature value
Both measure temperature, but they provide the information differently.
Analog Sensor Connection with Arduino
Example using an LDR:
5V │ LDR │ ├──────── A0 │ Resistor │ GND
The LDR and resistor form a voltage divider.
Arduino reads the voltage at A0.
int value = analogRead(A0); Serial.println(value);
The result depends on the Arduino board and ADC configuration.
For a typical Arduino Uno:
0 V → approximately 0 5 V → approximately 1023
because the Uno's default ADC is 10-bit.
Analog Sensor with ESP32
ESP32 boards have ADC-capable GPIOs.
For example:
#define SENSOR_PIN 34 void setup() { Serial.begin(115200); } void loop() { int value = analogRead(SENSOR_PIN); Serial.println(value); delay(500); }
The ESP32 reads the analog sensor and converts the input into a digital ADC reading.
Important: ESP32 ADC behavior depends on the specific ESP32 chip/board and configuration, so don't assume every board has exactly the same ADC characteristics.
Digital Sensor Connection
For a simple digital sensor:
Sensor │ ├── VCC ├── GND └── OUT │ ↓ ESP32 GPIO
Example:
#define SENSOR_PIN 27 void setup() { Serial.begin(115200); pinMode(SENSOR_PIN, INPUT); } void loop() { int state = digitalRead(SENSOR_PIN); if (state == HIGH) { Serial.println("Detected"); } else { Serial.println("Not Detected"); } delay(500); }
Analog Signal vs Digital Signal
Imagine a sensor measuring light intensity.
Analog
The signal can continuously change:
0.0V 0.4V 0.8V 1.2V 1.7V 2.1V 2.8V 3.3V
Digital
A simple digital sensor may report:
0 → No detection 1 → Detection
Or a digital communication sensor can send a complete numerical value, such as:
Temperature = 28.6°C Humidity = 64%
Advantages of Analog Sensors
- Simple circuit design for many applications
- Continuous measurement
- Often inexpensive
- Useful when the exact magnitude of a physical quantity is needed
- Can be directly interfaced with ADC inputs
Disadvantages
- Analog signals can be affected by electrical noise
- Usually require ADC conversion
- Long wires can introduce interference
- Signal conditioning may be required
- Accuracy depends on the sensor, circuit, ADC, reference, and noise
Advantages of Digital Sensors
- Easy to process using microcontrollers
- Digital communication can provide multiple measured values
- Often includes signal conditioning inside the sensor
- Less concern about analog voltage interpretation at the microcontroller input
- Can communicate using standard protocols such as I²C and SPI
Disadvantages
- Communication protocol is required for many sensors
- Some digital sensors are more expensive
- Software libraries may be required
- Protocol/address conflicts can occur in larger systems
Examples of Analog Sensors
Common examples include:
- LDR
- LM35
- Potentiometer
- Analog soil-moisture sensor
- Thermistor
- FSR
- Many MQ-series gas sensor modules
Examples of Digital Sensors
Common examples include:
- DHT11
- DHT22
- DS18B20
- BME280
- MPU6050
- Digital PIR modules
- Digital Hall-effect sensors
- VL53L0X
Some of these use a dedicated digital communication protocol rather than simply outputting HIGH/LOW.
Real-World Example: Automatic Street Light
Suppose we want to automatically turn ON a street light at night.
Using an analog LDR
Light ↓ LDR ↓ Analog Voltage ↓ Arduino/ESP32 ADC ↓ Program checks light level ↓ Relay ↓ Light
Example logic:
If light level < threshold ↓ DARK ↓ Light ON
Real-World Example: Motion Alarm
Using a digital PIR sensor:
Human Movement ↓ PIR Sensor ↓ Digital HIGH ↓ ESP32 ↓ Buzzer ↓ Alarm
Key Concept
The easiest way to remember the difference is:
ANALOG Physical Quantity ↓ Sensor ↓ Continuous Signal ↓ ADC ↓ Digital Number
DIGITAL Physical Quantity ↓ Sensor ↓ Digital Signal/Data ↓ Microcontroller
In one sentence:
Analog sensors provide continuously varying signals, while digital sensors provide discrete digital states or digital data that a microcontroller can process directly.