Murray State University School of Engineering CourseWiki

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.

Digital waveform switches between LOW and HIGH; analog waveform changes smoothly through intermediate voltages. Both are plotted against time.

Classify the sensor's output circuit, not just its name

Classify the sensor's output circuit, not just its name

Common examples
Device and connectionSignal at the input
Button or switch with a pull-upDigital open/closed state.
Quadrature encoder with compatible logic outputsTwo digital pulse trains; their order gives direction.
HC-SR04 ultrasonic module, Echo pinA timed digital pulse. Its duration represents distance; its voltage height does not.
Potentiometer connected as a voltage dividerAnalog voltage from its wiper (middle terminal).
Photoresistor in a voltage dividerAnalog voltage as resistance changes with light.
Phototransistor with a load resistorAnalog response to light unless a threshold circuit converts it to digital.
Pressure or proximity sensorDepends 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.

Practice identifying sensor signals