Asynkronix

Indie app developer

My Arduino controlled fridge

A while ago the fridge thermostat of my combined fridge and freezer broke. I didn’t want to buy a new fridge, so I checked the price of a new thermostat. The price was about 700 Swedish kronor, or 100 USD. As I already had a 30$ Arduino and a 2$ relay lying around, I thought: why not give it a try? So I started with a quick and dirty fix, disconnected the thermostat and connected the Arduino and the relay to the fridge compressor. I made a very simple timer based Arduino sketch that turned the compressor on for 5 minutes and off for 20 minutes. This worked really well and the fridge was up and running in no time. Of course the temperature was not very constant, especially when the door was opened and closed a lot (something that happens when a teenager in the family consumes huge amounts of milk). To solve this I had to add a temperature sensor, and I also happened to have a LM335 sensor lying around. I adjusted the Arduino sketch, added the LM335, and now the fridge has been running as solid as rock for 4 months. I built the relay shield myself, but as it controls high currents and high voltage I recommend you buy it. You can for example get one from Robotshop.

Here is the code (I got a lot of inspiration from spacetinkerer):

//fridgeWithLM335
int t;
int relayPin =  4;      
int ledPin = 13;

float tk;
float tc;

float tcset;
float tcdelta;

int relayState;

void setup() {
  tcset=6.0;
  tcdelta=1.5; // 4.14--7.55

  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  turnCompressorOn();
}

void loop() {
  t=analogRead(0);
  tk = t * 0.004882812 * 100;
  tc = tk - 2.5 - 273.15; 
  if (tc>(tcset+tcdelta) && isCompressorOff()){
    turnCompressorOn();
  } else if (tc<(tcset-tcdelta) && isCompressorOn()){
    turnCompressorOff();
  }   
  delay(30*1000);
}

void turnCompressorOn(){
  relayState=LOW;
  digitalWrite(relayPin,relayState);
  digitalWrite(ledPin,!relayState);
}

void turnCompressorOff(){
  relayState=HIGH;
  digitalWrite(relayPin,relayState);
  digitalWrite(ledPin,!relayState);
}

boolean isCompressorOff(){
  return (relayState==HIGH); 
}

boolean isCompressorOn(){
  return !isCompressorOff();
}

Comments are closed.