Home › Wiring › LM35 temperature sensor with Arduino Uno

LM35 temperature sensor with Arduino Uno

How to connect an LM35 temperature sensor to an Arduino Uno: the wiring, a sketch that works, and a simulator to try it in your browser before you build it.

LM35 temperature sensor wired to an Arduino Uno in Zen Circuit Lab

LM35DZ analog thermometer · output 10 mV per °C (250 mV at 25 °C) · 4–30 V supply · ±0.5 °C

Wiring

LM35 temperature sensor pinArduino Uno
+V_S5V
V_outA0
GNDGND

Run it in the labFree, no account needed. The same wiring, with the sketch already on the board.

Code

From the project Arduino thermometer with an alarm: LM35, LCD and buzzer. It also compiles in the Arduino IDE with the libraries it includes.

// Thermometer with an alarm: an LM35 on A0 (10 mV per °C), the reading on a 16×2 I2C LCD, an active buzzer on D8 above 35 °C.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int SENSOR = A0, BUZZER = 8;
const float ALARM_C = 35.0;

void setup() {
  Serial.begin(9600);
  pinMode(BUZZER, OUTPUT);
  lcd.init(); lcd.backlight();
}

void loop() {
  float c = analogRead(SENSOR) * 500.0 / 1023.0;      // 5 V reference: 1023 = 500 °C worth of 10 mV
  bool hot = c >= ALARM_C;
  digitalWrite(BUZZER, hot ? HIGH : LOW);
  lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(c, 1); lcd.print(" C   ");
  lcd.setCursor(0, 1); lcd.print(hot ? "Too hot!        " : "OK              ");
  Serial.print(c, 1); Serial.println(" C");
  delay(500);
}

For teachers

The project runs in the browser on a laptop or a phone, so every student can build and test it before the class touches a real board. Assign it on the teacher's page and set what counts as done: a prediction, a hidden fault found, or a passing test sheet.

Related