Learn Arduino

Lesson 11 of 16 · 25 min

Arduino Temperature Sensor: TMP36 to Degrees

The TMP36 outputs 750 mV at 25 °C and changes by 10 mV per °C, so on a 5 V Arduino the temperature in °C is (analogRead(A0) × 5.0 / 1023 − 0.5) × 100.

This lesson also runs on an interactive 3D board: wire it, press Run and watch the circuit respond.

Open the 3D lesson

The TMP36 is the easiest analog temperature sensor to live with: three legs, no calibration, and a straight line from −40 °C to 125 °C. Its output is 0.5 V at 0 °C plus 10 mV for every degree above that.

Because the Uno turns 0–5 V into 0–1023, each ADC step is about 4.9 mV — roughly half a degree. That is plenty for a thermostat, a greenhouse monitor or a fan controller, and the same code works on a breadboard or inside a project box.

What you need

Everything below is in a standard Arduino starter kit.
PartQtyNotes
Arduino Uno R31A0 measures, pin 6 drives the fan
TMP36 sensor1Flat side facing you: 5 V, A0, GND
TIP120 + 1 kΩ1Only if you switch a real fan
5 V fan1A 40 mm fan draws about 100 mA
Breadboard + jumpers1

How to wire it

TMP36 left leg (Vs) → 5 V, middle leg (Vout) → A0, right leg → GND. Keep the sensor away from the regulator and the USB chip: they warm the board by several degrees, so measure air, not the PCB.

Pin-by-pin wiring for this lesson.
PinConnects toWhat it does
5VTMP36 Vs (left)Power for the sensor.
A0TMP36 Vout (middle)0.5 V plus 10 mV per °C.
GNDTMP36 GND (right)Ground.
~D61 kΩ → BaseSwitches the fan through the transistor.
Wiring map for Arduino Temperature Sensor: 5V to TMP36 Vs (left), A0 to TMP36 Vout (middle), GND to TMP36 GND (right), ~D6 to 1 kΩ → Base.
Every connection this lesson needs, drawn from the pin table above.

Reading an Arduino temperature sensor accurately

The TMP36 is a straight line: 0.5 V at 0 °C plus 10 mV for each degree, from −40 °C to 125 °C. The ADC turns that into a number, and one step of a 10-bit converter is about 4.9 mV, so the raw resolution is roughly half a degree before you average anything.

Accuracy is a different question from resolution. The part is specified at ±2 °C over its range and ±0.5 °C at 25 °C, so no amount of averaging turns it into a lab thermometer. Placement matters more than maths: sit it beside the board's regulator and you will be measuring the regulator, several degrees above the room.

From TMP36 readings to a thermostat

A thermostat is a threshold with hysteresis. Fan on above 28 °C, off below 26 °C — the gap stops it hunting on and off around a single number, the same problem the night light had in lesson 6.

Once the fan is on a PWM pin, the same reading can set its speed instead of just switching it: map 26–34 °C onto 80–255 and the noise rises with the heat. If you need better than ±2 °C, a DS18B20 gives digital readings over one wire and an SHT31 adds humidity on the same I2C bus as the OLED in lesson 14.

The sketch

heat.ino
const int SENSOR = A0;  // TMP36 Vout
const int FAN = 6;      // PWM through a transistor
const float LIMIT = 28.0;

void setup() {
  Serial.begin(9600);
  pinMode(FAN, OUTPUT);
}

void loop() {
  int raw = analogRead(SENSOR);
  float volts = raw * 5.0 / 1023.0;        // 0-5 V
  float tempC = (volts - 0.5) * 100.0;     // 10 mV per degree

  Serial.print(tempC, 1);
  Serial.println(" C");

  // above the limit: fan full on, below: off
  analogWrite(FAN, tempC > LIMIT ? 255 : 0);
  delay(200);
}

What the code does

  1. raw × 5.0 / 1023.0 turns the 0–1023 reading back into volts; the .0 matters, otherwise the maths stays integer.
  2. (volts − 0.5) × 100 converts the offset and the 10 mV per degree slope into °C in one step.
  3. The fan switches on through the transistor exactly as in the motor lesson — a pin cannot power a fan.
  4. delay(200) is a comfortable sample rate; the sensor settles long before that.

Specifications

Typical values for the parts used here.
ItemValue
SensorTMP36, −40 to 125 °C
Output10 mV/°C, 750 mV at 25 °C
Accuracy±2 °C
Fan5 V DC, switched by a TIP120
Readingevery 200 ms

Common mistakes

Sources

The figures in this lesson come from these documents. Every value in the tables above can be checked against them.

Frequently asked questions

How accurate is the TMP36?

±2 °C over its range and ±0.5 °C at 25 °C, which is fine for a thermostat or a data logger but not for anything that needs lab accuracy. For that, use a DS18B20 or an SHT31.

What is the difference between TMP36 and LM35?

They look identical and are wired differently: the LM35 outputs 0 V at 0 °C and 10 mV/°C, so no offset; the TMP36 starts at 0.5 V so it can also read below zero. Check the part number before copying code.

Why does my temperature reading jump around?

ADC noise of one or two counts is normal. Average ten readings, add a 100 nF capacitor from Vout to ground, and keep the sensor leads short.

Can I read temperature without a sensor?

The ATmega328P has an internal bandgap temperature sensor, but it is uncalibrated and only good to a few degrees — useful for detecting overheating, not for measuring a room.

Want to see this circuit before you own the parts? The Arduino simulator draws this exact pin table on a 3D Uno R3: click any jumper to see what it carries, press Run and read the serial monitor.

Open the Arduino simulator

Published 12 November 2026 · last updated 17 November 2026 · written and tested by Nick Hu.