Analog vs digital
An analog signal can take any value in a range, like a dimmer’s smooth brightness; a digital signal takes only set levels, usually two, HIGH and LOW, standing for 1 and 0. An analog-to-digital converter measures one in steps, so a 10-bit ADC on 5 V reads in 5 ÷ 1,024 ≈ 4.88 mV steps.
step = Vref ÷ 2n
where Vref is its full-scale voltage and n its number of bits, so a 10-bit ADC on 5 V reads in 4.88 mV steps.
Digital signals shrug off small noise; analog ones carry every wobble with them.
What is the difference between analog and digital?
An analog signal can be any value in a range and changes smoothly; a digital signal has only a few allowed values, usually two, and jumps between them.
Turn a potentiometer and an LED dims through every brightness in between, as in Figure 1: analog. Press a button and a pin reads only HIGH or LOW: digital. Most real circuits use both, sensing the analog world and processing it digitally.
Dial at 70%: the LED draws 2.02 mA. Every position of the knob gives its own current between 0.669 mA and 14.9 mA, with no steps: that is analog.
What is an analog signal?
An analog signal is a voltage or current that varies continuously to represent something, in proportion to it, like a microphone’s voltage following sound.
Sensors such as a thermistor in a divider, a light sensor or a microphone give analog signals. Amplifiers, filters and radio all started analog. Their weakness is that any noise added along the way becomes part of the signal and can’t be removed afterwards.
What is a digital signal?
A digital signal represents information as a sequence of set levels, almost always two: HIGH for 1 and LOW for 0, with a band in between that counts as neither.
A typical 5 V CMOS input reads anything above 3.5 V as HIGH and below 1.5 V as LOW, so noise smaller than that margin is ignored and the bits arrive exactly, as Figure 2 shows. That is why digital copies don’t degrade, and why logic gates can be chained by the billion. Chips pass bits to each other the same way, over serial buses such as I2C, SPI and UART.
Read as digital, ±1 V of noise: every HIGH stays above 3.5 V and every LOW below 1.5 V, so the input reads all 8 bits exactly; the noise is simply ignored.
How does an analog-to-digital converter work?
An analog-to-digital converter, or ADC, measures a voltage many times a second and turns each measurement into a number, in 2n steps for n bits.
More bits give finer steps, as Figure 3 shows; an Arduino Uno’s ADC has 10 bits, 1,024 levels. The sampling rate must be more than twice the highest frequency in the signal, which is why audio, heard up to about 20 kHz, is sampled at 44.1 kHz or more.
3-bit: 23 = 8 levels, so each step is a 1/8 of the range.
How do you turn a digital signal back into analog?
A digital-to-analog converter, or DAC, turns numbers back into voltages, and a microcontroller without one can fake it with PWM and a filter.
PWM switches a pin fully on and off quickly; a low-pass filter smooths it to its average, the duty cycle times the HIGH voltage. A motor averages PWM by itself, and your eye averages a fast-blinking LED, which is how a digital pin dims a light.
Is analog or digital better?
Neither: digital is better for storing, copying, sending and processing information without loss; analog is how the real world arrives and leaves, through sensors, microphones and speakers.
Digital wins on noise, accuracy over distance and flexibility, since software can change what it does. Analog can be simpler, faster and lower-power for one fixed job, and it never has steps. Most devices sense in analog, convert, think in digital, and convert back.
How do you work out an ADC’s step and a PWM pin’s voltage?
To work out an ADC’s step, divide the reference voltage by 2n, so 5 V over 10 bits is 4.88 mV; for filtered PWM’s average, multiply the duty cycle by the HIGH voltage.
Example 1: an ADC’s resolution
A 10-bit ADC measures 0 to 5 V. How many levels does it have, and how big is each step?
- Given
- a 10-bit ADC with a 5 V reference
- Find
- how many levels it has and its smallest step
- Solution
- Levels = 210 = 1,024Step = 5 V ÷ 1,024 = 4.88 mV
- Answer
- 1,024 levels, 4.88 mV each
Example 2: an analog-looking voltage from a digital pin
A 5 V pin uses PWM at 25% duty, and a filter smooths it. What steady voltage comes out?
- Given
- a 5 V digital pin switching on and off 25% of the time, smoothed by a filter
- Find
- the voltage it averages to
- Solution
- V = 0.25 × 5 V = 1.25 V
- Answer
- 1.25 V
Summary
Key equations
- levels = 2n an n-bit converter
- step = Vref ÷ 2n its resolution
- Vavg = duty × Vhigh filtered PWM
Key terms
- ADC
- Analog in, a number out.
- DAC
- A number in, a voltage out.
- Sampling rate
- Readings a second.
- Logic level
- The voltage that counts as 1 or 0.
Practice problems
-
Which is an analog signal?
It follows the sound smoothly through every value; the others switch between two levels.
-
How many levels does an 8-bit ADC have?
2⁸ = 256 levels, numbered 0 to 255.
-
A 12-bit ADC reads 0 to 5 V. What is its step?
5 V ÷ 2¹² = 5 V ÷ 4,096 ≈ 1.22 mV.
-
Why do digital signals resist noise?
Noise that doesn’t push a level across the threshold changes nothing in the reading.
-
A 5 V PWM pin at 40% duty is filtered. What voltage comes out?
0.4 × 5 V = 2 V.
FAQ
Is a potentiometer analog or digital?
Analog: turning it varies the resistance smoothly. Read it with an ADC and the number you get is digital.
Is a push button analog or digital?
Digital in use: it is either pressed or not, and a pin reads it as HIGH or LOW, usually with a pull-up resistor.
Is sound analog or digital?
Sound itself is analog, a smooth pressure wave. A phone or computer stores it digitally, as samples from an ADC.
What does analogRead do on an Arduino?
It uses the board’s 10-bit ADC to turn a pin’s voltage into a number from 0 to 1,023.
Can analogWrite output a real analog voltage?
On most Arduino boards, no: it outputs PWM, a fast on-off signal whose average is the voltage you asked for.
What is a logic level?
The voltage a digital input treats as 1 or 0. A 3.3 V board and a 5 V board have different levels, so connecting them can need a level shifter.
Why is digital audio sampled at 44.1 kHz?
To capture sound up to about 20 kHz, the top of human hearing, a signal must be sampled more than twice as fast.
What are digital circuits?
Circuits that work with just two voltage levels, 0 and 1, such as 0 V and 5 V, built from logic gates; computers, phones and microcontrollers are all digital circuits.