Project

Keep Your Cool: Monitor Temperature with an Arduino

June 28, 2015 by Tim Youngblood

The LM35 is an ideal temperature sensor for measuring ambient temperature. It provides a linear output proportional to the temperature, with 0 V corresponding to 0 degrees C and an output voltage change of 10 mV for each degree C change. LM35s are easier to use than thermistors and thermocouples because they are so linear and require no signal conditioning.

You can use an Arduino to monitor the air temperature by using an LM35 temperature sensor

The LM35 is an ideal temperature sensor for measuring ambient temperature. It provides a linear output proportional to the temperature, with 0 V corresponding to 0 degrees C and an output voltage change of 10 mV for each degree C change. LM35s are easier to use than thermistors and thermocouples because they are so linear and require no signal conditioning. 

The output of an LM35 can be connected directly to a Arduino analog input. Because the Arduino analog-to-digital converter (ADC) has a resolution of 1024 bits, and the reference voltage is 5 V, the equation used to calculate the temperature from the ADC value is:

temp = ((5.0 * analogRead(TemperaturePin)) / 1024) * 100.0

To display the temperature, we will use a liquid crystal display (LCD). 

 

Experiment

 

The purpose of this experiment to build a temperature monitor using an LM35, a 16x2 LCD, and an Arduino.

 

Hardware Required

  • 1 x Arduino Mega2560
  • 1 x LCD 
  • 1 x 5 kohm potentiometer
  • 1 x breadboard
  • 1 x LM35 temperature sensor
  • 1 x 1k ohm resistor
  • Female connectors
  • jumper wires

 

 

Wiring Diagram

Circuit Diagram

Circuit Diagram

Connect the components as shown in the figure above. A 1 kohm resistr is connected between the LM35 output and GND to limit the current without affecting the output voltage. 

LCD Pins

LCD Pins

 

The LCD is connected to the Arduino as shown below. The middle terminal of the potentiometer is connected to pin 3 of the LCD to change the brightness of the LCD backlight. The other two pins of the potentiometer are connected to 5 V and GND. Enable is connected to Arduino pin 9 of Arduino and RS is connected to Arduino pin 8. RW is connected to ground. 

DB4-----> pin4

DB5----->pin5

DB6----->pin6

DB7----->pin7

RS----->pin8

 

EN----->pin9

 

Code

The program uses the LiquidCrystal.h library to write data to the display. In the loop(), the value of the sensor output is continually read, converted to degrees C, then displayed on the LCD. 

#include    //arduino lcd library

LiquidCrystal lcd(8,9,4,5,6,7);   //defining lcd pins

int value=0;            //initializing variables
float volts=0.0;      
float temp=0.0;      
float tempF=0.0;

void setup()
{
  pinMode(3,INPUT);      //setting arduino pin3 as input
  Serial.begin(9600);   // opens serial port, sets data rate to 9600 bps
  lcd.begin(16,2);      // set up the LCD's number of columns and rows
 
  
}

void loop()
{
  value=analogRead(A0);          //read from A0
  volts=(value/1024.0)*5.0;      //conversion to volts
  temp= volts*100.0;             //conversion to temp Celsius
  tempF=temp*9/5+32;             //conversion to temp Fahrenheit

//display temp no lcd

  Serial.print("temperature= "); 
  Serial.println(temp);
  lcd.setCursor(0,0);
  lcd.print("TEMP= ");
  lcd.print(temp);
  lcd.print(" C");
  lcd.setCursor(0,1);
  lcd.print("TEMP= ");
  lcd.print(tempF);
  lcd.print(" F");
  
  
  delay(500);
}

Keep_Your_Cool.zip

Video

Give this project a try for yourself! Get the BOM.

12 Comments
  • A
    aabacc February 17, 2016

    Hello, can you explain the limiting resistor after the LM35 output. From the specs,; the chip specs states it takes a max of .1 ma (I think that what it means) so I don’t think there is that much current going to the Arduino?

    Thanks.

    Like. Reply
  • S
    Sounak Nandy March 24, 2016

    Is the code for Arduino UNO same for Arduino ATMega 2560

    Like. Reply