Learning Goals 5 min
- Wire a TMP36 — a three-pin, linear, analog temperature sensor — using no partner resistor and no library.
- Derive the conversion formula
°C = (mV − 500) / 10from the TMP36 datasheet, and explain why it's much simpler than the thermistor maths in L02-11. - Compare a TMP36 reading against your L02-11 thermistor reading and discuss which one you'd trust for a real project — and why.
Warm-Up 10 min
Cluster B ended with the thermistor — a tiny resistor whose value changes with temperature. It works, but you needed a partner resistor, a divider equation and a logarithm. The TMP36 is a different beast: it's an integrated circuit (an "IC" — a tiny black chip with three legs) that already contains the divider, the amplifier and the linearisation inside. You give it 5 V and ground, and the middle pin spits out a voltage that's a clean linear function of temperature.
Quick check
The TMP36 datasheet says: 10 mV per °C, with a 500 mV offset at 0 °C. So at 25 °C, what voltage do you expect on the output pin?
Reveal
500 mV + 25 × 10 mV = 750 mV. That's 0.75 V on the output pin at a comfortable room temperature. At 0 °C you'd see 500 mV; at 50 °C you'd see 1.00 V. Linear, predictable, no logs.
New Concept · A sensor that does the maths for you 20 min
What the TMP36 actually is
The TMP36 is a small analog IC in a TO-92 package — looks identical to a small transistor. Three pins, viewed from the flat face, left to right:
| Pin (flat face) | Name | Connect to |
|---|---|---|
| Left | +VS | +5 V |
| Middle | VOUT | An analog pin (e.g. A0) |
| Right | GND | GND |
Getting the orientation wrong is the #1 mistake. Plugging the TMP36 in backwards puts +5 V across GND and VOUT, which heats the chip up rapidly and can destroy it. If it ever gets too hot to touch, unplug immediately and check the orientation.
From ADC reading to millivolts
The Arduino UNO's ADC reads 0–5 V as 0–1023. To convert a raw reading back into a voltage:
float volts = raw * (5.0 / 1023.0); // volts
float mV = volts * 1000.0; // millivoltsOr more directly: mV = raw * 5000.0 / 1023.0. Use whichever form reads more naturally.
From millivolts to °C
The TMP36 datasheet gives the linear formula:
°C = (mV - 500) / 10Sanity check: 750 mV − 500 = 250, divided by 10 = 25 °C. Matches the warm-up. The whole pipeline:
int raw = analogRead(A0);
float mV = raw * (5000.0 / 1023.0);
float tC = (mV - 500.0) / 10.0;Three lines. No partner resistor. No β constant. No logarithm. Compare to the thermistor:
int raw = analogRead(A0);
float R = 10000.0 * (1023.0 / raw - 1.0);
float tK = 1.0 / (1.0/298.15 + (1.0/3950.0) * log(R / 10000.0));
float tC = tK - 273.15;Same answer, half the code. That's what you pay extra cents for.
Trade-offs vs the thermistor
| Thermistor | TMP36 | |
|---|---|---|
| Price | Very cheap | About 8× the price |
| Pins | 2 + partner resistor | 3, no extras |
| Maths | β-equation, log() | linear, subtract + divide |
| Range | −50 to +125 °C | −40 to +125 °C |
| Accuracy out of the box | ±2 °C (varies by batch) | ±2 °C (datasheet) |
| Drift over time | Some | Very low — factory calibrated |
| Self-heating | Noticeable | Negligible (very low current) |
For a one-off classroom build, either works. For a product, the TMP36's factory calibration is worth the price.
Worked Example · A 3-wire thermometer 20 min
Step 1 — wiring
On the breadboard what you build
On paper what engineers draw
- Plug the TMP36 into the breadboard with the flat face toward you.
- Left pin → +5 V rail.
- Middle pin → A0.
- Right pin → GND rail.
That's it. Three wires. No resistor, no divider, no library, no fuss.
Step 2 — the sketch
Save as tmp36-read.ino:
// L02-13: TMP36 → °C (linear, no library)
const int TMP = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(TMP);
float mV = raw * (5000.0 / 1023.0);
float tC = (mV - 500.0) / 10.0;
Serial.print("raw: ");
Serial.print(raw);
Serial.print(" mV: ");
Serial.print(mV, 0);
Serial.print(" T: ");
Serial.print(tC, 1);
Serial.println(" °C");
delay(500);
}Step 3 — upload and read
Open Serial Monitor at 9600. With the TMP36 sitting in still room air:
raw: 154 mV: 753 T: 25.3 °C raw: 154 mV: 753 T: 25.3 °C raw: 155 mV: 758 T: 25.8 °C
If the temperature reads −40 °C (~100 mV), you've got the chip in backwards — unplug, check orientation, try again. If it reads 100+ °C and is hot to touch, definitely backwards — let it cool before re-trying.
Step 4 — finger test
Pinch the TMP36 between thumb and finger. Over 30–60 seconds the temperature climbs to ~30–33 °C. Release — it falls back over the next minute. Notice how much faster it responds than the thermistor: the TO-92 package has less thermal mass than a glass-bead thermistor.
Step 5 — accuracy check
If you have a thermistor sketch from L02-11 still wired, run them side-by-side (the thermistor on A0, TMP36 on A1). The two readings should agree within 1–2 °C across the day. If one is consistently off, trust the TMP36 — it's factory-calibrated. The thermistor's β is approximate.
Basic 7 min
Goal: Print the temperature in °F alongside °C. Useful when comparing your sensor to a US-style weather website.
Challenge 1 7 min
Goal: Apply the L02-08 smoothing (running average of N = 10) to the raw TMP36 reading. The °C output should stop wobbling in the last decimal place.
Challenge 2 6 min
Goal: Use the Arduino's internal 1.1 V reference instead of the default 5 V reference. This makes the ADC 5× more sensitive — but only useful up to ~60 °C with a TMP36. Look up analogReference(INTERNAL) in the Arduino docs and adapt the conversion accordingly.
Challenge 3 · TMP36 vs thermistor — side by side 15 min
Wire both a TMP36 (on A0) and your L02-11 thermistor divider (on A1) on the same breadboard. Write one sketch that prints both temperatures, plus the difference, every second:
TMP36: 26.4 °C Thermistor: 26.7 °C Δ: +0.3 °C TMP36: 26.4 °C Thermistor: 26.7 °C Δ: +0.3 °C TMP36: 26.5 °C Thermistor: 26.8 °C Δ: +0.3 °C
Now experiment:
- Cup both sensors in your hand for 60 seconds. Which one rises faster? Which one settles higher?
- Blow on both sensors. Same questions.
- Put both sensors briefly in front of a fridge door when you open it (just for 5 s, don't freeze the Arduino). Which one drops faster?
Measure it: in the hand-cupping test, count how many seconds each sensor takes to rise by 2 °C. Write both times as a comment at the top of your sketch.
It works if both temperatures and the difference print every second, and your comment gives a rise time for each sensor.
Recap 5 min
The TMP36 is an integrated analog temperature sensor in a TO-92 case. Connect +VS to 5 V, GND to GND, and VOUT straight to an analog pin. The output is a linear 10 mV per °C with a 500 mV offset at 0 °C, so the conversion is just °C = (mV − 500) / 10. No partner resistor, no β constant, no logarithm — the chip does all of that internally. Compared to the thermistor in L02-11 it's pricier but tidier, faster to respond and factory-calibrated. The unforgiving part is orientation: get the three pins backwards and the chip cooks itself.
- TMP36
- A 3-pin analog temperature sensor IC in a TO-92 package. 10 mV / °C, 500 mV offset at 0 °C, range −40 to +125 °C.
- Linear sensor
- One whose output rises by a constant amount per unit of input. Easy maths:
output = slope × input + offset. - TO-92
- The little semi-cylinder plastic case used for many small transistors and the TMP36. Flat face is the "front".
- Factory calibration
- The sensor was tested and trimmed at the factory so it matches its datasheet without per-unit tweaks.
- Self-heating
- When current flows through a sensor it dissipates a little power as heat, which can change its own reading. Negligible on the TMP36.
- Reference voltage
- The voltage at the top of the ADC's range. UNO defaults to 5 V; can be switched to an internal 1.1 V with
analogReference(INTERNAL)for higher resolution at the cost of range.
Extra Mission 5 min
Part 1 — Pick the right sensor for a product
Pick a product that needs a temperature reading — a chef's probe, a bath thermometer, an egg incubator, a classroom display. On paper, design it and choose the TMP36 or the thermistor.
Your design must include:
- A name and a one-sentence job for the product.
- Whether it needs a fast or a slow reaction. Use your Challenge 3 rise times to pick the sensor.
- The temperature range it must handle, and whether your sensor covers it.
- The wiring for the chosen sensor and any LEDs.
Part 2 — Make it
Build it with your chosen sensor on A0. Print °C every second. Light an LED when the reading leaves the safe range you chose.
Bring back next class: the uploaded sketch, a Serial Monitor screenshot and a photo of the circuit.