Created
September 18, 2015 14:44
-
-
Save thenickcox/17aa08fa95478bb680cf to your computer and use it in GitHub Desktop.
temperature_sensor.ino
This file contains hidden or 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
const int temperaturePin = 0; | |
const float maxHighTemp = 72.0, | |
minLowTemp = 66.0, | |
voltageConversion = 0.004882814; | |
float getVoltage(int pin){ | |
return (analogRead(pin) * voltageConversion); | |
} | |
int pinsInUse[] = {13, 7}; | |
float degreesF(float voltage){ | |
float degreesC = (voltage - 0.5) * 100.0; | |
return degreesC * (9.0/5.0) + 32.0; | |
} | |
void setup(){ | |
int i = 0; | |
Serial.begin(9600); | |
for (i = 0; i < sizeof(pinsInUse); i++) { | |
pinMode(pinsInUse[i], OUTPUT); | |
} | |
} | |
void loop(){ | |
float voltage, currentTempInF; | |
String currentTempStr, currentTemp; | |
voltage = getVoltage(temperaturePin); | |
currentTempInF = degreesF(voltage); | |
Serial.println(currentTempInF); | |
digitalWrite(pinsInUse[0], currentTempInF > maxHighTemp ? HIGH : LOW); | |
digitalWrite(pinsInUse[1], currentTempInF < minLowTemp ? HIGH : LOW); | |
delay(1500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment