I'm not sure if this is the best place to put this topic, but I couldn't really see a better one. Anyway, I'm building a thermostat for brewing beer. I looked around at other people's projects for a bit and found that was no standalone thermostat, they all featured a permanent serial or network connection of some sort. I have no use for this feature after debugging is complete, so I left it out. Here is my first prototype. Any comments or suggestions would be welcomed!
/* This is a thermostat (originally) intended for homebrewing beer without having to worry about temperature. It has no connection to the internet, or in fact,
even to a computer once debugging is complete. It doesn't need it.
The circuit is simple, 1 LED for visual feedback, 2 relays connected through BC548 transistors, a bigger relay for the heating device, and a piezo buzzer for audible feedback.
A schematic diagram can be found at http://frazer-makingstuffup.blogspot.com/2011/04/homebrew-homebrewing-thermostat.html
*/
int HEAT =2; // to BC548 controlling a reed relay, which in turn drives a relay capable of switching 240V
int INDICATE = 3; //visual feedback
int ALARM = 4; //audible feedback
int pin = 0; // analog pin
int raw_temp = 0; //from sensor
int tempc = 0; // temperature variable
int too_cold = 17; // set minimum temperature acceptable
int cold = 21; // set low range
int right = 22; // set desired temperature
int too_hot = 24; // set maximum acceptable temperature
void setup()
{
Serial.begin(9600);
pinMode( HEAT, OUTPUT); //all digital pins are outputs
pinMode(INDICATE, OUTPUT);
pinMode(ALARM, OUTPUT);
analogReference(INTERNAL);
}
void loop()
{
raw_temp = analogRead(pin); // get reading from LM35
tempc = ((100* raw_temp)/1024.0); // convert to whole decimal degrees
Serial.println(tempc); //serial print used for debugging,can be left out in the final installation, but can't hurt to leave it in
if(tempc <= too_cold ) // if temperature is less than or equal to the minimum temperature acceptable
{
digitalWrite(HEAT, HIGH); // turn on the heater and the audible feedback
digitalWrite(INDICATE, HIGH);
digitalWrite(ALARM, HIGH); //also flash the visual feedback
delay(100);
digitalWrite(HEAT, HIGH);
digitalWrite(INDICATE, LOW);
digitalWrite(ALARM, [HIGH);
}
elseif(tempc <= cold) // if temperature is colder than the desired temperature, but warmer than the minimum
{
digitalWrite(HEAT, HIGH); // turn on the heater
digitalWrite(INDICATE, HIGH); // provide static visual feedback
digitalWrite(ALARM, LOW); // no audible feedback
}
else if(tempc == right) // if the desired temperature has been reached
{
digitalWrite(HEAT, LOW); // no heating
digitalWrite(INDICATE, LOW); // no visual feedback
digitalWrite(ALARM, LOW); // no audible feedback
}
else if(tempc >= too_hot) // if temperature is too high
{
digitalWrite(HEAT, LOW); // no heating
digitalWrite(INDICATE, HIGH); // audible feedback
digitalWrite(ALARM, HIGH); // visual feedback flashing
delay(100); //
digitalWrite(HEAT, LOW);
digitalWrite(INDICATE, LOW);
digitalWrite(ALARM, HIGH);
}
tempc = 0; // reset tempc to 0
delay(1000); // delay 1 second before re-looping
}