Lesson 14 LM35 Temperature Sensor

Share for us

Introduction

LM35 is a temperature sensor produced by National Semiconductor. It has very high operational accuracy and a wide operating range. With small size, low cost and reliability, LM35 is widely applied in engineering. Since it uses internal compensation, the output can begin with 0℃. LM35 has many different packages. Under the normal temperature, the LM35 requires no additional calibration to  reach the accuracy of plus or minus 1/4℃. The power supply mode can be classified as single power source and positive-and-negative double power supply. Its pins are as shown below. Under the positive-and-negative dual power supply mode, it can measure a negative temperature. Under the single power supply mode and 25℃, the quiescent current is about 50μA and it has a wide operation voltage range – between 4 to 20V, thus saving electricity.

Components

– 1* SunFounder Uno board

– 1 * Breadboard

– 1 * USB data cable

– 1 * LM35 Temperature Sensor

– 1 * I2C LCD1602

– Several jumper wires

Experimental Principle

The output voltage of the LM35 is proportional to Celsius temperature. When placed in 0℃ ambient temperature, it will output 0V. The output voltage will increase 10mV each time the temperature increases by 1℃. The calculation formula is as follows:

Experimental Procedures

Step 1: Build the circuit

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorials on our website)

Note: Here you need to add a library. Refer to the description in Lesson 4 previously in the manual.

Step 3: Compile the code

Step 4: Upload the sketch to the SunFounder Uno board

Now, you can see the current temperature displayed on the I2C LCD1602.

Code

/*****************************************
* name:LM35 Temperature Sensor
* function:
* LM35 output voltage has a linear relation with the Celsius temperature, output of 0 v when 0 ℃, 
* every increase 1 ℃, the output voltage increase 10 mv
*****************************************/
//Email:support@sunfounder.com
//Website:www.sunfounder.com
//lm35 attach to A0
/****************************************/#define lmPin A0 //LM35 attach to
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line displayfloat tem = 0;
long lmVal = 0;void setup()
{
  lcd.init(); //initialize the lcd
  lcd.backlight(); //open the backlight 
}
void loop()
{
  lmVal = analogRead(lmPin);//read the value of A0
  tem = (lmVal * 0.0048828125 * 100);//5/1024=0.0048828125;1000/10=100
  lcd.setCursor(5,0);//place the cursor on 5 column,0 row
  lcd.print(“LM35″);//print”LM35”
  lcd.setCursor(0,1);//place the cursor on 0 column,1 row
  lcd.print(“Tem= “);//print”Tem= “
  lcd.setCursor(5,1);//place the cursor on 5 column,1 row
  lcd.print(tem);//print tem
  lcd.print(char(223));//print the unit” ℃ “
  lcd.print(“C”);
  delay(200);//delay 200ms