Project 12 LM35 Temperature Sensor

1. 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.

2. Hardware Required

  • LM35 *1

  • Control board* 1

  • Breadboard*1

  • USB cable * 1

  • Breadboard jumper wire * 5

3. Connection for REV4

4. Connection for 2560 R3

5. 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
}

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