Friday, November 22, 2013

How to control termometer in Arduino

Today I'm going to show you how to control termometer. Firstly you will need to connect terometer to Arduino.

Now open your arduino! =)

void setup() //setup function
{
  Serial.begin(9600); //install Serial output
}

int checkTemp() //read temperature function
{
  float voltage = 0; //float variable for volts
  float celsius = 0; //float variable for celsius
  float sensor = 0;  //float variable for sensor
  
  sensor = analogRead(0); //read from analog input 0
  voltage = (sensor * 5000) / 1024; // convert raw sensor value to millivolts
  voltage = voltage - 500; // remove voltage offset
  
  return (voltage / 10); // convert millivolts to Celsius and return result
}

void loop() //loop function
{
    Serial.println(checkTemp()); //print result of checkTemp() function
}

Ok, now upload your code. And press tools->"Serial Monitor" or Ctrl + Shift + M. Done!

No comments:

Post a Comment