Build it step by step
0 of 8 doneWire the TMP36
Pin 1 to 5V, pin 2 to A0, pin 3 to GND.
Wire the LM3914 power
Pin 3 and pin 9 to 5V, pin 2 and pin 4 to GND, pin 8 to GND.
Wire the reference
Pins 6 and 7 together, 2.2 kilohm from pin 7 to GND.
Wire the filter
D9 through 10 kilohm to pin 5, 10 microfarad from pin 5 to GND.
Wire the LEDs
Each anode to 5V, each cathode to one output pin (1 and 10 to 18).
Upload the sketch
Serial monitor shows the temperature.
Pinch the sensor
More LEDs light as it warms.
Let it cool
The bar shrinks.
How do you build a thermometer bar of lights?
A TMP36 and a bar graph driver light more LEDs as the room warms, a first sensor project. You need Arduino Uno R3, TMP36 temperature sensor, LM3914 bar graph driver, LED 5 mm red × 10, Resistor 2.2 kΩ, Resistor 10 kΩ, Electrolytic capacitor 10 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- SensorsBuy
- Integrated CircuitsBuy
- SemiconductorsBuyLED 5 mm red × 10
- PassivesBuyResistor 2.2 kΩ × 1
- PassivesBuyResistor 10 kΩ × 1
- PassivesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| TMP36 pin 1 (Vs) | Uno 5V | Power, flat face toward you |
| TMP36 pin 2 (output) | Uno A0 | 10 mV per degree plus a 0.5 V offset |
| TMP36 pin 3 | Uno GND | Ground |
| Uno D9 | 10 kilohm to LM3914 pin 5, 10 microfarad to GND | PWM filtered into a smooth voltage |
| LM3914 pin 3 (V+) and pin 9 (mode) | Uno 5V | Bar mode |
| LM3914 pin 2 (V-), pin 4 (RLO), pin 8 | Uno GND | Ground and low reference |
| LM3914 pins 6 and 7 | Tied together, 2.2 kilohm from pin 7 to GND | Reference and LED current |
| LM3914 pins 1 and 10 to 18 | Ten red LED cathodes, anodes to 5V | LEDs light when their output goes low |
Code
The TMP36 gives 10 millivolts for every degree Celsius with a half-volt offset, so 25 degrees reads 0.75 V. The LM3914 is a bar graph driver: it compares its input voltage with ten evenly spaced levels between 0 and its 1.25 V reference and lights that many LEDs, with a built-in current regulator so no resistor is needed for each LED. The reference current resistor sets the LED current, about 12.5 volts divided by the resistor, which is a little under 6 mA with 2.2 kilohms. The Uno reads the TMP36, then turns the temperature range of 15 to 35 degrees into a duty cycle of up to 25 percent on a PWM pin. A resistor and capacitor smooth the PWM into a steady voltage between 0 and about 1.25 V for the LM3914. That means the bar shows your own range, not the sensor's raw voltage, and you can change TEMP_LOW and TEMP_HIGH to zoom in. Warm the sensor with a finger and the bar climbs. Keep the TMP36 pins the right way round: wiring it backwards makes the chip hot.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int TMP = A0;
const int PWM_PIN = 9;
const float TEMP_LOW = 15.0; // bar empty at this temperature, in degrees C
const float TEMP_HIGH = 35.0; // bar full at this temperature
float readTempC() {
long sum = 0;
for (int i = 0; i < 32; i++) { sum += analogRead(TMP); delay(2); }
float volts = (sum / 32.0) * 5.0 / 1023.0;
return (volts - 0.5) * 100.0; // TMP36: 10 mV per degree, 0.5 V at 0 degrees
}
void setup() {
pinMode(PWM_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
float t = readTempC();
float frac = (t - TEMP_LOW) / (TEMP_HIGH - TEMP_LOW);
frac = constrain(frac, 0.0, 1.0);
// The LM3914 full scale is 1.25 V and the filtered PWM tops out at 5 V times duty,
// so a duty of 25 percent (value 63) is full scale.
analogWrite(PWM_PIN, (int)(frac * 63));
Serial.print(t, 1);
Serial.println(" C");
delay(500);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
200.2 C 200.3 C 200.2 C 200.3 C 200.2 C 200.3 C
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Room at about 20 degrees | About 2 or 3 LEDs lit |
| Hold the sensor in a hand | 6 to 8 LEDs lit |
| Below 15 degrees | Bar empty |
| Above 35 degrees | All ten lit |
| Remove the filter capacitor | Bar flickers |
If it does not work
No LEDs light
Check pin 3 and pin 9 are on 5V and the LED direction.
Only one LED lights
Pin 9 left open means dot mode, tie it to 5V.
Bar full all the time
Check the 10 kilohm and 10 microfarad filter parts.
Temperature reads odd
Check the TMP36 pin order, flat face toward you.
LEDs dim
Check the 2.2 kilohm reference resistor.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the thermometer bar of lights?
Arduino Uno R3, TMP36 temperature sensor, LM3914 bar graph driver, LED 5 mm red × 10, Resistor 2.2 kΩ, Resistor 10 kΩ, Electrolytic capacitor 10 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the thermometer bar of lights take to build?
About 60 minutes for a beginner maker, in 8 steps.
How do I know the thermometer bar of lights works?
Room at about 20 degrees: About 2 or 3 LEDs lit. Hold the sensor in a hand: 6 to 8 LEDs lit. Below 15 degrees: Bar empty.
No LEDs light: what should I check?
Check pin 3 and pin 9 are on 5V and the LED direction.
Only one LED lights: what should I check?
Pin 9 left open means dot mode, tie it to 5V.
Bar full all the time: what should I check?
Check the 10 kilohm and 10 microfarad filter parts.
Temperature reads odd: what should I check?
Check the TMP36 pin order, flat face toward you.
