Temperature sensor LM35

From Wiring

Jump to: navigation, search

This tutorial demonstrates how to connect a temperature sensor LM35. You can find the datasheet here.

Setup diagram


Lm35.jpg

Code


// Analog pin.
int sensorPin = 0;
// Temperature variables.
int centigrade = 0;
int fahrenheit = 0;


void setup()
{
  // Start serial communication.
  Serial.begin(9600);
  
}

void loop()
{
  // Converts reading to temperature in centigrade.
  centigrade = ( 5.0 * analogRead(sensorPin) * 100.0) / 1024.0;
  // Converts to temperature in fahrenheit.
  fahrenheit = (centigrade * 9)/ 5 + 32;

  // Sends to serial port.
  Serial.print(centigrade,DEC);
  Serial.print(" degree celsius, ");
  Serial.print(fahrenheit,DEC);
  Serial.println(" degree fahrenheit.");

  delay(1000);
}


Language: English  • EspaƱol
Personal tools