How to Build a Temperature-Based LED Bar with TMP36 and Arduino
In this project, we’ll use a TMP36 temperature sensor and an Arduino to light up a row of LEDs based on the ambient temperature. As the temperature increases, more LEDs will light up from left to right, just like a temperature meter.
Components Required
- Arduino Uno Starter Kit
- Bread Board
- Jumper Wires
- 5mm LEDs Assortment Pack
- Resistors ( 220 ohms recommended)
- TM36 Temperature Sensor
This post may contain affiliate links. If you purchase through these links, I may earn a small commission at no extra cost to you. It helps support this blog and keeps the projects coming—thanks for your support!
TMP36 Pinout and Wiring
Facing the flat side of the TMP36 with the text facing you:

TMP36 Pin | Connects to | Description |
---|---|---|
1 (VCC) | 5V | Power supply |
2 (VOUT) | A0 | Analog output to Arduino |
3 (GND) | GND | Ground |
LEDs: Connect 6 LEDs to Arduino digital pins D2 through D7, each in series with a 220Ω resistor.
Arduino Code
const int tempPin = A0;
const int ledPins[] = {2, 3, 4, 5, 6, 7};
const int ledCount = 6;
void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
int sensorValue = analogRead(tempPin);
float voltage = sensorValue * (5.0 / 1023.0); // Convert analog reading to voltage
float temperatureC = (voltage - 0.5) * 100.0; // TMP36: 10mV per degree with 500mV offset
// Map temperature range (20–40°C) to number of LEDs to turn on (0–6)
int level = map(temperatureC, 20, 40, 0, ledCount);
level = constrain(level, 0, ledCount);
// Light up LEDs according to temperature level
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], i < level ? HIGH : LOW);
}
delay(300); // Short delay to stabilize readings
}
Visual Temperature Bar with TMP36
This standalone project turns an analog temperature sensor (TMP36) into a simple LED thermometer. It’s ideal for learning how to convert analog input into real-world feedback.
Code Explanation
const int tempPin = A0;
const int ledPins[] = {2, 3, 4, 5, 6, 7};
const int ledCount = 6;
void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
int sensorValue = analogRead(tempPin);
float voltage = sensorValue * (5.0 / 1023.0); // Convert analog reading to voltage
float temperatureC = (voltage - 0.5) * 100.0; // TMP36: 10mV per degree with 500mV offset
int level = map(temperatureC, 20, 40, 0, ledCount);
level = constrain(level, 0, ledCount);
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], i < level ? HIGH : LOW);
}
delay(300);
}
How It Works
– The TMP36 sensor gives an analog voltage that corresponds to temperature.
– The formula (voltage - 0.5) * 100
converts that voltage to Celsius.
– The temperature is then mapped from 20°C–40°C into 0–6 LED levels.
– Based on the current temperature, a corresponding number of LEDs light up to create a bar-style indicator.
Why It’s Cool
This project is beginner-friendly, highly visual, and easily extendable. You can add an OLED display, buzzers, or even WiFi integration later.
How It Works
- The TMP36 sensor provides an analog voltage based on the ambient temperature. At 0°C, the output is around 0.5V. Each 1°C adds 10mV.
- Arduino reads this analog signal from pin A0. The voltage is then converted to degrees Celsius using the formula:
(voltage - 0.5) * 100
. - The temperature is mapped from a range (e.g., 20°C to 40°C) to how many LEDs should light up (from 0 to 6).
- For example:
- At 0°C → 0 LEDs on
- At 50°C → ~3 LEDs on
- At 100°C → All 6 LEDs on
- This creates a simple visual feedback system showing how hot it is using lights instead of a number.
Optional Upgrades
- Replace the LEDs with RGB LEDs and fade colors based on temperature.
- Add a buzzer to beep when temperature exceeds a certain threshold.
- Display the temperature on an LCD or OLED.
- Change LED colors based on temperature zones: green (cool), yellow (warm), red (hot).
đź”§ Recommended Arduino Starter Kits for Beginners
If you’re just getting started with Arduino, these beginner-friendly kits will help you learn faster and avoid the headache of missing parts. They all include essential components like LEDs, resistors, jumper wires, and an Arduino-compatible board.
- Arduino Official Starter Kit
Includes a genuine Arduino UNO board, project book, and components for 15+ tutorials.
👉 Check it on Amazon - Elegoo UNO R3 Super Starter Kit
Affordable and packed with sensors, LEDs, motors, and wires — great value.
👉 View the Elegoo Kit - Freenove Ultimate Starter Kit
Includes 200+ components, an Arduino-compatible board, and 50+ example projects.
👉 See the Freenove Kit
đź’ˇ Tip: Choose a kit with a good variety of components so you can build multiple projects without buying extra parts later.