Prefer to click through the interactive model?

ADC / DAC — study guide

The same fragments the interactive model serves, read in order. One source, two views.

Bridging the analog and digital worlds

a smooth voltage becomes a staircase of numbers, and back V time analog voltage sampled and quantized ADC: voltage to number DAC: number to voltage
An ADC samples a smooth continuous voltage into a stair-stepped sequence of numbers, and a DAC turns numbers back into a stepped voltage.

A digital pin lives in a world of two answers. It reads a voltage near the supply as HIGH and a voltage near ground as LOW, and everything in between is either rounded to one of those or refused outright. That is enough to read a button or blink a light, but the physical world does not arrive in ones and zeros. A temperature, a knob position, the loudness of a sound, the reading off most sensors — these are continuous voltages that slide smoothly through every value in a range.

An analog-to-digital converter, or ADC, is the bridge inward. It takes a continuous voltage and reports a number: measure the voltage, find where it falls in a known range, and hand the processor an integer standing for that level. A digital-to-analog converter, or DAC, is the bridge back out. It takes a number and produces the matching voltage, so a program can shape a smooth analog output instead of just switching a pin on and off.

Both directions lose something, because a number is discrete and a voltage is not. The whole craft of conversion is controlling that loss with two dials: how often you look at the signal, and how finely you divide the voltage range into numbered levels. Get those two right and the digital copy is indistinguishable from the analog original for the job at hand.

Sampling — snapshots of a moving voltage

An ADC does not watch a signal continuously. It looks at the voltage at one instant, measures it, and produces a single number for that instant; then it does the whole thing again a moment later. A conversion is a snapshot, and a stream of conversions is a stream of snapshots taken at a steady beat. What the voltage did between two snapshots is simply not recorded. like a strobe light flashing on a moving scene: you only ever see the frozen instants it lights up, and whatever moved in the dark between flashes leaves no record

The beat has a name: the sample rate, measured in samples per second. A rate of one thousand samples per second means the converter captures a fresh number a thousand times each second, spacing its snapshots a millisecond apart. Faster sampling packs the snapshots closer together, so the string of numbers traces the original curve more tightly and misses less of its movement.

This is the first of the two things a conversion quantizes. Sampling chops continuous time into discrete instants — the signal existed at every moment, but the digital record only knows the moments the converter happened to look. How closely those instants need to be spaced is not a matter of taste; it is set by how fast the signal itself moves.

Sample rate and the Nyquist trap

too few samples: a fast wave reads as a slow one that is not there V time real fast signal samples taken phantom (aliased) wave
Sampling a fast wave too slowly makes the sample points trace a slower phantom wave that was never in the signal.

There is a hard rule for how fast you must sample, and it depends on the fastest wiggle in the signal. To capture a signal whose highest frequency is some value, the sample rate has to be more than twice that frequency. This is the Nyquist criterion, and the doubling is not a safety margin — it is the floor. Sample a signal that reaches one thousand hertz, and you need more than two thousand samples per second just to have a chance of representing it.

Break the rule and the snapshots do not merely get rougher; they lie. A wave too fast for the sample rate gets caught at a different point in each of its cycles, and the numbers that come out trace a slower wave that was never there. This false low-frequency ghost is called aliasing, and it is dangerous because the digital record cannot tell it apart from a genuine slow signal — the numbers are self-consistent and completely wrong. like the spokes of a fast wheel filmed by a slow camera: they can appear to crawl or even spin backward, a motion that looks real on screen but is not what the wheel is doing

Aliasing cannot be undone after the fact, so real systems prevent it at the door. They either sample fast enough to stay above twice the highest frequency present, or they filter the incoming signal to remove frequencies above half the sample rate before it ever reaches the converter. Either way, the guiding number is the same: half the sample rate is the ceiling on what the signal is allowed to contain.

Bit depth — how fine the numbers are

step = Vref / 2^N : more bits, more levels, a nearer rung few bits: 4 coarse levels Vref 0 one step true value rounds to nearest line more bits: 8 fine levels Vref 0 smaller step true value rounds to a nearer line
An N-bit converter splits the reference span into 2-to-the-N equal levels of size Vref over 2-to-the-N, so more bits round a value to a nearer level.

Sampling handles time; bit depth handles value. When the converter measures a snapshot, it cannot report just any number — it has to pick one of a fixed set of levels and round the true voltage to the nearest one. The bit depth, or resolution, is how many bits that number carries, and an N-bit converter has exactly two-to-the-N levels to choose from. Every reading lands on one of them. like measuring with a ruler that only has marks every few millimeters: you have to call each length the nearest mark, and a ruler with finer marks leaves less rounding

The count grows fast. An 8-bit converter offers 256 levels, a 10-bit converter 1024, a 12-bit converter 4096. The size of one step is the voltage range divided by the number of levels: step equals the reference voltage divided by two-to-the-N. Over a 5 V range, a 10-bit converter's 1024 levels put each step at about 4.9 mV, so any real voltage is pinned to the nearest four-and-a-bit-millivolt rung. Move to 12 bits and the 4096 levels shrink each step to roughly 1.2 mV.

More bits means less rounding, and the difference is the size of the gap between what the signal was and what the number says it was. That gap is quantization error, and it never fully disappears — you can only make the steps small enough that it stops mattering for what you are measuring. A coarse converter turns a smooth slope into a visible staircase; a fine one makes the same staircase steps too small to notice.

The reference voltage sets the ruler

A level count on its own measures nothing. Two-to-the-N steps only become volts once you know what voltage the top and bottom of the scale stand for, and that span is set by the reference voltage. The reference is the full-scale value the converter maps to its highest code; zero volts maps to the lowest. Every number the ADC reports is really a fraction of the reference. like a measuring cup whose printed maximum sets the whole scale: the same number of graduations spread across a smaller cup measures a narrower range in finer marks

Because the step size is the reference divided by the number of levels, the reference does double duty: it fixes both the range you can measure and how much one step is worth. A 5 V reference over 1024 levels gives steps of about 4.9 mV; drop the reference to 3.3 V and those same 1024 levels now cover a narrower range in finer steps of roughly 3.2 mV each. Shrinking the reference buys resolution over a smaller window — useful when a sensor only ever swings across a volt or two.

The reference also sets a hard ceiling. A voltage above the reference does not read as a bigger number; it simply pins at the maximum code and stays there, so anything past full scale is invisible and indistinguishable from anything else past full scale. Choosing the reference is choosing the ruler: it decides what the biggest thing you can measure is, and how fine the marks are along the way.

DAC — turning numbers back into voltage

each number becomes a held voltage: the DAC builds a staircase V time codes in: 2 5 7 6 3 1 number sets the level
A DAC turns each digital number into a held voltage level, building an analog staircase that steps up and down with the numbers.

A digital-to-analog converter runs the whole process backward. Where an ADC takes a voltage and hands back a number, a DAC takes a number and produces the matching voltage: give it a code and it drives its output to the fraction of the reference that the code represents. Feed it a stream of numbers and it builds a stream of voltages, one held steady until the next number arrives.

That held-then-jumped output is a staircase, for the same reason the ADC's reading was. The DAC can only produce its two-to-the-N discrete levels, so a value meant to glide smoothly comes out as a series of flat steps. More bits mean finer steps and a smoother-looking result, exactly as on the way in; smoothing the corners off the staircase, when it matters, is a job for a filter after the converter.

Not every controller has a true DAC built in, so a common substitute is to switch a pin on and off very fast and let its average stand in for an analog level — a filtered PWM output, which the neighboring topic on pulse-width signals covers in its own right. However the voltage is produced, the payoff is the same: a program stops being limited to fully on or fully off and can set an output anywhere in between.

The ADC already in your controller

This is not exotic hardware you bolt on later. Most microcontrollers ship with an ADC already inside them, wired to a handful of pins that can read a voltage instead of just a logic level. The classic hobby board, the Arduino Uno, has a built-in 10-bit ADC: a read of an analog pin returns a number from 0 to 1023, measured against a default 5 V reference. Many newer controllers, such as the Raspberry Pi Pico and the ESP32, carry 12-bit ADCs that return 0 to 4095 over their range.

The canonical first thing to read is a potentiometer — a knob with a wiper that taps off a voltage somewhere between its two ends. Wire the ends across the supply and ground, feed the wiper into an analog pin, and turning the knob sweeps the voltage smoothly across the reference range. The controller reads it as a number that climbs and falls with the knob, and just like that a physical position has become an integer a program can act on.

From there every analog sensor works the same way, because most of them ultimately present their reading as a voltage. The controller does not know or care whether that voltage came from a knob, a light sensor, or a temperature probe; the ADC turns it into a number, and the number is where the program's job begins.

Why every real-world sensor needs this

A digital controller is deaf to the analog world without a converter in front of it. Its pins read only HIGH and LOW, but almost nothing worth sensing arrives that way — the readings that tell a machine what is happening around it are continuous voltages. The ADC is the ear that turns those voltages into numbers a program can compare, threshold, and reason about. Take it away and the controller can tell that a wire is high or low, and nothing else.

For a build like a small self-driving car, this is the gateway to the whole sensing side. Analog sensors that report a distance, a light level, or a battery voltage all reach the controller as a voltage, and every one of them passes through an ADC to become a usable number. Two choices set whether those numbers are trustworthy: sample fast enough for how quickly the reading changes, and use enough bits that the steps are finer than the difference you need to detect.

The outward direction matters too, wherever a controller has to produce a smooth level rather than a switch. Converting between numbers and voltages is the seam where the digital brain meets the physical body, and the sensors, buses, and control loops built on top of this concept all assume that seam is already in place. It is the first thing that has to work before any of them can.