Arduino Lesson #5 – analog temperature sensor LM35DZ

In this new post at my technic-blog, I like to show, how to read temperature values from an analog LM35DZ device at Arduino UNO.

Arduino Lesson #5 - analog temperature sensor LM35DZ
Arduino Lesson #5 – analog temperature sensor LM35DZ

Buy a LM35DZ sensor for Arduino

The analog temperature sensor of type LM35DZ is very cheap, and you get this device at ebay.de for €1.7 without shipping cost. If you want it a little bit cheaper, and you can wait for your delivery, you can take a look at aliexpress.com, banggood.com or wish.com.

Technical data of sensor LM35DZ

  • Temperature measuring range from 0 °C to 100 °C
  • Precision ±0,4 °C
  • Supply voltage 4 V to 30 V

The LM35 DZ sensor has a linear relationship between the output current and the measured temperature. For every full 1 °C, the electrical voltage decreases by 10mV. I.e. 0 °C is 0 V at the output signal.

analog temperature sensor LM35DZ
analog temperature sensor LM35DZ

Pinout analog temperature sensor LM35DZ

This device has 3 legs and below you find the pinout.

Pinout analoge temperature sensor LM35DZ
Pinout analog temperature sensor LM35DZ

Simple circuit with LM35DZ at Arduino Nano

The tiny microcontroller Arduino Nano has the same pins as the big one Arduino UNO R3. But this device does not have an external power connector.

Here you can find a simple circuit with this analog sensor.

Arduino Nano with analog temperature sensor LM35DZ
Arduino Nano with analog temperature sensor LM35DZ

Sample code in Arduino IDE 2.0

To read the actual value and calculate the temperature, you dont need a library. Here i like to show you a short sample code to read actual value and calculate temperature in Celsius, Fahrenheit and Kelvin.

//temperature sensor connected to analog A0 pin
#define temperatursensorPin A0

void setup() {
  //begin serial communication with 9600 baud
  Serial.begin(9600);
}
void loop() {
  //read curent value
  int value = analogRead(temperatursensorPin);
  //calculate temperature in dregree Celsius
  float temperatureCelsius = (125 * value) >> 8;
  //calculate temperature in Fahrenheit
  float temperatureFahrenheit = temperatureCelsius * 1.8 + 32;
  //calculate tempeature in Kelvin
  float temperatureKelvin = temperatureCelsius + 273.15;
  //print temperature value to serial interface
  Serial.print("Temperatur :");
  Serial.print(temperatureCelsius, 2);
  Serial.print(" °C");
  Serial.print(" | ");
  Serial.print(temperatureFahrenheit, 2);
  Serial.print(" F");
  Serial.print(" | ");
  Serial.print(temperatureKelvin, 2);
  Serial.print(" K");
  Serial.println();
  delay(500);
}

This code will print the values to the serial interface. You can read this with the serial Monitor from the Arduino IDE.

print temperature values from LM35DZ to serial interface
print temperature values from LM35DZ to serial interface

Linechart in Arduino IDE 2.0

The Arduino IDE has a very good feature for number values, you can print this values on linechart.

serial Plotter with temperature values
serial Plotter with temperature values

To write this values to the linechart you have following some rules.

First the labels in the legend will be written with text following on a colon, the value will be added automatically with the next line followed by a line break.

 Serial.print("Celsius:");
 Serial.println(temperatureCelsius);
 Serial.print("Fahrenheit:");
 Serial.println(temperatureFahrenheit);
 Serial.print("Kelvin:");
 Serial.println(temperatureKelvin);

Here is the complete code to print values from an analog temperature sensor LM35DZ to the serial plotter.

//temperature sensor connected to analog A0 pin
#define temperatursensorPin A0

void setup() {
  //begin serial communication with 9600 baud
  Serial.begin(9600);
}
void loop() {
  //read curent value
  int value = analogRead(temperatursensorPin);
  //calculate temperature in dregree Celsius
  float temperatureCelsius = (125 * value) >> 8;
  //calculate temperature in Fahrenheit
  float temperatureFahrenheit = temperatureCelsius * 1.8 + 32;
  //calculate tempeature in Kelvin
  float temperatureKelvin = temperatureCelsius + 273.15;
  //print temperature value to serial interface
  Serial.print("Celsius:");
  Serial.println(temperatureCelsius);
  Serial.print("Fahrenheit:");
  Serial.println(temperatureFahrenheit);
  Serial.print("Kelvin:");
  Serial.println(temperatureKelvin);
  delay(500);
}

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *