int tempIn = 3; // temperature sensor on Analogue Pin 3
int ledOut = 7; // LED on Digital Pin 7
int aiValue = 0; // input value (0-1023 = 0 to 5v)
float setPoint = 71; // Trigger value in 'C
float deadband = 0.5; // Differential for reset value in 'C
/*
18.
NOTE: the deadband action can be disabled by setting the deadband to 0
19.
*/
float degC; // The temperature in Degrees Centigrade
void setup()
{
pinMode(ledOut, OUTPUT); // Configure the Digital Pin Direction for the LED
Serial.begin(9600);
}
void loop()
{
degC = getTemperature(getVolts()); //Get the Volts and the Temperature using Helper functions.
if (degC > setPoint)
{
digitalWrite(ledOut, HIGH); // Temperature Limit Reached, turn the LED on.
Serial.println(" | Output: ON.");
}
else
{
if (degC < (setPoint - deadband))
{
digitalWrite(ledOut, LOW); // Temperature dropped below SP and deadband, turn the LED off.
Serial.println(" | Output: OFF.");
}
}
delay(1000);
}
float getVolts()
{
int inputValue;
inputValue = analogRead(tempIn);
float volts;
volts = (((float)inputValue / 1024) * 5);
Serial.print("Input Value: ") ; Serial.print(inputValue);
Serial.print(" | Voltage: ") ; Serial.print(volts);
return volts;
}
float getTemperature(float volts)
{
float temp = (volts - 0.5) / 0.01 ;
Serial.print(" | Temperature: "); Serial.print(temp); Serial.print(" 'C");
return temp;
}
No comments:
Post a Comment