Electronics Basics

Analog and Digital Signals Compared

How continuous analog signals differ from two-state digital ones, and how ADCs and DACs let a microcontroller read and act on the real world.

On this page
  1. Two ways of carrying information
  2. Why digital is so robust
  3. Logic levels
  4. Where the two worlds meet
  5. Reading digital inputs well
  6. Sampling and what gets lost
  7. Choosing between them
  8. Safety note

Two ways of carrying information

A signal is a voltage that changes in a way that means something. What differs between analog and digital is how much of the voltage range carries meaning.

An analog signal can take any value within a range. A thermistor circuit, a microphone and a light sensor all produce voltages that slide smoothly as the temperature, sound or brightness changes. Every small change in the voltage matters.

A digital signal is treated as having just two meaningful states, usually called high and low, or 1 and 0. The exact voltage within each band matters much less than which side of a threshold it sits on.

A dimmer knob and a light switch are a handy comparison. The knob has endless in-between positions; the switch has two.

Why digital is so robust

Real wires pick up noise: small unwanted voltage wobbles from nearby power lines, motors, or the circuit’s own switching. On an analog line that wobble is mixed into the information and often cannot be separated from it afterwards.

On a digital line, a high just has to be recognisably high. A receiver typically has a threshold region, and as long as noise does not push the voltage across it, the receiver reads the right value. That is why long data connections between devices are almost always digital, and why a clean-looking 1 stays a 1 after being copied many times.

This does not make digital magic. Noise that is large enough, or edges that are too slow, can still cause misreads. It simply gives you a margin that analog lacks.

Logic levels

What counts as high or low depends on the chip family and its supply voltage. Boards commonly run at 3.3 V or 5 V, and a pin designed for one is not always safe to connect straight to the other. Datasheets list the voltage ranges a chip treats as low and high, and the maximum it can tolerate. Checking that before joining two boards is part of reading datasheets, and a mismatch can cause misreads or damage.

Where the two worlds meet

The physical world is mostly analog: temperatures, light levels, sounds and positions vary smoothly. A microcontroller is digital: it handles numbers. Converters sit in between.

Analog to digital (ADC)

An analog-to-digital converter measures a voltage and reports it as a whole number. Two ideas describe it:

  • Resolution. How many steps the range is divided into. A 10-bit converter has 1024 steps. Across a 5 V range, each step represents roughly 4.9 mV (5 divided by 1024).
  • Reference. The voltage that counts as full scale. If the reference is 5 V and the input is 2.5 V, a 10-bit reading would be about halfway, near 512.

Two practical points follow. First, the reading is only as good as the supply and reference behind it; a wobbling supply gives a wobbling number. Second, higher resolution does not guarantee higher accuracy, because noise and sensor limits can swamp the smallest steps.

Many boards have only a few analog-capable pins, and some share a single converter between them, so reading several channels happens one after another rather than all at once.

Digital to analog

Going the other way, a digital-to-analog converter (DAC) outputs a chosen voltage. Many hobby microcontrollers do not have one, or have only one or two. Makers more often use pulse-width modulation (PWM): a pin switches rapidly between high and low, and the fraction of time spent high (the duty cycle) sets the average level.

PWM is good for dimming LEDs and controlling motor speed, because the load responds to the average. It is not a true analog voltage, though. If you need a smooth voltage, a simple filter made from a resistor and a capacitor can average the pulses, with some residual ripple. For driving larger loads from a pin, the pin itself is not suitable, which is where transistor switching comes in.

Reading digital inputs well

A digital input expects a clearly high or clearly low voltage. If a pin is connected to nothing, it can pick up stray charge and read randomly. This is the floating input problem, and pull-up resistors are the usual remedy.

Mechanical buttons add a second wrinkle: their contacts bounce, producing a burst of rapid transitions on one press. This can be dealt with in hardware or software, and is a good example of an analog reality leaking into a digital view.

Sampling and what gets lost

Reading an analog signal in code means taking snapshots. You sample the value at intervals, and what happens between snapshots is invisible to the program. If the signal changes faster than you sample, the readings can misrepresent it. For slow things like room temperature, once a second is ample; for audio or vibration, sampling must be much faster and is usually handled by dedicated hardware.

It also helps to average several readings for a noisy sensor, trading a little speed for steadier numbers.

Choosing between them

A rough rule for makers: use digital signals wherever the information is naturally on or off, or where data must travel far or between chips. Use analog where you are measuring something continuous and have no digital version of the sensor. Many modern sensors do the conversion internally and hand you numbers over a digital bus, which can make the whole question simpler for you.

For small hardware with limited processing, such as tiny machine learning projects on microcontrollers, the quality of the analog front end still shapes what the code can do with the data.

Safety note

The voltages discussed here are low-voltage hobby levels. Follow manufacturer guidance for your boards and sensors, and never connect mains-powered equipment to inputs on a hobby board.

The complete guide to electronics basics

How Electronic Circuits Work A Maker Primer
Read the guide

Keep exploring

Guides from other topics

All topics →