Voltage dividers and analog sensors
Objectives
Section titled “Objectives”By the end of this lesson you will:
- Compute the output voltage of a voltage divider from two resistor values
- Convert an ADC reading to a voltage from its resolution and reference voltage, and compare it against a multimeter
- Explain how the input resistance of an ADC (and of a meter) affects a voltage divider’s accuracy
Before you start
Section titled “Before you start”- You have completed the Voltage, current and resistance lesson, and can use Ohm’s law and series circuits
- For the lab: a breadboard, jumper wires, a 10 kΩ resistor, a 12 kΩ resistor, two 1 MΩ resistors, a multimeter, and a board
- The part reading a knob through the ADC uses the Developer Hub’s QWA309 example, which runs only on the TESAIoT Dev Kit. If you are using the Eva Kit, see the note in the lab.
See it work first
Section titled “See it work first”If you have a TESAIoT Dev Kit, open the QWA309 Potentiometer Monitor example on the Developer Hub and flash it to the board. The screen shows four cards, one per potentiometer (knob), each with a raw count, a voltage, and a percentage. Turn one knob all the way in both directions and notice two things.
- The raw count runs from about 0 to about 4095 — why this particular number?
- The maximum voltage the screen shows is about 1.8 V, not 3.3 V — why?
Per this example’s README, all four knobs are wired to pins P15.4 through P15.7 and read with a 12-bit SAR ADC, reference voltage 1.8 V. By the end of this lesson, you will be able to explain every number on that screen yourself.
Concepts
Section titled “Concepts”1. The voltage divider
Section titled “1. The voltage divider”Two resistors in series across a supply produce a midpoint voltage proportional to the supply voltage — this is called a voltage divider.
The same current flows through R1 and R2 (they are in series): I = V_in / (R1 + R2). So the voltage across R2 is I × R2.
V_out = V_in × R2 / (R1 + R2)Example: 3.3 V, R1 = 10 kΩ (top), R2 = 4.7 kΩ (bottom)
V_out = 3.3 × 4.7 / (10 + 4.7) = 3.3 × 0.3197 = 1.055 VWorking backwards: you want 1.8 V from 3.3 V. The ratio you need is 1.8 / 3.3 = 0.545. Choose R1 = 10 kΩ, and R2 = 12 kΩ gives exactly 3.3 × 12 / 22 = 1.800 V. We will actually wire this 10 kΩ / 12 kΩ pair in the lab.
A potentiometer (knob) is a resistor with a sliding middle pin (the wiper). Its two end pins sit across a supply, so the middle pin is a voltage divider whose ratio you can adjust. Turn it 30% of its travel, and the middle pin gives about 30% of the voltage across it. The knob’s total resistance value has no effect on the ratio, as long as nothing loads it by drawing current (that is section 3’s topic).
Many analogue sensors use exactly this principle — a thermistor (resistance changes with temperature), or an LDR (resistance changes with light). Put it in place of R1 or R2, and the midpoint voltage changes with whatever quantity you want to measure.
2. The ADC: from voltage to a number, and back
Section titled “2. The ADC: from voltage to a number, and back”An N-bit ADC (analog-to-digital converter) splits the range from 0 to a reference voltage (V_ref) into 2^N steps, giving a number from 0 to 2^N − 1.
- A 12-bit ADC has 2^12 = 4096 steps, so raw values fall in the range 0 to 4095
- The size of one step (1 LSB) = V_ref / 2^N
Example: a 12-bit ADC with V_ref = 1.8 V (the kind used to read a knob on the TESAIoT Dev Kit)
1 LSB = 1.8 V / 4096 = 0.000439 V ≈ 0.44 mVConverting a raw count back to a voltage:
V = raw × V_ref / 2^Nraw 2048 → 2048 × 1.8 / 4096 = 0.900 V (exactly half of the full range)raw 3000 → 3000 × 1.8 / 4096 = 1.318 VSome code divides by 4095 instead of 4096. The Pot Monitor example uses POT_ADC_FULL_SCALE = 4095 and computes in whole millivolts.
So raw 3000 gives 3000 × 1800 / 4095 = 1318 mV (rounded down). The two approaches differ by less than one LSB, far smaller than the resistor tolerances already present in the circuit.
What matters is knowing which one the code you are using has chosen.
Percentage does not need a reference voltage. Percentage = 100 × raw / full-scale is a pure ratio. Voltage, on the other hand, depends directly on V_ref. If the real V_ref differs from what the code assumes, the calculated voltage is off by that same proportion, while the percentage stays correct. The TESAIoT Dev Kit’s SDK notes this exact caveat in its CM33 example that reads a knob: the function that converts to volts “multiplies by a hard-coded 3.3 V,” not a measured real V_ref. This is exactly why we need to compare against a multimeter at least once.
3. When the voltage divider is loaded
Section titled “3. When the voltage divider is loaded”The formula in section 1 works when nothing draws current out of V_out — but in real life, something always does: the ADC pin, and the multimeter itself. Looking from the V_out pin, the voltage divider behaves like a supply V_th with an internal resistance R_th = R1 ∥ R2 (a Thévenin equivalent circuit).
The load you connect divides the voltage one more time:
V_out = V_th × R_load / (R_load + R_th)Example: 3.3 V divided by two 100 kΩ resistors gives 1.65 V unloaded, and R_th = 100 kΩ ∥ 100 kΩ = 50 kΩ.
| Load | V_out | Error from 1.65 V |
|---|---|---|
| 1 MΩ | 1.65 × 1 M / 1.05 M = 1.571 V | −4.8% |
| 10 MΩ (a typical multimeter) | 1.65 × 10 M / 10.05 M = 1.642 V | −0.5% |
A rule of thumb worth remembering: make the load’s resistance at least about 100 times R_th, and the error stays below about 1%.
A SAR ADC has one more thing to consider. While sampling, the ADC connects a sampling capacitor to the pin, and that capacitor must charge through R_th quickly enough before conversion happens. Suppose the internal capacitor is 5 pF (a value assumed for this calculation — check the chip’s datasheet for the real one), with R_th = 50 kΩ.
τ = R × C = 50 kΩ × 5 pF = 250 nsTo settle within half an LSB of 12 bits, you need about ln(2^13) ≈ 9 τ ≈ 2.25 µsIf the ADC’s sampling time is shorter than this, the reading comes out slightly low, and it shifts depending on the previous reading. There are three fixes: lower the resistor values (at the cost of wasted current — two 10 kΩ resistors at 3.3 V draw 165 µA continuously), lengthen the sampling time, or add a small capacitor at the ADC pin as a local charge reserve. For high accuracy, insert a voltage-follower op-amp in between.
Worked example
Section titled “Worked example”Problem: a sensor outputs 0 to 5 V, and we want to read it with a 12-bit ADC that accepts 0 to 1.8 V (V_ref = 1.8 V). Design a voltage divider, then convert the reading back to the sensor’s voltage.
Step 1: choose a ratio. 5 V must come down below 1.8 V, with some margin. Choose a ratio of 1/3, with R1 = 20 kΩ, R2 = 10 kΩ.
V_adc max = 5 × 10 / (20 + 10) = 1.667 V below 1.8 V, with about 7% headroomStep 2: check the side effects
Current the circuit draws from the 5 V sensor = 5 V / 30 kΩ = 0.167 mAR_th = 20 kΩ ∥ 10 kΩ = 6.67 kΩ a 10 MΩ load causes only about 6.67 k / 10 M ≈ 0.07% errorResolution on the sensor's side = 0.44 mV × 3 = 1.32 mV per stepIf the sensor can supply only very little current, 0.167 mA may be too much — check its datasheet. This is the trade-off between current and accuracy.
Step 3: convert back. A reading of raw = 3500.
V_adc = 3500 × 1.8 / 4096 = 1.538 VV_sensor = V_adc × (R1 + R2) / R2 = 1.538 × 3 = 4.614 VStep 4: compare against a meter. Measure the sensor’s output voltage with a multimeter. If it differs from 4.614 V by more than about 1%, suspect these three things in order: the resistors’ real values (measured in Ω mode, powered off), the real V_ref, and the ADC’s sampling time.
Practice
Section titled “Practice”- A 3.3 V supply, R1 = 4.7 kΩ (top), R2 = 10 kΩ (bottom). What is V_out?
- You want 1.2 V from 3.3 V, using R2 = 10 kΩ as the bottom resistor. What must R1 be? Using the nearest standard E24 value, what voltage do you actually get?
- A 12-bit ADC, V_ref = 1.8 V. (a) How many volts is raw 1024? (b) How many volts is the maximum raw value, 4095? Why does it not reach exactly 1.8 V?
- A 10-bit ADC, V_ref = 3.3 V. How many mV is one LSB, and roughly what raw value would 1.0 V give?
- A voltage divider of two 1 MΩ resistors from 3.3 V, measured with a meter whose input resistance is 10 MΩ — what would it read? Compare this against the two-100-kΩ example with a 1 MΩ load in section 3, and notice something.
- A 12-bit ADC reads raw 2867, and the code uses a full scale of 4095. What percentage is that?
Solution
Section titled “Solution”- V_out = 3.3 × 10 / 14.7 = 2.245 V ≈ 2.24 V
- R1 = R2 × (V_in / V_out − 1) = 10 kΩ × (3.3 / 1.2 − 1) = 10 kΩ × 1.75 = 17.5 kΩ. The nearest E24 value is 18 kΩ, giving 3.3 × 10 / 28 = 1.179 V.
- (a) 1024 × 1.8 / 4096 = 0.450 V (b) 4095 × 1.8 / 4096 = 1.7996 V. The maximum is one LSB (0.44 mV) below V_ref, because the count starts at 0.
- 1 LSB = 3.3 V / 1024 = 3.22 mV, and 1.0 V × 1024 / 3.3 = 310.3, so raw is about 310.
- R_th = 500 kΩ, giving 1.65 × 10 M / 10.5 M = 1.571 V — exactly the same as the section 3 example, because the ratio R_load / R_th is 20 in both cases. The error depends on this ratio, not on the absolute values.
- 100 × 2867 / 4095 = 70.0%
Check your understanding
Section titled “Check your understanding”Answer at least 4 of the 5 questions in quiz.yaml correctly. Questions 4 and 5 test loading effects — if you get them wrong, go back and reread section 3.
Part A: a voltage divider on a breadboard (any board)
- With USB unplugged, connect R1 = 10 kΩ from 3V3 to point M, and R2 = 12 kΩ from point M to GND.
- Guess: write down the voltage you expect at point M (1.80 V, if 3V3 is exactly 3.30 V).
- Plug in USB. Measure the real 3V3 voltage and the voltage at point M. Recalculate using the real 3V3 voltage you measured, and compare.
- Unplug USB, and change both resistors to 1 MΩ. Guess first what you will measure, then plug in USB and measure point M.
- Investigate: the value you measured in step 4 is probably noticeably below half of 3V3. Use the formula in section 3 to work backwards and find your meter’s input resistance.
R_meter = R_th × V_measured / (V_th − V_measured) where V_th = 3V3 / 2 and R_th = 500 kΩExample: measured 1.571 V from a V_th of 1.650 V → R_meter = 500 k × 1.571 / 0.079 ≈ 9.9 MΩResistor tolerance (±5%) can shift the result by several more percent, so it is worth measuring the real value of both 1 MΩ resistors first (before wiring them in, and not while holding the leads with your fingers), then using V_th = 3V3 × R2 / (R1 + R2) and R_th = R1 ∥ R2 from your measured values. Compare the result against your meter’s manual (most are around 10 MΩ in DC voltage mode). If they are close, you have just measured the “measuring instrument” using itself.
Part B: reading a knob through the ADC (TESAIoT Dev Kit)
- Run the QWA309 Potentiometer Monitor example, and turn one knob to four positions: roughly 1/4, 1/2, 3/4, and all the way.
- At each position, record the raw value and the mV value the screen shows, then calculate it yourself with raw × 1800 / 4095. Your number must match the screen. If it does not, find what the code does differently from what you assumed.
- If you can reach the knob’s middle pin (for example, from a pin underneath the board), measure the middle pin’s voltage relative to GND with a multimeter, and compare it against what the ADC reports. If you cannot reach it, skip this step — never probe a chip’s pins on a powered board.
- If you want to see the value change over time as a graph, try the QWA309 4-Channel ADC Scope example, which reads all four knobs every 60 ms and plots them as a line graph.
| Position | raw | mV on screen | mV calculated by hand | Meter (if measured) |
|---|---|---|---|---|
| about 1/4 | ||||
| about 1/2 | ||||
| about 3/4 | ||||
| all the way |
If you are using the Eva Kit: the SDK has a C example for CM33 that reads a knob on the Eva Kit as a 16-bit raw value (0 to 65535), a percentage, and a voltage, computed by multiplying against an assumed 3.3 V. Compare the voltage the code reports against a multimeter, and explain the difference using the V_ref discussion in section 2.
Going further
Section titled “Going further”The next lesson, Basic components, applies Ohm’s law to an LED, looks at what capacitors and diodes actually do, and chooses a transistor for when a microcontroller pin cannot supply enough current. If you want to go on to read a knob from C code on the TESAIoT Dev Kit, see the lesson Analog and ADC in the TESAIoT Firmware Stack course.
Reflect
Section titled “Reflect”Next time you see a voltage number on some device’s screen, what will you ask yourself before trusting that number?
References
Section titled “References”- AIoT in Action: examples/s05/05_adc_counts_to_volts.py
- AIoT in Action: examples/s05/03_pot_setpoint_deadband.py
- SDK: cm33/io/03_read_potentiometers.c (raw, percent and volts)
- Lessons In Electric Circuits by Tony R. Kuphaldt (open book)
- README of QWA309 Potentiometer Monitor (Developer Hub, commit 372d0d8)
- Voltage divider (Wikipedia)
Review questions
Answer on your own first, then open the answer.
-
A divider from 3.3 V has R1 = 10 kΩ on top and R2 = 20 kΩ at the bottom. What is the output? (Objective 1)
- 1.1 V
- 2.2 V
- 1.65 V
- 3.3 V
Show answer
Answer: B. 2.2 V
V_out = 3.3 × 20 / (10 + 20) = 2.2 V แรงดันขาออกคือแรงดันคร่อมตัวล่าง ตัวล่างใหญ่กว่าจึงได้แรงดันมากกว่าครึ่ง ถ้าได้ 1.1 V แปลว่าสลับตัวบนกับตัวล่าง
-
A 12-bit ADC with a 1.8 V reference reads 2048. About what voltage is on the pin? (Objective 2)
- 0.90 V
- 1.65 V
- 2.048 V
- 0.45 V
Show answer
Answer: A. 0.90 V
V = 2048 × 1.8 / 4096 = 0.90 V คือครึ่งหนึ่งของช่วง 0 ถึง 1.8 V ค่าดิบเป็นจำนวนขั้น ไม่ใช่ mV
-
Code converts raw counts to volts with a hard-coded 3.3 V, but the real reference is 3.2 V. Which is true? (Objective 2)
- ทั้งโวลต์และเปอร์เซ็นต์ผิดเท่ากัน
- โวลต์ที่รายงานสูงเกินจริงราว 3% แต่เปอร์เซ็นต์ยังถูก
- ทั้งโวลต์และเปอร์เซ็นต์ยังถูก เพราะ ADC ชดเชยเอง
- เปอร์เซ็นต์ผิด แต่โวลต์ถูก
Show answer
Answer: B. โวลต์ที่รายงานสูงเกินจริงราว 3% แต่เปอร์เซ็นต์ยังถูก
เปอร์เซ็นต์คืออัตราส่วนของค่าเต็มสเกล ไม่ต้องใช้แรงดันอ้างอิง ส่วนโวลต์คูณกับ 3.3 แทน 3.2 จึงสูงเกิน 3.3 / 3.2 = 1.031 เท่า วิธีจับความผิดแบบนี้คือเทียบกับมัลติมิเตอร์
-
A divider of two 100 kΩ resistors from 3.3 V drives a 1 MΩ load. About what is the output? (Objective 3)
- 1.65 V
- 1.57 V
- 1.50 V
- 0.30 V
Show answer
Answer: B. 1.57 V
R_th = 50 kΩ ได้ 1.65 × 1 M / (1 M + 50 k) = 1.571 V ต่ำกว่าค่าไม่มีโหลดราว 4.8% เพราะโหลดดึงกระแสออกจากจุดกลาง
-
An ADC reads low on a high-resistance divider. Which of these help? (choose all that apply) (Objective 3)
- ลดค่าตัวต้านทานของวงจรแบ่งแรงดันลง
- ใส่ op-amp แบบ voltage follower คั่นระหว่างวงจรแบ่งแรงดันกับ ADC
- เพิ่มค่าตัวต้านทานทั้งสองตัวเป็นสิบเท่า
- ตั้งเวลาสุ่มตัวอย่าง (acquisition time) ของ ADC ให้ยาวขึ้น
Show answer
Answer: A. ลดค่าตัวต้านทานของวงจรแบ่งแรงดันลง · B. ใส่ op-amp แบบ voltage follower คั่นระหว่างวงจรแบ่งแรงดันกับ ADC · D. ตั้งเวลาสุ่มตัวอย่าง (acquisition time) ของ ADC ให้ยาวขึ้น
ทุกข้อที่ถูกลด R_th ที่ ADC มองเห็น หรือให้เวลาตัวเก็บประจุสำหรับสุ่มประจุนานขึ้น การเพิ่มค่าตัวต้านทานทำให้ R_th สูงขึ้นและอาการหนักขึ้น
Cite this lesson
If you teach from this lesson or reuse it in slides or documents, credit it with the text below. If you changed it, add (adapted) after the title.
"Voltage dividers and analog sensors" from TESA Open Knowledge by the Thai Embedded Systems Association (TESA), https://github.com/tesaiot/tesa-qualification-program, licensed under CC BY-NC 4.0
Thai attribution: "วงจรแบ่งแรงดันและเซนเซอร์แบบอนาล็อก" จาก TESA Open Knowledge โดยสมาคมสมองกลฝังตัวไทย (Thai Embedded Systems Association: TESA) https://github.com/tesaiot/tesa-qualification-program สัญญาอนุญาต CC BY-NC 4.0
TESA Open Knowledge · © 2026 สมาคมสมองกลฝังตัวไทย (TESA) · CC BY-NC 4.0
Content is licensed CC BY-NC 4.0. Reuse it non-commercially and credit the Thai Embedded Systems Association (TESA) every time. · How to cite TESA