Skip to content

Instantly share code, notes, and snippets.

@joelongstreet
Created July 29, 2014 17:19
Show Gist options
  • Save joelongstreet/5398f75f42d48570b125 to your computer and use it in GitHub Desktop.
Save joelongstreet/5398f75f42d48570b125 to your computer and use it in GitHub Desktop.
int sensorPin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;
// print out the voltage
// Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
// Serial.print(temperatureC); Serial.println(" degrees C");
// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.println(temperatureF);
delay(100); //waiting a second
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment