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 pin | Connects to | Notes |
|---|---|---|
| 5V | TMP36 left pin (+Vs) | Flat face toward you, legs down |
| A0 | TMP36 middle pin (Vout) | |
| GND | TMP36 right pin (GND) |
The sketch
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.