Last active
August 29, 2015 14:02
-
-
Save EstebanMDQ/356e9dc17b94e6c51589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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