35 ADC and DAC: Conversion Calculations
More
Depth: Practitioner
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
35.1 Start With the Decision
This section: Start With the Decision — An ADC turns a voltage into a digital count.
An ADC turns a voltage into a digital count. The reference is the voltage used for comparison. The scale maps counts back to volts, and the range sets the allowed input span. An ADC count is useful only when it maps back to the measured voltage. Work the scale, error, and range at the bench.
35.2 Route Overview
This section: Route Overview — This is part 1 of 2.
This is part 1 of 2. Continue with ADC and DAC: Interactive Design Calculators.
35.3 Part Objectives
This section: Part Objectives
- Test adc/dac worked examples with a concrete scenario and pass criteria.
- Validate adc/dac calculation links with a concrete scenario and pass criteria.
35.4 Start Simple
This section: Start Simple — Picture a light sensor producing 1.20 volts while a device shows a digital count and the dashboard shows a percentage.
Make the Bench Value and the Screen Value Agree
Picture a light sensor producing 1.20 volts while a device shows a digital count and the dashboard shows a percentage. The test engineer must show how one known input becomes both outputs without hiding a reference value, scale factor, unit change, or rounding choice.
Write the known values first. Record input range, reference, number of steps, output unit, formula, and rounding rule. Calculate the expected count by hand, then run the same value through the device. Keep the code, board, settings, and meter reading with the result.
Try zero, mid-range, near-full-scale, just outside range, a changed reference, a negative input where allowed, and a value between two codes. Check clipping, rounding, output reconstruction, and the final display. Reverse the calculation to see whether the reported value can recover the original within the stated limit.
Do not use a neat digital result as proof that the physical input is safe or accurate. Keep urgent control on a path that handles out-of-range and failed-input states locally. A distant chart may show the result, but it cannot restore resolution lost at conversion.
This opening does not cover every converter design. Practitioner builds the input-to-output worksheet and bench check. Under the Hood examines step size, reference error, noise, sample timing, output levels, and uncertainty.
Use this value check:
- Write each known value.
- Keep each stated unit.
- Work the sum once.
- Test the mid point.
- Test both end points.
- Check the round trip.
Imagine a datasheet number, an ADC code, and a dashboard value that must all agree. Worked examples show the conversion path step by step so no scale factor, reference voltage, or rounding decision hides in the code. Start with one known input, calculate the expected digital value, and compare it with a measured result.
- Start Simple
- In 60 Seconds
- Phoebe’s Field Notes: Where the Converter Numbers Come From
- Key Concepts
- ADC/DAC Worked Examples
- Prerequisites
- Why This Chapter Matters
- How To Use This Chapter
- ADC Conversion Formula
- 10-bit Temperature ADC
- LM35 Temperature Example
- Quantization Error Example
- Checkpoint: ADC Codes and Error
- Knowledge Check: ADC Step Size
- Nyquist Audio Sampling
- Vibration Accelerometer Example
- ESP32 Soil Moisture Example
- Ultrasonic Distance Example
- Checkpoint: Sampling and Sensor Fit
- 8-bit DAC Motor Control
- Gamma-Corrected LED Dimming
- Checkpoint: DAC and Dimming
- Knowledge Check Quiz
- Quiz: ADC Conversion Calculation
- Quiz: DAC Output Voltage
- For Kids: Meet the Sensor Squad!
- ADC Input Impedance Pitfall
- Key Takeaway
- ADC/DAC Calculation Links
Use this path through the worked examples:
- First turn input voltage into ADC codes, then convert the code back into a physical value.
- Then quantify the limits: reference voltage, step size, and quantization error.
- Next apply the same discipline to sampling-rate and sensor-fit examples.
- Finally reverse the direction with DAC output, gamma correction, calculators, and review quizzes.
Checkpoints recap the calculation pattern; collapsed examples and calculators are deeper practice once the main flow is clear.
- Worked Example Structure: Each worked example follows the same format: problem statement, identify knowns and unknowns, select the appropriate formula, substitute values with units, compute result, verify the answer is physically plausible, and state the practical implication
- Unit Consistency Checking: All quantities in a formula must use consistent SI base units before computing; convert mA to A, kOhm to Ohm, nF to F, and mV to V before substituting into formulas to prevent systematic errors by factors of 10^3
- Voltage Divider Analysis: Vout = Vin x R2 / (R1 + R2); used in thermistor circuits, LDR circuits, and reference voltage generation; the key insight: Vout approaches Vin when R2 >> R1, and approaches 0 when R2 << R1
- LED Current Limiting Design: R = (Vsupply - Vf) / If; typical values: Vsupply = 3.3 V, Vf = 2.0 V (red LED), If = 10 mA; R = (3.3 - 2.0) / 0.010 = 130 ohm; round up to 150 ohm standard value for safety
- RC Filter Cutoff Calculation: fc = 1 / (2 pi R C); 10 kohm and 100 nF gives fc = 1 / (2 pi x 10000 x 100e-9) = 159 Hz; any noise above 159 Hz is attenuated; signals well below 159 Hz pass without significant attenuation
- Battery Life Estimation: Runtime (hours) = Battery capacity (mAh) / Average current (mA); for duty-cycled devices: Iavg = Iactive x duty_cycle + Isleep x (1 - duty_cycle); a 1000 mAh battery powering a 50 mA active / 0.1 mA sleep device at 10% duty cycle: Iavg = 5 + 0.09 = 5.09 mA; runtime = 1000/5.09 = 196 hours
- ADC Voltage Conversion: Voltage = (ADC_reading / (2^bits - 1)) x Vref; for a 12-bit ADC reading 2048 with Vref = 3.3 V: V = (2048/4095) x 3.3 = 1.65 V; verify: at maximum reading (4095), output = Vref = 3.3 V (correct)
- Power Dissipation Check: P = V^2 / R or P = I^2 x R; a 100 ohm resistor carrying 50 mA: P = (0.050)^2 x 100 = 0.25 W; requires at least a 0.5 W rated resistor (50% safety margin); a 1/4 W (0.25 W) resistor would run at its absolute limit and fail early
35.5 Learning Objectives
This section: Learning Objectives
- Calculate ADC Output: Compute digital values from analog voltage inputs using the ADC conversion formula
- Select Reference Voltages: Evaluate and match Vref to sensor output ranges for maximum resolution
- Quantify Quantization Error: Derive measurement precision limits across different ADC resolutions
- Determine Nyquist Sampling Rates: Compute minimum and practical sampling frequencies for specific signal types
- Compute DAC Output Voltages: Derive specific analog voltages from digital input values
- Construct Gamma Correction Tables: Build non-linear mappings for perceptually accurate LED dimming
This chapter walks through the math behind converting real-world sensor voltages into digital numbers and back again, step by step. If you have ever wondered how a temperature sensor’s voltage becomes the “23.5C” on your screen, these worked examples show exactly how that calculation happens. No advanced math is needed — just multiplication and division.
35.6 Prerequisites
This section: Prerequisites
Before diving into this chapter, you should be familiar with:
- ADC Fundamentals: Understanding of ADC operation and resolution
- Nyquist Sampling Theory: Understanding of sampling rate requirements
- Binary Fundamentals: Binary number systems and powers of 2
35.7 Why This Chapter Matters
This section: Why This Chapter Matters — Follow these connections in order: This is the chapter that turns the earlier ideas into engineering workflow.
Follow these connections in order: This is the chapter that turns the earlier ideas into engineering workflow. Students often think they understand a topic until they have to plug in numbers and justify a design choice. In real IoT work, this kind of calculation is what connects a sensor datasheet, a microcontroller spec, and an actual usable measurement or control signal. After this chapter, a beginner should be able to work through converter problems step by step instead of treating ADC and DAC settings as mysterious configuration values.
35.8 How To Use This Chapter
This section: How To Use This Chapter
- Work the examples in order. They were chosen to move from direct formula use toward more realistic design decisions.
- Before reading each solution, try to identify the known values, the unknown value, and the governing formula yourself.
- If you get stuck, the goal is not speed. The goal is to learn a repeatable method: identify, calculate, verify, interpret.
35.9 ADC Conversion Formula
This section: ADC Conversion Formula — Start with the smallest complete loop: a voltage goes into the converter, a digital code comes out, and the code must still make physical sense when converted back.
Start with the smallest complete loop: a voltage goes into the converter, a digital code comes out, and the code must still make physical sense when converted back.
The fundamental ADC conversion formula relates analog input voltage to digital output value:
Where:
- = Analog input voltage (volts)
- = Reference voltage (maximum measurable voltage)
- = ADC resolution (number of bits)
- = Floor function (round down to nearest integer)
Inspect the labelled evidence in Figure 35.1 as the entry point to adc conversion formula. The visual is specifically about aDC conversion showing how continuous analog voltage is sampled and quantized into discrete digital steps.
First identify Temperature vs Resistance in Figure 35.1, then contrast it with Resistance (OHMs) and test the claim beside Relationship. These visible labels explain aDC conversion showing how continuous analog voltage is sampled and quantized into discrete digital steps. They keep adc conversion formula tied to evidence that can be inspected on the schematic, part, or trace.
35.10 10-bit Temperature ADC
This section: 10-bit Temperature ADC
Given:
- ADC Resolution: 10 bits (Arduino Uno)
- = 3.3V
- = 1.65V (sensor output at 25C)
Calculate Digital Output:
Result: The ADC outputs 511 (binary: 0111111111)
Verification:
- 511.5 is exactly half of 1023, so the floor gives 511, confirming is half of
- This digital value would be read by
analogRead(A0)as 511
35.11 LM35 Temperature Example
This section: LM35 Temperature Example — The LM35 is a popular precision temperature sensor that outputs 10mV per degree Celsius.
The LM35 is a popular precision temperature sensor that outputs 10mV per degree Celsius.
LM35 Specifications:
- Output: 10mV/C
- Temperature Range: 0-100C
- Voltage Range: 0-1.0V
Scenario: Measuring room temperature (25C) with 10-bit ADC
Step 1: Calculate Sensor Output Voltage
Step 2: ADC Configuration
For optimal resolution with 0-1V sensor range:
- Use = 1.0V (external reference or ATmega internal 1.1V)
- Resolution: 10-bit → 1024 discrete values
Step 3: Calculate Digital Output
Step 4: Calculate Resolution (Temperature per ADC Count)
This means each ADC step represents approximately 0.1C change.
Step 5: Convert ADC Reading Back to Temperature
Key Insight: By matching to sensor range (1V instead of 5V), we maximize resolution and minimize wasted ADC range.
Comparison: 5V Reference vs 1V Reference
| Configuration | Resolution | Wasted Range | Temperature Precision |
|---|---|---|---|
| 5V Vref | 4.88mV/count | 80% (1V used, 4V unused) | 0.488C/count |
| 1V Vref | 0.977mV/count | 0% (1V used, 1V available) | 0.098C/count |
Using 1V reference gives 5x better temperature resolution by fully utilizing ADC range!
35.12 Quantization Error Example
This section: Quantization Error Example — Quantization error is the inherent inaccuracy introduced when converting continuous analog signals to discrete digital values.
Quantization error is the inherent inaccuracy introduced when converting continuous analog signals to discrete digital values.
Quantization Error Formula:
Where LSB (Least Significant Bit) is the smallest voltage change the ADC can detect.
10-bit ADC with 3.3V Reference:
What This Means:
- Under the floor rule above, 1.650 V gives code 511, while 1.653 V gives code 512
- Worst-case error: +/-1.61mV from actual voltage
Comparison Across ADC Resolutions:
| Resolution | LSB Step (3.3V) | Max Error | Example Use Case |
|---|---|---|---|
| 8-bit | 12.9mV | +/-6.45mV | Low-cost light sensors |
| 10-bit | 3.22mV | +/-1.61mV | Arduino Uno (general purpose) |
| 12-bit | 0.805mV | +/-0.403mV | ESP32 (precision sensors) |
| 16-bit | 0.0503mV | +/-0.0252mV | Thermocouples, strain gauges |
Reducing Quantization Error:
-
Use Higher Resolution ADC
- 12-bit vs 10-bit: 4x reduction in error (1.61mV → 0.403mV)
- 16-bit vs 10-bit: 64x reduction in error
-
Oversampling and Averaging
- Average N samples to gain extra resolution
- Effective bits increase by log2(N)/2
- Example: Average 16 samples with 10-bit ADC → 12-bit effective resolution
-
Match Vref to Signal Range
- If measuring 0-1V signal, use 1V reference (not 3.3V or 5V)
- Maximizes use of ADC’s available range
This section:
Checkpoint: ADC Codes and Error
You now know:
- A 10-bit ADC reports codes from 0 to 1023, so half of a 3.3V reference lands at code 511 after the floor operation.
- Matching the LM35’s 0-1V range to a 1V reference gives about 0.1C per count instead of wasting 80% of a 5V range.
- Quantization error is bounded by half an LSB: 3.22mV steps give +/-1.61mV worst-case error, while 16-sample averaging can reach 12-bit effective resolution.
35.13 Nyquist Audio Sampling
This section: Nyquist Audio Sampling — The ADC examples handled voltage resolution.
The ADC examples handled voltage resolution. The next question is time resolution: how often must the system sample so the changing signal is still recoverable?
Given:
- Human voice frequency range: 300 Hz to 3.4 kHz
- Highest frequency: = 3.4 kHz
Calculate Minimum Sampling Rate:
Practical Implementation:
- Telephone systems: 8 kHz (provides margin above 6.8 kHz minimum)
- VoIP codecs: 8-16 kHz
- Audio recording: 44.1-48 kHz (for full 20 kHz human hearing range)
35.14 Vibration Accelerometer Example
This section: Vibration Accelerometer Example
Given:
- Machine vibration events: 0-100 Hz
- Highest frequency: = 100 Hz
Calculate Minimum Sampling Rate:
Practical Implementation:
- Industrial IoT: 500-1000 Hz (2.5-5x oversampling for safety margin)
- Allows detection of unexpected high-frequency faults
- Ensures anti-aliasing filter has gradual roll-off
Real-World Sampling Rates:
| Application | Signal Bandwidth | Nyquist Minimum | Practical Rate | Oversampling Factor |
|---|---|---|---|---|
| Audio (telephone) | 3.4 kHz | 6.8 kHz | 8 kHz | 1.2x (minimal) |
| Audio (music) | 20 kHz | 40 kHz | 44.1-48 kHz | 1.1-1.2x |
| Accelerometer | 100 Hz | 200 Hz | 500-1000 Hz | 2.5-5x |
| ECG (heartbeat) | 150 Hz | 300 Hz | 500-1000 Hz | 1.7-3.3x |
| Ultrasonic distance | 40 kHz | 80 kHz | 200 kHz+ | 2.5x |
35.15 ESP32 Soil Moisture Example
This section: ESP32 Soil Moisture Example
Soil Moisture Sensor ADC Optimization for Precision Agriculture
Scenario: A smart irrigation system uses a capacitive soil moisture sensor that outputs 1.2V (dry) to 2.8V (saturated). You need to determine optimal ADC configuration on an ESP32 to detect 1% moisture changes for water-efficient farming.
Given:
- Sensor output range: 1.2V (dry/0%) to 2.8V (saturated/100%)
- ESP32 ADC: 12-bit, configurable attenuation (0 dB, 2.5 dB, 6 dB, 11 dB)
- Moisture measurement range: 0-100%
- Required resolution: 1% moisture change detection
Steps:
-
Calculate voltage per percent moisture:
-
Choose and verify the input range: Select attenuation for the exact ESP32 variant, then calibrate and test the full 1.2–2.8 V sensor span. Attenuation does not guarantee linearity or accuracy.
-
Measure the usable resolution: Compare the calibrated voltage change per code and measured noise with the required 16 mV change.
-
Check nonlinearity: Test known voltages across the span; use a divider or external ADC if the required accuracy is not achieved.
-
Implement oversampling for noise reduction:
- Average 64 samples to gain ~3 effective bits
- Effective resolution: 12 + 3 = 15 bits equivalent
- Averaging 64 samples may provide about three additional effective bits under the conditions below; it does not guarantee 15-bit performance.
Result:
- Measure dry and wet endpoint codes under the installed conditions.
- For the assumed linear endpoint model, use moisture_percent = 100.0 * (adc_value - dry_code) / (wet_code - dry_code).
- With 64-sample averaging, the modeled code spacing could be <0.01% VWC if effective bits are actually gained; measure ENOB and sensor calibration before claiming moisture resolution.
Key Insight: Verify attenuation, calibration, noise, and the sensor relationship together before claiming moisture resolution or accuracy.
35.16 Ultrasonic Distance Example
This section: Ultrasonic Distance Example
Ultrasonic Distance Measurement Timing with ADC Sampling
Scenario: An autonomous robot uses an HC-SR04 ultrasonic sensor for obstacle detection. The echo pulse width (about 117 µs to 23.3 ms for 2 cm to 4 m at 20 °C) must be measured accurately. You need to determine if ADC-based measurement or timer-based capture is appropriate.
Given:
- Round-trip echo time at 343 m/s: about 117 µs for 2 cm and 23.3 ms for 4 m; keep the trigger pulse duration separate.
- Speed of sound: 343 m/s at 20C
- Required distance accuracy: 1cm
- ESP32 ADC sampling rate: 2 MSPS maximum (but limited in practice)
- ESP32 timer resolution: 12.5ns (80MHz clock)
Steps:
-
Calculate time per centimeter of distance: (Factor of 2 because sound travels to object and back)
-
Evaluate ADC-based approach:
- If we sample analog echo signal at 100kHz: 10us between samples
- Time resolution: 10us corresponds to 0.17cm
- Problem: HC-SR04 outputs digital pulse, not analog - ADC not appropriate
-
Evaluate timer-based approach (correct method):
- ESP32 timer at 80MHz: 12.5ns resolution
- Theoretical distance resolution: 0.5 x 343 m/s x 12.5ns = 0.002mm
- Far exceeds 1cm requirement
-
Implement with pulseIn() timing (try on Wokwi):
duration_us = pulseIn(ECHO_PIN, HIGH); // Measures pulse width distance_cm = duration_us / 58.3; // Convert to distance -
Consider temperature compensation:
- Speed of sound: m/s
- At 0C: v = 331.3 m/s (time factor = 60.3 us/cm)
- At 40C: v = 355.5 m/s (time factor = 56.2 us/cm)
- Using 343 m/s throughout 0–40 °C gives approximately +3.5% error at 0 °C and −3.5% at 40 °C.
Result:
- Use hardware timer capture, not ADC, for pulse width measurement
- Distance calculation:
distance_cm = duration_us * speed_of_sound / 20000 - Temperature compensation removes one error source; verify the 1 cm requirement across distance, target, mounting, and environmental conditions.
Key Insight: ADCs are for converting analog voltage levels to digital values. For timing measurements (pulse width, frequency), use hardware timers or input capture peripherals.
This section:
Checkpoint: Sampling and Sensor Fit
You now know:
- Voice at 3.4 kHz needs at least 6.8 kHz sampling, so 8 kHz gives a practical telephone-rate margin.
- A 100 Hz vibration signal needs 200 Hz minimum sampling, but 500-1000 Hz gives filter and fault-detection margin.
- In the soil example, 64-sample averaging could improve nominal code spacing if ENOB is measured to increase; ultrasonic distance needs timer capture and separate accuracy validation.
35.17 8-bit DAC Motor Control
This section: 8-bit DAC Motor Control — Now reverse the conversion path.
Now reverse the conversion path. Instead of asking which code represents a measured voltage, ask which output voltage a digital code will command.
Given:
- DAC Resolution: 8 bits (0-255)
- = 5V
- Motor controller accepts 0-5V (0V = stopped, 5V = full speed)
DAC Formula:
Calculate Output Voltages:
| Speed Setting | Digital Input | Calculation | DAC Output | Motor Speed |
|---|---|---|---|---|
| Stopped | 0 | 0.00V | 0% | |
| 25% Speed | 64 | 1.25V | 25% | |
| 50% Speed | 128 | 2.51V | 50% | |
| 75% Speed | 192 | 3.76V | 75% | |
| Full Speed | 255 | 5.00V | 100% |
Arduino Code Example (try on Wokwi):
// Control motor speed with DAC output
int speed_percent = 50; // 50% speed
int dac_value = map(speed_percent, 0, 100, 0, 255);
// On ESP32 with built-in DAC (8-bit, 0-3.3V output):
dacWrite(DAC1, dac_value); // Outputs ~1.65V (50% of 3.3V Vref)
// Note: For 0-5V motor control, add an op-amp gain stage after DAC
35.18 Gamma-Corrected LED Dimming
This section: Gamma-Corrected LED Dimming — Human perception of LED brightness is nonlinear; the example below approximates it with a gamma-2.2 power law.
Human perception of LED brightness is nonlinear; the example below approximates it with a gamma-2.2 power law. A “50% brightness” setting needs gamma correction to appear closer to half as bright.
Linear DAC (appears too bright):
- With a linear LED-current or PWM-duty driver, a 50% drive fraction appears about 73% as bright under the example’s gamma-2.2 model; a 2.5 V DAC output alone does not determine LED brightness.
Gamma-Corrected DAC (perceptually accurate):
For 50% perceived brightness:
Comparison:
| Desired perceived brightness | Uncorrected linear LED-drive value | Modeled perceived brightness | Gamma-corrected LED-drive value | Modeled perceived brightness |
|---|---|---|---|---|
| 25% modeled target | 64 | ~53% under gamma 2.2 | 12 | ~25% under gamma 2.2 |
| 50% modeled target | 128 | ~73% under gamma 2.2 | 56 | ~50% under gamma 2.2 |
| 75% modeled target | 192 | ~88% under gamma 2.2 | 135 | ~75% under gamma 2.2 |
Arduino Gamma Correction Code (computed directly):
void setLEDBrightness(int percent) {
float target = constrain(percent, 0, 100) / 100.0f;
int corrected = (int)roundf(powf(target, 2.2f) * 255.0f);
analogWrite(LED_PIN, corrected);
}
This section:
Checkpoint: DAC and Dimming
You now know:
- An 8-bit DAC spans 0-255 codes, so 64, 128, 192, and 255 produce about 1.25V, 2.51V, 3.76V, and 5.00V on a 5V reference.
- On an ESP32, the same 50% code maps to about 1.65V because the built-in DAC uses a 3.3V output range.
- Gamma correction changes a 50% perceived LED setting from linear code 128 to about code 56 with gamma 2.2.
35.19 Knowledge Check Quiz
This section: Knowledge Check Quiz
This section:
Math helps the Sensor Squad turn real-world measurements into exact numbers!
35.19.1 Temperature Detective Story
Temperature Terry was measuring the temperature of a fish tank. “It is 25 degrees Celsius! I am sending out 0.250 volts.”
ADC Andy looked at the signal. “Okay, I need to turn that into a number Max can understand. My scale goes from 0 to 1023 — that is 1024 steps because I am a 10-bit ADC.”
the microcontroller was curious. “How do you figure out which step number matches 0.250 volts?”
Andy pulled out his formula notebook. “Easy! The fish tank sensor goes from 0 volts (freezing) to 1 volt (boiling hot for fish). So 0.250 volts is one quarter of the way. One quarter of 1023 is about 255. So I tell Max: the reading is 255!”
the LED wanted to know more. “And how does Max turn 255 back into a temperature?”
Max smiled. “I divide 255 by 1023 and multiply by 100 degrees. That gives me about 25 degrees — exactly what Sammy measured!”
the battery chimed in. “But what if you only had 256 steps instead of 1024?”
Andy nodded. “Then each step would be a bigger jump — about 0.4 degrees instead of 0.1 degrees. I would be less precise. That is why more steps (higher resolution) means better measurements!”
35.19.2 Key Words for Kids
| Word | What It Means |
|---|---|
| ADC Formula | The math equation that converts voltage to a number |
| Resolution | How many steps you have (more steps = more precise) |
| Reference Voltage | The maximum voltage the ADC can measure |
| Quantization Error | The tiny mistake from rounding to the nearest step |
| Gamma Correction | Special math to make LED brightness look right to human eyes |
35.19.3 Try This at Home!
The Step Calculator Game!
- Imagine you have a ruler that only goes from 0 to 10 (11 marks)
- Measure something that is about 7.3 cm long
- With only 11 marks, you would round to 7 — that is like an ADC with low resolution!
- Now imagine a ruler with 0 to 100 (101 marks) — you could say 73!
- With 0 to 1000 (1001 marks) — you could say 730!
What you learned: More marks on your ruler (higher ADC resolution) means you can measure more precisely. The rounding you do is quantization error — it is small but always there!
This section:
Compare the two sensor-to-converter paths. The upper path connects a weak source directly; the lower path inserts a buffer.
-
Wrong: A weak sensor source always gives a true reading. Add a buffer so the input can charge.
The red cross marks the direct path, whose reading may be biased when the converter samples. In the lower path the added amplifier drives the converter input so it can settle. The divider example below shows why source resistance matters even when the steady voltage looks right.
The Error: You use a 200 kΩ upper and 100 kΩ lower divider to bring a 5 V sensor output to about 1.67 V for an ESP32 ADC. The high-resistance source may give an inaccurate reading if the ADC input does not settle during acquisition. What should you check?
Why It Happens: ADC inputs are not infinite impedance. The ESP32 ADC has an internal sample-and-hold capacitor that draws charging current during conversion. High-impedance sources (like voltage dividers with large resistors) may not settle in the available acquisition time, biasing the reading toward a prior sample voltage when acquisition is too short.
The Numbers:
- ESP32 ADC: Input impedance ~100 MΩ (DC), but sample capacitor ~6 pF
- Voltage divider: 200 kΩ ∥ 100 kΩ = 66.7 kΩ output impedance
- Illustrative RC time constant: 66.7 kΩ × 6 pF ≈ 400 ns, before ADC switch and parasitic capacitances
- ESP32 ADC conversion time: ~10 µs
Problem: The illustrative 400 ns RC time constant must be checked against the ADC acquisition phase, not the whole conversion time; if settling fails, the reading can be biased toward the previously held voltage. No 5–10% error can be inferred without acquisition timing.
Correct Design Rules:
-
Check ADC source resistance and acquisition time: use the divider’s Thevenin resistance R1 ∥ R2, not R1 + R2, and verify the chosen ADC’s input settling.
- A 2 kΩ upper / 1 kΩ lower divider gives about 1.67 V from 5 V and 667 Ω source resistance.
- Trade-off: Lower resistance = more current draw (power vs accuracy)
-
Add buffer capacitor: 0.1µF capacitor at ADC input
- Acts as local charge reservoir
- Reduces effect of source impedance
- Place within 1 cm of ADC pin
-
Use op-amp buffer: For high-impedance sensors (>10kΩ)
- Rail-to-rail op-amp (MCP6002) between sensor and ADC
- Input impedance: >1 GΩ (doesn’t load sensor)
- Output impedance: ~50Ω (drives ADC easily)
Example Calculation:
5 V sensor → about 1.67 V ESP32 ADC input:
High-impedance, unbuffered: R1 = 200 kΩ, R2 = 100 kΩ; Vout = 1.67 V; Rth = 66.7 kΩ; verify acquisition settling.
Lower-impedance alternative: R1 = 2 kΩ, R2 = 1 kΩ; Vout = 1.67 V; Rth = 667 Ω; divider current = 5 V / 3 kΩ = 1.67 mA.
Best (op-amp buffer):
- High-impedance 200 kΩ upper / 100 kΩ lower divider (low power)
- Op-amp output drives ADC directly
- Divider current: 5 V / 300 kΩ = 16.7 µA, plus the op-amp quiescent current (MCP6002: about 100 µA typical per amplifier)
Verification: Apply known voltages, alternate high and low input levels, and compare calibrated readings at different acquisition settings. Dependence on the previous sample or acquisition time can reveal settling error; a consistently low value alone does not identify its cause.
This section:
ADC and DAC calculations are the practical math behind every sensor and actuator interface in IoT. The key formulas — Digital Output = floor((Vin/Vref) x (2^n - 1)) for ADC and Vout = Vref x (Digital Input / (2^n - 1)) for DAC — along with matching reference voltage to sensor range and applying Nyquist sampling rates, form the essential toolkit for reliable IoT hardware design.
This section:
35.20 ADC/DAC Calculation Links
This section: ADC/DAC Calculation Links — Key Insight: Every ADC calculation starts with matching Vref to the sensor’s output range to maximize resolution.
| Calculation Type | Key Formula | Depends On | Used In |
|---|---|---|---|
| ADC Output | floor((Vin/Vref) × (2^n - 1)) | Input voltage, Reference voltage, Resolution (n bits) | All sensor readings |
| DAC Output | Vref × (Digital / (2^n - 1)) | Digital value, Reference voltage, Resolution | Analog control signals |
| Step Size | Vref / 2^n | Reference voltage, Resolution | Quantization error analysis |
| Quantization Error | ±(Step Size / 2) | Step size | Sensor accuracy specs |
| Sampling Rate | fs ≥ 2 × fmax | Maximum signal frequency | Nyquist compliance |
| PWM Duty Cycle | (Desired Output / Vmax) × 100% | Target voltage, Supply voltage | LED dimming, Motor speed |
| Gamma Correction | Vout = Vin^γ (γ ≈ 2.2) | Linear input value | LED brightness perception |
| Voltage Divider | Vout = Vin × (R2 / (R1+R2)) | Input voltage, Resistor ratio | Level shifting 5V→3.3V |
| Source Impedance | Rtotal = R1 | R2 |
Key Insight: Every ADC calculation starts with matching Vref to the sensor’s output range to maximize resolution. The floor() function causes quantization error (±½ LSB), which sets the fundamental accuracy limit. For output, choose DAC (true analog) for audio/RF or PWM (cheaper, digital) for LED/motor control where fast switching is acceptable.
35.21 Continue to the Next Part
This section: Continue to the Next Part — Carry this evidence into ADC and DAC: Interactive Design Calculators, which begins with Interactive Calculators.
Carry this evidence into ADC and DAC: Interactive Design Calculators, which begins with Interactive Calculators.
Find help
3 reviewed answers.
Where should I start in a module?
Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.
Modules and pathsReviewed
What can I try when a project does not work?
Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.
When you are stuckReviewed
How do interactive examples work?
Use the interactive guide to check how examples and simulations work before changing your project.
Interactive examples guideReviewed
