Warm-hands meter on an Arduino Uno
A TMP36 on A0 and three LEDs: hold the sensor and the LEDs light one by one as it warms two, four and six degrees over the room. The whole build, an Arduino Uno and 7 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
Build it as the Starter Projects Kit: the parts in numbered bags and a booklet that checks every step. Retails for about $48, free on Mokxi.
What you'll learn
- Reading an analog temperature sensor
- Converting a reading to volts and then to degrees
- Comparing against a baseline
- Lighting LEDs as a bar of levels
- Calibrating a constant to your room
- Difficulty: Beginner
- Time: About 15 minutes
- Board: Arduino Uno R3
- Parts: 9
How it works
The TMP36 outputs 0.5 V at 0 C and 10 mV more for each degree. The Uno reads it on A0, turns the reading into volts and then into degrees Celsius, and prints all three.
The sketch compares the temperature with a room baseline of 22 C. Squeeze the sensor and it warms. At 2 degrees over, one LED lights, at 4 two, at 6 all three. It updates four times a second.
Parts list
9 parts, plus the jumper wires. They retail for about $34; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Full-size breadboard
- 1 × Temperature sensor, TMP36In Starter Projects Kit.
- 3 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 3 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Kits that can build it
These 3 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Temperature sensor, TMP36 pin GND | Arduino Uno R3 pin GND |
| LED, red (1) pin C | Arduino Uno R3 pin GND |
| LED, red (2) pin C | Arduino Uno R3 pin GND |
| LED, red (3) pin C | Arduino Uno R3 pin GND |
| Resistor, 220 Ω (3) pin 1 | Arduino Uno R3 pin 4 |
| Resistor, 220 Ω (2) pin 1 | Arduino Uno R3 pin 3 |
| Resistor, 220 Ω (1) pin 1 | Arduino Uno R3 pin 2 |
| Temperature sensor, TMP36 pin VS | Arduino Uno R3 pin 5V |
| Temperature sensor, TMP36 pin VOUT | Arduino Uno R3 pin A0 |
| LED, red (1) pin A | Resistor, 220 Ω (1) pin 2 |
| LED, red (2) pin A | Resistor, 220 Ω (2) pin 2 |
| LED, red (3) pin A | Resistor, 220 Ω (3) pin 2 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Warm-hands meter: a TMP36 temperature sensor and three LEDs that light one
// by one as the sensor warms up.
//
// TMP36 left leg (flat side toward you) -> 5V, middle -> A0, right -> GND
// pin 2, 3, 4 the three LEDs, each through 220 ohm to GND
//
// The TMP36 gives 0.5 V at 0 C and 10 mV more for every degree, so
// volts = reading * 5.0 / 1024
// celsius = (volts - 0.5) * 100
//
// The room is the baseline: 22 C here. Set BASELINE to what the serial
// monitor reads in your room before you touch the sensor. Then squeeze the
// sensor between your fingers and it climbs toward skin temperature: two
// degrees over the baseline lights the first LED, four the second, six the
// third.
const int SENSOR = A0;
const float BASELINE = 22.0; // the room: change it to what yours reads
const int LEDS[3] = {2, 3, 4};
void setup() {
for (int i = 0; i < 3; i++) pinMode(LEDS[i], OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: warm-hands meter");
}
void loop() {
int reading = analogRead(SENSOR);
float volts = reading * 5.0 / 1024.0;
float celsius = (volts - 0.5) * 100.0;
Serial.print("reading ");
Serial.print(reading);
Serial.print(", volts ");
Serial.print(volts, 2);
Serial.print(", degrees C ");
Serial.println(celsius, 1);
int lit = 0;
if (celsius >= BASELINE + 2) lit = 1;
if (celsius >= BASELINE + 4) lit = 2;
if (celsius >= BASELINE + 6) lit = 3;
for (int i = 0; i < 3; i++) digitalWrite(LEDS[i], i < lit ? HIGH : LOW);
delay(250);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Makes the three LED pins outputs by looping over the LEDS array. Then it starts the serial port and prints a hello line.
void setup() {
for (int i = 0; i < 3; i++) pinMode(LEDS[i], OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: warm-hands meter");
}loop sketch.ino
Reads A0, converts it with reading * 5.0 / 1024.0 and then (volts - 0.5) * 100.0 to get celsius, and prints the numbers. It sets lit to 1, 2 or 3 as the temperature passes BASELINE plus 2, 4 and 6, then turns on that many LEDs.
void loop() {
int reading = analogRead(SENSOR);
float volts = reading * 5.0 / 1024.0;
float celsius = (volts - 0.5) * 100.0;
Serial.print("reading ");
Serial.print(reading);
Serial.print(", volts ");
Serial.print(volts, 2);
Serial.print(", degrees C ");
Serial.println(celsius, 1);
int lit = 0;
if (celsius >= BASELINE + 2) lit = 1;
if (celsius >= BASELINE + 4) lit = 2;
if (celsius >= BASELINE + 6) lit = 3;
for (int i = 0; i < 3; i++) digitalWrite(LEDS[i], i < lit ? HIGH : LOW);
delay(250);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- LEDs are already lit with the sensor untouched This project
Your room differs from 22 C. Read the serial monitor and changeBASELINEto match. - The readings look strange This project
Check which leg of the TMP36 goes to 5V, A0 and ground. - The part gets very hot, and the reading is nonsense. Temperature sensor
The legs are reversed. With the flat face toward you, the order is +Vs, Vout, GND from left to right. Fix it right away, because a reversed TMP36 heats quickly. - The temperature is off by a lot or negative. Temperature sensor
Output is 0.5 V at 0 degrees C plus 10 mV per degree. So C = (volts minus 0.5) times 100. Compute volts from the ADC using the right reference, 5 V or 3.3 V, not always 5. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The LED does not light, or it lights once and then dies. LED
LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin. - A blue or white LED stays dark on 3.3 V. LED
Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.