ThisCalculator

Everyday

LM35 Arduino Temperature Monitor: Wiring & Code

Updated · Standard formula, shown below

LM35 Arduino Temperature Monitor: Wiring & Code

Yes, you can monitor temperature with an Arduino and an LM35 sensor, and this guide shows exactly how to wire it and read the output. You connect the LM35’s three pins to 5V, ground, and an analog input, then use a simple formula to convert the analog reading into degrees Celsius. The result is a reliable, low-cost temperature monitor that works from 0°C to 100°C (32°F to 212°F) with no external components required.

What the LM35 Is and Why It’s Popular

The LM35 is a precision integrated-circuit temperature sensor made by Texas Instruments. Unlike thermistors, which need a calibration table and a resistor network, the LM35 outputs a voltage that is directly proportional to temperature: 10 millivolts per degree Celsius. At 25°C, it outputs 250 mV; at 0°C, it outputs 0 V. This linear output makes it one of the easiest analog temperature sensors to use with a microcontroller.

It is also inexpensive, widely available, and requires no external calibration. The sensor itself is a three-pin package (TO-92) that looks like a small transistor. You can power it from the Arduino’s 5V pin, and it draws about 60 µA, so it barely affects your power budget. For these reasons, the LM35 is a common starting point in Arduino tutorials and electronics education.

How the LM35 Works

Inside the LM35, a band-gap reference and an amplifier produce an output voltage that rises 10 mV for every 1°C increase in temperature. The formula is:

Temperature (°C) = Vout (mV) / 10

For example, if the output voltage is 750 mV, the temperature is 75°C. This linear relationship holds from 0°C to 100°C with the standard version (LM35DZ), and some versions go down to -55°C or up to 150°C, but those require a negative supply voltage for sub-zero readings.

The Arduino’s analog-to-digital converter (ADC) reads voltages from 0 to 5V and converts them to an integer from 0 to 1023. The resolution is therefore 5V / 1024 ≈ 4.88 mV per step. Since the LM35 changes 10 mV per degree, the ADC step corresponds to about 0.488°C. That is fine for most room-temperature monitoring, but you can improve resolution by using the AREF pin with a lower reference voltage, or by using a 10-bit ADC with an external reference.

Wiring the LM35 to an Arduino

The LM35 has three pins. When the flat face is toward you, the left pin is VCC (power), the middle pin is Vout (signal), and the right pin is GND. Connect them as follows:

  • VCC (left) → Arduino 5V
  • Vout (middle) → Arduino A0 (analog input)
  • GND (right) → Arduino GND

That’s the entire circuit. No resistors, capacitors, or pull-ups are needed. If you are using a breadboard, insert the LM35 with the flat side facing you and the pins going into three separate rows. Double-check the pinout before powering up—reversing VCC and GND can damage the sensor.

Arduino Code to Read the Temperature

Here is a complete sketch that reads the LM35 on analog pin A0 and prints the temperature to the Serial Monitor every second:

const int sensorPin = A0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int reading = analogRead(sensorPin);
  float voltage = reading * (5.0 / 1023.0);
  float tempC = voltage * 100.0;
  Serial.print("Temperature: ");
  Serial.print(tempC);
  Serial.println(" °C");
  delay(1000);
}

The code works in three steps:

  1. Read the raw ADC value (0–1023) with analogRead().
  2. Convert that to a voltage using the reference voltage (5.0 V) and the ADC resolution (1023).
  3. Multiply the voltage by 100 to get degrees Celsius, because the LM35 outputs 10 mV per degree.

If you want Fahrenheit, use the conversion: tempF = tempC * 9.0 / 5.0 + 32.0.

Common Problems and How to Fix Them

