5.00 VTMP36ATmega328PADC10-bit1 step 4.88 mV1.1 V1analogReference(DEFAULT);2int raw = analogRead(A0);3long mV = raw * 5000L / 1024;4float t = (mV - 500) / 10.0;rawmVt °C750 mV1100 mV5 V1.1 V4.8 V15374724.7698340874924.91023109859.816078128.1
740745750755760735740745750755760input (mV)read back (mV)READING NEAR 750 mV5 V ref: 4.88 mV1.1 V ref: 1.07 mV050010001500200002565127681023input (mV)rawRAW CODE vs INPUT5 V ref1.1 V ref
Back: the board (TMP36 sensor, 5 V rail, the chip with its ADC and 1.1 V reference)Front: the firmware card and the raw, mV and t result cellsTokens: voltages, reference voltages and numbers moving through the codePlots: the reading in stairs near 750 mV, and the raw code over the whole input rangeA TMP36 at 25 °C gives 750 mV on A0 of an Arduino Uno R3. With the 5 V reference the 10-bit ADC returns 153 (steps of 4.88 mV), which scales back to 747 mV and 24.7 °C. With the internal 1.1 V reference it returns 698 (steps of 1.07 mV): 749 mV and 24.9 °C, but anything from about 1.1 V up reads 1023. The plots are computed from the datasheet rule raw = Vin × 1024 / VREF.

Read and scale

  1. An ADC cannot measure volts on its own. It compares the pin with a reference voltage, VREF, and reports what fraction of VREF it sees, as a whole number from 0 to 1023. On an Uno, VREF is the 5 V rail by default.

Change the reference

Range and accuracy

What happens

;; step 1/9 · measure
ADC   analog-to-digital converter
VREF  the reference voltage: the length of the ruler
      Uno default: AVCC = 5 V
pin A0 sees 750 mV from the TMP36 (25 °C)
answer: a whole number 0 .. 1023  (10 bits)

The ATmega328P datasheet gives the result as ADC = VIN × 1024 / VREF, where 0 is ground and 1023 (0x3FF) is VREF minus one step. So code ÷ 1024, not ÷ 1023, turns a reading back into a fraction of VREF. One step is not the whole error. The datasheet lists ±2 LSB absolute accuracy for the ADC itself, and the TMP36 is only accurate to about ±2 °C. A fine step shows small changes; it does not make the sensor more correct.