Free Shipping Over $119



Arduino UNO R3/MEGA 2560 R3 Project 12: LM35 Temperature Sensor

Posted by Fiona Su on

Introduction

LM35 is a common and easy-to-use temperature sensor. It does not require other hardware. You just need an analog port to make it work. The difficulty lies in compiling the code to convert the analog value it reads to celsius temperature.

thumb 

Hardware Required:

  • Arduino board *1
  • LM35*1
  • Breadboard*1
  • Breadboard jumper wire *5

Video Tutorial

Connection

Connection for REV4:

thumb

Connection for 2560 R3:

thumb

Sample Code:

int potPin = 0; // initialize analog pin 0 for LM35 temperature sensor
void setup()
{
Serial.begin(9600);// set baud rate at”9600”
}
void loop()
{
int val;// define variable
int dat;// define variable
val=analogRead(0);// read the analog value of the sensor and assign it to val
dat=(125*val)>>8;// temperature calculation formula
Serial.print("Tep:");// output and display characters beginning with Tep
Serial.print(dat);// output and display value of dat
Serial.println("C");// display “C” characters
delay(500);// wait for 0.5 second
}

Result:

After downloading the program, you can open the monitoring window to see the current temperature.

thumb 

All Tutorial

Buy 

0 comments

Leave a comment

Please note, comments must be approved before they are published