Arduino Thermometer in 3 minutes

LM35 sensor on a prototyping board

Building a simple thermometer with Arduino is very easy.
For this project I use:

 Arduino Mega board

 LM35CZ sensor

Searching on Google “Arduino LM35” you can find this page on Arduino Playground.

So I use this equation:

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

As you can see on the Playground this is the most inaccurate acquisition but the simplest.

The schematic is very easy to make:

Arduino MEGA wiring diagram

The code is very easy, too.

It begins with declarations.

int thermometer = A11; 

int sensorValue = 0;

thermometer” is the pin where the sensor is attached.

sensorValue” is the value of the sensor.

In the setup I set up the serial port and the analog input.

void setup() {
  Serial.begin(9600);
  pinMode(thermometer,INPUT);
}

In the loop I do the arithmetic mean on ten reads.  A sample is done every 100 milliseconds.

I use the equation from the Arduino Playground.

At the end Arduino board writes on serial port the value.

void loop(){

  sensorValue=0;

  for(int i=0;i<10;i++){

      sensorValue = sensorValue +((5*analogRead(thermometer))*100)/1024;  

      delay(100);
  }

  sensorValue = sensorValue/10;

  Serial.print(sensorValue);
  Serial.println("°C");

  delay(500);
}

You can download the code and try.

It works on every Arduino board changing the analog input pin (i.e. A11 → A0)