PortDock

Analog input scaling — turning raw ADC counts into bar, °C and other units

Feed 4–20 mA or 0–10 V signals into an ADC through a shunt or divider and scale raw counts linearly to engineering units: count size, clipping, open loop.

Tools for this guidePlot Windows program · freeModbus Master Windows program · freeADC Resolution & Scaling Calculator web · no install4–20 mA Scaling Calculator web · no install

Pressure transmitters, temperature converters and similar sensors output their value as 4–20 mA or 0–10 V. An MCU ADC, a PLC analog input module or a panel meter turns that into a number, and «scaling» turns the number back into bar or °C. The steps are always the same: signal → ADC input voltage → ADC code → engineering value. Every step is linear, so two end points are all you need.

4–20 mA becomes 0.6–3.0 V across a 150 Ω shunt, divided by the 0.806 mV LSB of a 12-bit 3.3 V ADC gives codes 745–3724, then linear scaling to 0–10 bar
Reading a 4–20 mA, 0–10 bar pressure transmitter with a 150 Ω shunt and a 12-bit 3.3 V ADC. About 2979 codes are in use, not 4096.

1. Signal to ADC input voltage

A current signal becomes a voltage across one shunt resistor (V = I × R). A voltage signal such as 0–10 V is reduced with a divider when it exceeds the ADC reference. Either way, the point is to put the top of the signal a little below the reference.

Shunt4 mA20 mAReferenceResult
150 Ω0.6 V3.0 V3.3 VAbout 9 % headroom — the top code (4095) is about 22 mA
165 Ω0.66 V3.3 V3.3 V20 mA is exactly full scale — anything above clips
250 Ω1 V5 V5 V20 mA is exactly full scale — anything above clips

Without headroom, a reading just above 20 mA sticks at the top code and you cannot tell «exactly full» from «over range». For 0–10 V into a 3.3 V ADC, leave the same room with a ratio of 0.3 (10 V → 3.0 V). Pick standard divider resistors with the voltage divider calculator.

2. Voltage to code

1 LSB = V_REF ÷ 2^N                     (Microchip AN693)
code  = ⌊V_IN × 2^N ÷ V_REF⌋, max 2^N − 1     (ATmega328P §23.7, N bits)

12 bits, 3.3 V → 1 LSB = 0.806 mV
0.6 V → 744.7,  3.0 V → 3723.6      ← about 2979 codes in use

A 12-bit ADC does not use all 4096 steps here. Without the range below 4 mA (0–0.6 V) and above 20 mA (3.0–3.3 V) about 2979 codes remain, so for 0–10 bar one count is about 0.0034 bar — the real resolution of this circuit. Microchip's AN693 notes that even an ideal converter has up to ±½ LSB of quantization error, and real converters add offset and gain errors and non-linearity (DNL, INL): 1 LSB is the step you can resolve, not the accuracy.

3. Code to engineering value — a two-point line

value = low + (code − code_low) ÷ (code_high − code_low) × (high − low)

code 2234 → 0 + (2234 − 744.7) ÷ (3723.6 − 744.7) × 10 = 5.00 bar   (12 mA)
CodeSignalValue (0–10 bar)
00 mA−2.50 bar (open loop or no power)
7454.00 mA0.00 bar
14898.00 mA2.50 bar
223412.00 mA5.00 bar
297916.00 mA7.50 bar
372420.00 mA10.00 bar
409522.0 mA11.25 bar (top code)

4. Out of range and open loop

4–20 mA starts at 4 mA, not 0, so a reading far below the low end (near code 0 above) is not «0 bar» but an open loop or a transmitter supply problem. Showing values above the top as «out of range» separately is also good practice. Where faults begin (NAMUR NE 43 limits and so on) is summarized in the 4–20 mA scaling calculator.

5. Noise and the input filter

The ATmega328P datasheet (§23.6.1) says its ADC is optimized for sources of about 10 kΩ output impedance or less, and advises removing components above the Nyquist frequency (f_ADC/2) with a low-pass filter. An RC filter on the shunt voltage delays the response by τ = R × C, so choose it with the RC time constant calculator against the response you need. Averaging several readings in software is also common.

Values the device has already scaled

In PortDock

Published 2026-10-23