Love meter on an Arduino Uno
Hold a TMP36 between your fingers and a bar of ten WS2812B LEDs fills from pink to red with your warmth, measured against the room in half-degree steps. The whole build, an Arduino Uno and 3 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 Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Love meter: hold the temperature sensor between your fingers and a bar of
// ten LEDs fills up with your warmth. The warmer your hands, the more love.
//
// TMP36 VS -> 5 V, VOUT -> A0, GND -> GND
// LED bar 10 WS2812B LEDs, DIN <- 330 ohms <- pin 6, VDD -> 5 V, VSS -> GND
//
// It is the classic love-o-meter, honest about what it measures: the TMP36
// gives 10 mV per degree Celsius, with 500 mV at 0 degrees, so
// degrees = (millivolts - 500) / 10. For the first two seconds the sketch
// reads the room and keeps that as the baseline. After that, every half a
// degree above the room lights one more LED, from pink up to deep red.
//
// A hand warms the sensor slowly, over ten or twenty seconds, because the
// little plastic package has to heat up. That slow climb is the fun part.
//
// Things to try. Drag the sensor's temperature up. Change STEP_TENTHS to make
// the meter harder or easier to fill.
#include <Adafruit_NeoPixel.h>
const int BAR_PIN = 6;
const int LEDS = 10;
const int STEP_TENTHS = 5; // tenths of a degree per LED
Adafruit_NeoPixel bar(LEDS, BAR_PIN, NEO_GRB + NEO_KHZ800);
const char *LABELS[] = {"Just friends", "A little crush", "Sweet on you", "Smitten",
"Head over heels", "True love!"};
long room = 0; // tenths of a degree
int lastLevel = -1;
long tenths() {
long mv = analogRead(A0) * 5000L / 1024;
return mv - 500; // 10 mV a degree is 1 mV a tenth
}
void setup() {
Serial.begin(9600);
bar.begin();
bar.setBrightness(150);
bar.show();
long sum = 0;
for (int i = 0; i < 20; i++) {
sum += tenths();
delay(100);
}
room = sum / 20;
Serial.print("Love meter ready. The room is ");
Serial.print(room / 10);
Serial.print(".");
Serial.print(abs(room % 10));
Serial.println(" C. Hold the sensor!");
}
void loop() {
long warmer = tenths() - room;
int level = constrain(warmer / STEP_TENTHS, 0, LEDS);
for (int i = 0; i < LEDS; i++) {
if (i < level) {
// Pink at the bottom, deep red at the top.
bar.setPixelColor(i, 255, 100 - i * 10, 140 - i * 14);
} else {
bar.setPixelColor(i, 0, 0, 0);
}
}
bar.show();
if (level != lastLevel) {
lastLevel = level;
Serial.print("Level ");
Serial.print(level);
Serial.print(": ");
Serial.println(LABELS[level * 5 / LEDS]);
}
delay(200);
}
Parts list
5 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
5 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 6; Resistor, 330 Ω pin 1
- Arduino Uno R3 pin 5V; Temperature sensor pin VS; Addressable RGB LEDs pin VDD
- Ground: Arduino Uno R3 pin GND; Temperature sensor pin GND; Addressable RGB LEDs pin VSS
- Arduino Uno R3 pin A0; Temperature sensor pin VOUT
- Resistor, 330 Ω pin 2; Addressable RGB LEDs pin DIN
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.