Skip to content

Instantly share code, notes, and snippets.

@EstebanMDQ
Last active August 29, 2015 14:02
Show Gist options
  • Save EstebanMDQ/356e9dc17b94e6c51589 to your computer and use it in GitHub Desktop.
Save EstebanMDQ/356e9dc17b94e6c51589 to your computer and use it in GitHub Desktop.
float temp;
float target_temp = 21.0;
const int tempPin = A0; // the analog pin used to read temp
const int ledPin = 3; // the number of the LED pin
/*
LM 35
5v --|\
A0 --| |
GND --|/
LED
GND -------------------|\ (-)
PIN3 ---1k-/\/\/\-------|/ (+)
*/
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}
float measure_temp()
{
float tempK = (((analogRead(tempPin)/ 1023.0) * 5.0) * 100.0);
//Converts Kelvin to Celsius minus 2.5 degrees error
float tempC = tempK - 273.0;
// float tempF = ((tempK - 2.5) * 9 / 5) - 459.67;
return tempK;
}
void loop()
{
// check what works best
temp = measure_temp();
if( temp > target_temp ) {
digitalWrite(ledPin, LOW);
} else {
digitalWrite(ledPin, HIGH);
}
Serial.print("temperature = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment