# Program LM35 Temperature Sensor with Arduino

Before creating the program, we will calculate how to measure and convert the output of LM35 into temperature. We will convert the voltage at the output leg LM35, then calculate it based on the reference voltage is used, turn it into Celsius, and then sends it to a computer via serial communication. ## LM35 temperature sensor circuit

If we use a 5 volt reference voltage, then the Arduino can measure at least up to 5000 mV. whereas only limited ability LM35 150o Celsius or 150 x 10 mV = 1500 mV (1.5 volt). So that the voltage coming out of the foot of the LM35 output will not likely exceed 1.5 volts.

Based on a simple equation, then we can calculate the temperature based on a comparison between the voltage capacity that can be counted by Arduino analog pin (1024) and the ability to measure suh LM35

Temperatures in Voltage (T): 0-500

Chopped input voltage (Vin): 0-1024

0/500 = 0/1024

T / 500 = Vin / 1024

T = (Vin * 500) / 1024

#### Program LM35 temperature sensor

```// Free Tutorial Arduino
// www.ioisalman.com

const int pTemperature = A0;
float temperature data;

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

void loop () {
data = analogRead (pTemperature);
temperature = Data * 500/1024;

Serial.print ("Data");
Serial.print (data);
Serial.print ("temperature");
Serial.print (temperature);
Serial.println ();
delay (1000);
}```

Program in Sketch above will read the data from temperature sensors on the A0 pin on the Arduino board and then convert it into a temperature. Climate information will be sent to the computer via serial communication with a baud rate of 9600 every 1000 milliseconds.

### float temperature data;

Variable temperature and data using a float, which contains data types that allow decimal numbers. Here using decimal for their division so if we use an integer, the final result of our lack of precision as the result of the division will be rounded.

### data = analogRead (pSuhu);

AnalogRead function () is used to read input from analog sensors. The value of the analog read range from 0 to 1023 based on the capabilities of the microcontroller in the count from 0 -5 volts.

To obtain more precise measurement results, then we can change the reference voltage used. If we use the 5000 mV reference voltage, then the space of 1500 -5000 mV will never be used. Therefore, we can use the reference voltage 1500 mV (according to the maximum output on LM35) or using a lower reference voltage, a reference voltage eg INTERNAL whose value is 1.1 volts. As a side note, if you are using a reference voltage 1.1 volt (1100 mV), then the maximum limit that can dihitungan temperature is 110o Celsius.

#### program the temperature sensor reference voltage is 1.1 volts

```// Free Tutorial Arduino
// www.ioisalman.com

const int ptemperature = A0;
float temperature data;

void setup () {
// Change to the internal reference voltage, 1.1 volts
analogReference (INTERNAL);
Serial.begin (9600);
pinMode (ptemperature, INPUT);

}

void loop () {
data = analogRead (ptemperature);
temperature = Data * 110/1024;

Serial.print ("Data");
Serial.print (data);
Serial.print ("temperature");
Serial.print (temperature);
Serial.print ("C (");
Serial.print (convertToF (temperature));
Serial.print ("F)");
Serial.println ();
delay (1000);
}

convertToF float (float temperatureC) {
return (temperatureC * 9.0 / 5.0) + 32;
}
```

Sketch Program Program at a temperature sensor using a reference voltage 1.1 volt internal reference voltage of 1.1 volts then the temperature in Celsius is converted to Fahrenheit. Based on the concept, converting Celsius to Fahrenheit using the formula:

Then the information in Celsius and Fahrenheit temperature is sent to the computer by serial communication.