Digital and Analog Signals
Decide whether a sensor communicates with two logic states, a changing voltage, or the timing of pulses.
Digital uses two states; analog uses a range
Digital uses two states; analog uses a range
A digital input interprets two states: LOW/HIGH, or 0/1. The wire still carries a physical voltage; the receiving circuit decides which logic state it represents. A voltage in the undefined region between valid LOW and HIGH levels is not a useful third state.
An analog signal represents a quantity by a continuous range of values. A potentiometer wired between ground and 5 V can provide a changing voltage at its middle terminal. On a classic Uno R3, the usual analog measurement range is nominally 0–5 V with the default reference. That is not a universal sensor range.
Classify the sensor's output circuit, not just its name
Classify the sensor's output circuit, not just its name
| Device and connection | Signal at the input |
|---|---|
| Button or switch with a pull-up | Digital open/closed state. |
| Quadrature encoder with compatible logic outputs | Two digital pulse trains; their order gives direction. |
| HC-SR04 ultrasonic module, Echo pin | A timed digital pulse. Its duration represents distance; its voltage height does not. |
| Potentiometer connected as a voltage divider | Analog voltage from its wiper (middle terminal). |
| Photoresistor in a voltage divider | Analog voltage as resistance changes with light. |
| Phototransistor with a load resistor | Analog response to light unless a threshold circuit converts it to digital. |
| Pressure or proximity sensor | Depends on the model: analog voltage, switching output, or digital data. Read its documentation. |
A bare resistive sensor does not generate a usable voltage by itself: its surrounding circuit matters. A module may offer both analog and thresholded digital outputs.
Phototransistor circuits can measure light or switch at a threshold
Vishay's Ambient Light Sensors — Circuit and Window Design shows both light-meter circuits and light-switch circuits. The phototransistor current changes with illumination; the surrounding circuit determines whether the output preserves a range or switches between logic states.
Why an ultrasonic measurement can be digital
The HC-SR04 manufacturer datasheet, hosted by SparkFun describes an Echo pulse whose width represents the range. Digital describes the two voltage states; the information can be carried by their timing. A single digitalRead tells you the current state, not the pulse duration.
The ADC reads voltage; PWM controls time; Practice
The ADC reads voltage; PWM controls time
Analog-to-Digital Conversion turns an analog input into a number the program can use. Pulse-Width Modulation switches a digital output on and off for a controlled fraction of each cycle. Neither operation changes the fact that the processor stores and works with digital data.