Here is a script for a kegerator (beer fridge) controller with the Arduino. It uses a thermistor to get the temperature. You have to calibrate the thermistor by noting values on the screen at known temperatures. For a kegerator, if you know 0C and 10C, you could interpolate the other temps.
The script flashes a LED showing morse code for the thermistor value and it will convert to degrees C if you put the numbers in a table. It prints the values to the screen as well.
The controller turns the compressor on at a maximum temperature, and turns the compressor off at a minimum temperature that you input. On the example, it is set to turn on at 4C (Vmax=484) and off at 2C (Vmin=459).
I have not set this up in real life but it turns an LED on and off at the right temps so if it connected to the proper relay, it should work. The intended appliance is a chest freezer, and the relay would turn the power to the chest freezer on and off as the controller directs.
// Kegerator Controller
// Kegerator control to digital pin 5
// Thermistor to analog pin 2
// this example is with a 500 Ohm thermistor at 20C and a 1k Ohm resistor to ground
// 5VDC to thermistor to resistor to ground, pin 2 to thermistor/resistor junction
// Vmax is 4C, Vmin is 2C on my thermistor circuit.
// Vdyn is the current voltage read from the thermistor
// Pin 13 flashes morse value for Vdyn on LED, pin 9 sounds a morse tone on speaker for Vdyn
// 434-> 0C, 447-> 1C, 459-> 2C, 472-> 3C, 484-> 4C, 497-> 5C, 509-> 6C, 522-> 7C, 534-> 8C, 545-> 9C, 559-> 10C
int Vmax = 484;
int Vmin = 459;
int ThermistorPin = 2;
int ditlength = 25;
int hundreds = 0;
int tens = 0;
int ones = 0;
int Vdyn = 0;
int status = 0;
int x = 0;
int c = 0;
typedef void (*FunctionPointer) ();
FunctionPointer numeral[10] = {zero,one,two,three,four,five,six,seven,eight,nine};
int conversion[9] = {434,447,459,472,484,497,509,522,534};
void zero(void) {dash(); dash(); dash(); dash(); dash(); pause();};
void one(void) { dit(); dash(); dash(); dash(); dash(); pause();};
void two(void) {dit(); dit(); dash(); dash(); dash(); pause();};
void three(void) {dit(); dit(); dit(); dash(); dash(); pause();};
void four(void) {dit(); dit(); dit(); dit(); dash(); pause();};
void five(void) {dit(); dit(); dit(); dit(); dit(); pause();};
void six(void) {dash(); dit();dit();dit();dit(); pause();};
void seven(void) {dash(); dash(); dit(); dit(); dit(); pause();};
void eight(void) {dash(); dash(); dash(); dit(); dit(); pause();};
void nine(void) {dash(); dash(); dash(); dash(); dit(); pause();};
void dit() {
for (x=0; x<ditlength; x++){
digitalWrite(9, HIGH);
digitalWrite(13, HIGH);
delayMicroseconds(2800);
digitalWrite(9, LOW);
digitalWrite(13, LOW);
delayMicroseconds(100);
}
digitalWrite(9,LOW);
digitalWrite(13,LOW);
delay(100);
}
void dash() {
for (x=0; x<ditlength*3; x++){
digitalWrite(9, HIGH);
digitalWrite(13, HIGH);
delayMicroseconds(2800);
digitalWrite(9, LOW);
digitalWrite(13, LOW);
delayMicroseconds(100);
}
digitalWrite(9,LOW);
digitalWrite(13,LOW);
delay(100);
}
void pause(){
digitalWrite(9,LOW);
digitalWrite(13,LOW);
delay(300);
}
void setup() {
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop() {
Vdyn = analogRead(ThermistorPin);
Serial.println(Vdyn);
if(Vdyn > Vmax){
status = 1;
}
if (Vdyn < Vmin){
status = 0;
}
if(status == 1){
digitalWrite(5, HIGH);
Serial.println("Compressor On");
}
if(status == 0){
digitalWrite(5, LOW);
Serial.println("Compressor Off");
}
hundreds = int(Vdyn/100);
tens = int((Vdyn - (hundreds*100))/10);
ones = int(((Vdyn - (hundreds*100)) - (tens*10)));
numeral[hundreds]();
numeral[tens]();
numeral[ones]();
delay(1000);
for (c=0; c<9; c++){ //if in range 0 to 8, morse flash degrees Celsius
int d = c + 1;
if (Vdyn > conversion[c] && Vdyn < conversion[d]){
numeral[c]();
Serial.println(c);
}
}
delay(1000);
}