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 | ~RM 0.50 | ~RM 4.00 |
| 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
- 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.
Try It Yourself 20 min
Goal: Print the temperature in °F alongside °C. Useful when comparing your sensor to a US-style weather website.
Hint
float tF = tC * 9.0 / 5.0 + 32.0;
Serial.print(tC, 1); Serial.print(" °C ");
Serial.print(tF, 1); Serial.println(" °F");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.
Hint
const int N = 10;
int samples[N];
int idx = 0;
long total = 0;
int smoothedRaw() {
total -= samples[idx];
samples[idx] = analogRead(TMP);
total += samples[idx];
idx = (idx + 1) % N;
return total / N;
}Then call smoothedRaw() instead of analogRead(TMP) in loop(). Don't forget to seed the array in setup() so the first few readings aren't artificially low.
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.
Hint
With analogReference(INTERNAL) the ADC now reads 0–1.1 V as 0–1023. The new mV conversion is mV = raw * 1100.0 / 1023.0. The °C formula is unchanged. You get roughly 1 mV resolution (= 0.1 °C) instead of 4.9 mV (0.49 °C). The downside: any temperature that would push VOUT above 1.1 V (i.e. above ~60 °C) will saturate the ADC.
Mini-Challenge · 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?
Reflection prompt: Based on the experiments, which sensor would you choose if you wanted a fast, reactive temperature display (e.g. a chef's thermometer)? Which would you choose for a slow, accurate one (e.g. an incubator)?
Reveal one valid sketch
// L02-13 challenge: TMP36 + thermistor side by side
const int TMP = A0;
const int THERM = A1;
const float R_FIXED = 10000.0;
const float R0 = 10000.0;
const float T0_K = 298.15;
const float BETA = 3950.0;
float readTmp36() {
int raw = analogRead(TMP);
float mV = raw * (5000.0 / 1023.0);
return (mV - 500.0) / 10.0;
}
float readThermistor() {
int raw = analogRead(THERM);
float R = R_FIXED * (1023.0 / raw - 1.0);
float tK = 1.0 / (1.0/T0_K + (1.0/BETA) * log(R / R0));
return tK - 273.15;
}
void setup() {
Serial.begin(9600);
}
void loop() {
float a = readTmp36();
float b = readThermistor();
float d = b - a;
Serial.print("TMP36: "); Serial.print(a, 1);
Serial.print(" °C Thermistor: "); Serial.print(b, 1);
Serial.print(" °C "); Serial.print(d >= 0 ? "Δ: +" : "Δ: ");
Serial.print(d, 1); Serial.println(" °C");
delay(1000);
}Two helper functions keep the main loop clean — and the same shape will appear in every future multi-sensor sketch. Pattern: one helper per sensor, one line per print.
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.
Homework 5 min
Sensor showdown. Take three temperature readings on each of your two sensors (TMP36 + thermistor):
- Sitting on your desk in still air.
- Held tight in your fist for 60 seconds.
- Held in front of a fan or open window for 30 seconds.
Record the results in a 3 × 2 table. For each pair, write the difference (TMP36 − thermistor). Then answer:
- Were the differences consistent (always about the same), or did they vary by condition?
- Which sensor reacted faster? How do you know?
- If you could only buy one for a kitchen-thermometer project, which would you pick — and why?
Bring back next class:
- Your 3 × 2 comparison table with calculated differences.
- Your three written answers.
- Your
hw-l02-13.inosketch — tomorrow we'll add a humidity sensor next to it.