-
-
Save atamis/5701117 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
double Thermister(int RawADC) { | |
double Temp; | |
Temp = log(((10240000/RawADC) - 10000)); | |
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp ); | |
Temp = Temp - 273.15; // Convert Kelvin to Celcius | |
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit | |
return Temp; | |
} | |
boolean debug = false; | |
int led = 13; | |
int up = 2; | |
int down = 3; | |
double threshold = 85; // Fahrenheit | |
boolean triggered = false; | |
void setup() { | |
if(debug) Serial.begin(115200); | |
pinMode(led, OUTPUT); | |
pinMode(up, INPUT); | |
pinMode(down, INPUT); | |
digitalWrite(led, LOW); | |
} | |
void loop() { | |
double temp = Thermister(analogRead(0)); | |
if (digitalRead(up) == HIGH) { | |
threshold++; | |
triggered = false; | |
} | |
if (digitalRead(down) == HIGH) { | |
threshold--; | |
triggered = false; | |
} | |
if(debug){ | |
Serial.print(int(temp)); // display Fahrenheit | |
Serial.print("|"); | |
Serial.println(int(threshold)); | |
} | |
if (temp > threshold) triggered = true; | |
if(triggered) digitalWrite(led, HIGH); | |
else digitalWrite(led, LOW); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment