Arduino Temperature Reader program

Here is the finished product:

The bold sentences are comments about that section of the program.

 

* Tutorial 1: Reading Temperature

 

// The output pin of the LM35 temperature sensor

int lm35Pin = A0;

 

void setup()

{

   // set up serial at 9600 baud  

Serial.begin(9600);

}

void loop()

{

int analogValue;

float temperature;

 

   // read our temperature sensor

analogValue = analogRead(lm35Pin);

 

   // convert the 10bit analog value to Celcius

temperature = float(analogValue) / 1023;

temperature = temperature * 500;

 

   //Converting celsius to Farenheit

  

float F = (1.8)*temperature+32;

 

// print the temperature over serial

Serial.print(“Temp in Celsius: “);

Serial.print(temperature);

Serial.println(“C”);

 

Serial.print(“Temp in Farnheit: “);

Serial.print(F);

Serial.println(“F”);

// wait 1 second before reading the temperature again

delay(1000);

Leave a Comment

Your email address will not be published. Required fields are marked *