Most issues with the LM35 and Arduino come from wiring or power supply. Here are the most frequent problems and their solutions:

  • Reading is always 0 or 1023: Check that VCC and GND are not swapped, and that the signal pin is actually connected to A0. A floating analog pin can read random values, but a solid 0 or 1023 usually means a wiring error.
  • Reading is too high or too low by a few degrees: The Arduino’s 5V pin may not be exactly 5.00V. If you use a USB power supply, it might be 4.8V or 5.1V. For more accuracy, measure the actual voltage at the 5V pin and use that value in the code instead of 5.0.
  • Reading fluctuates rapidly: This is normal because the ADC has some noise. Take multiple readings and average them, or add a small capacitor (0.1 µF) between Vout and GND to smooth the signal.
  • Reading is stuck at a high value near 100°C: The LM35 may be too close to other components on the breadboard that generate heat, or the sensor may be touching your hand. Move it away from heat sources.
  • Sensor gets hot: You likely reversed VCC and GND. Disconnect power immediately and re-check the pinout.

Improving Accuracy and Resolution

The default 5V reference gives a resolution of about 0.5°C per ADC step. If you need finer readings, you can change the analog reference to 1.1V (internal) or use an external reference. With a 1.1V reference, the ADC step becomes 1.1V / 1024 ≈ 1.07 mV, which corresponds to about 0.107°C per step. To use the internal 1.1V reference, add analogReference(INTERNAL) in setup() and change the code to use 1.1 instead of 5.0:

float voltage = reading * (1.1 / 1023.0);

However, the LM35 outputs 0V at 0°C, so with a 1.1V reference, the maximum readable temperature is 110°C. That is fine for most indoor or outdoor monitoring. For sub-zero temperatures, you will need a negative supply voltage or a different sensor like the TMP36, which has a 500 mV offset at 0°C.

LM35 vs. Other Temperature Sensors

The LM35 is not the only option. Here is a quick comparison with common alternatives:

  • LM35: Analog output, 10 mV/°C, 0°C to 100°C (standard version), requires no extra components, but needs a negative supply for below 0°C.
  • TMP36: Analog output, 10 mV/°C with a 500 mV offset (0.5V at 0°C), so it can read negative temperatures without a negative supply. Range -40°C to +125°C.
  • DHT11/DHT22: Digital output, includes humidity, but slower (one reading per second or more) and less accurate (DHT11 is ±2°C).
  • DS18B20: Digital one-wire interface, waterproof versions available, range -55°C to +125°C, but requires a pull-up resistor and a library.

The LM35 is best when you want a simple, low-cost analog sensor for a narrow temperature range around room temperature. For broader ranges or humidity, choose a different sensor.

Frequently Asked Questions

Can the LM35 read negative temperatures with an Arduino?

No, not directly. The standard LM35DZ outputs 0V at 0°C and cannot go below that without a negative supply voltage. If you need to measure below 0°C, use a TMP36 or a DS18B20 instead.

What is the maximum temperature the LM35 can measure?

The LM35DZ is rated for 0°C to 100°C. Other variants like the LM35CA can go up to 150°C, but they require a higher supply voltage (up to 30V) and may need a heat sink. For most Arduino projects, the 0–100°C range is sufficient.

Why is my temperature reading off by 2 or 3 degrees?

Most likely the Arduino’s 5V pin is not exactly 5.00V. Measure the actual voltage at the 5V pin with a multimeter and use that value in the code. Also, the sensor itself has an accuracy of ±0.5°C at 25°C, so small deviations are normal.

Do I need a resistor with the LM35?

No. The LM35 is a voltage output device, not a resistive sensor. You can connect it directly to the Arduino without any external resistors. Adding a 0.1 µF capacitor between Vout and GND can reduce noise, but it is not required.

Can I use an ESP8266 or ESP32 instead of an Arduino?

Yes, but be careful: many ESP boards run at 3.3V logic. The LM35 will work with a 3.3V supply, but the output voltage will be the same (10 mV/°C), and the ADC reference is 3.3V, so you must change the code to use 3.3 instead of 5.0. The resolution will be slightly better because the reference is lower.

How do I convert the Celsius reading to Fahrenheit?

Use the standard formula: F = C * 9.0 / 5.0 + 32.0. In the Arduino code, add this line after calculating tempC and print both values.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.