Projects / Thermometer bar of lights

Thermometer bar of lights

Beginner1 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. UNOTMP3622.9°C

    Wire the TMP36

    Pin 1 to 5V, pin 2 to A0, pin 3 to GND.

  2. UNOLM3914

    Wire the LM3914 power

    Pin 3 and pin 9 to 5V, pin 2 and pin 4 to GND, pin 8 to GND.

  3. UNO

    Wire the reference

    Pins 6 and 7 together, 2.2 kilohm from pin 7 to GND.

  4. UNO

    Wire the filter

    D9 through 10 kilohm to pin 5, 10 microfarad from pin 5 to GND.

  5. UNO10.6 mA

    Wire the LEDs

    Each anode to 5V, each cathode to one output pin (1 and 10 to 18).

  6. UNOTMP3623.0°C

    Upload the sketch

    Serial monitor shows the temperature.

  7. UNO10.6 mA

    Pinch the sensor

    More LEDs light as it warms.

  8. UNOLM3914

    Let it cool

    The bar shrinks.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TMP36 pin 1 (Vs)Uno 5VPower, flat face toward you
TMP36 pin 2 (output)Uno A010 mV per degree plus a 0.5 V offset
TMP36 pin 3Uno GNDGround
Uno D910 kilohm to LM3914 pin 5, 10 microfarad to GNDPWM filtered into a smooth voltage
LM3914 pin 3 (V+) and pin 9 (mode)Uno 5VBar mode
LM3914 pin 2 (V-), pin 4 (RLO), pin 8Uno GNDGround and low reference
LM3914 pins 6 and 7Tied together, 2.2 kilohm from pin 7 to GNDReference and LED current
LM3914 pins 1 and 10 to 18Ten red LED cathodes, anodes to 5VLEDs 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.

CheckExpected
Room at about 20 degreesAbout 2 or 3 LEDs lit
Hold the sensor in a hand6 to 8 LEDs lit
Below 15 degreesBar empty
Above 35 degreesAll ten lit
Remove the filter capacitorBar 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 →

Ask Lark AI

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.