Bench NotesUno handbook

Reading Temperature with a TMP36

Convert the TMP36's analog output to degrees Celsius, with averaging to steady the reading.

BeginnerTMP36Serial

Overview

The TMP36 outputs 500 mV at 0 °C plus 10 mV per degree. At 25 °C it gives 750 mV. Read it on an analog pin, convert to millivolts, subtract 500 and divide by 10.

You will need

  • Arduino Uno R3
  • TMP36 temperature sensor (TO-92 package)
  • Optional 0.1 µF capacitor across +Vs and GND

Wiring

Uno pinConnects toNotes
5VTMP36 left pin (+Vs)Flat face toward you, legs down
A0TMP36 middle pin (Vout)
GNDTMP36 right pin (GND)
Wiring for Reading Temperature with a TMP36Arduino Uno 5V to TMP36 (flat face forward) +Vs (left); Arduino Uno A0 to TMP36 (flat face forward) Vout (middle); Arduino Uno GND to TMP36 (flat face forward) GND (right).Connections (each line is one wire)Arduino UnoTMP36 (flat face forward)5V+Vs (left)A0Vout (middle)GNDGND (right)
Original wiring diagram. Each line is one jumper wire; boxes on a line are series resistors.

The sketch

tmp36_thermometer.ino
const int SENSOR_PIN = A0;
const int SAMPLES = 10;

void setup() {
  Serial.begin(9600);
}

void loop() {
  long total = 0;
  for (int i = 0; i < SAMPLES; i++) {
    total += analogRead(SENSOR_PIN);
    delay(5);
  }
  float reading = total / (float)SAMPLES;
  float millivolts = reading * (5000.0 / 1024.0);
  float celsius = (millivolts - 500.0) / 10.0;

  Serial.print(celsius, 1);
  Serial.println(" C");
  delay(1000);
}

How the code works

Averaging ten readings smooths the ±1 count noise, which is half a degree on its own. The result depends on the 5 V supply being accurate; on USB it is often 4.8–5.1 V, which shifts the reading by a few degrees. For better accuracy, measure the 5V pin with a multimeter and use that value in place of 5000.

What you should observe

  • Room temperature appears once per second, for example 22.4 C.
  • Pinch the sensor between your fingers: the value climbs within a few seconds.
  • If the sensor gets hot to the touch, unplug at once: it is wired backwards.