Beer fridge controller 0.1

On the weekend I picked up a 220 liter beer fridge for $20. Its in really good condition (ignoring some minor rust in the freezer section), and the only real problem with it is that the thermostat doesn’t work leaving the compressor on the whole time. Doug suggested that instead of just buying a new thermostat, we should build an arduino fridge controller.

I’m not really a hardware guy, but once Doug had pointed me at the Dallas 1820 1-Wire temperature sensor, and lent me some resistors, it was pretty easy to pull the software side together. Note that this version doesn’t actually do any of the compressor control — it simulates that by turning a LED on. The compressor stuff has been delegated to Doug and will be mentioned later.

You can see that the circuit is in fact really simple. There is a LED to simulate the compressor (with a resistor), and then the 1-Wire temperature sensor (with another resistor). The code is pretty simple too. Here’s my latest fancy version:

    #include <OneWire.h>
    #include <DallasTemperature.h>
    #define COMPRESSOR 13
    #define ONEWIRE 2
    #define HIGHTEMP 4
    #define LOWTEMP 3
    #define SLEEP_SEC 10
    // 220L Kelvinator is 85 watts
    #define COMPRESSOR_WATTAGE 85.0
    OneWire oneWire(ONEWIRE);
    DallasTemperature sensors(&oneWire);
    unsigned long runtime = 0, chilltime = 0;
    boolean compressor = false;
    void setup()   {
      // initialize the digital pin as an output:
      pinMode(COMPRESSOR, OUTPUT);
    void loop()
      int i;
      float temperature;
      DeviceAddress addr;
      for(i = 0; i < sensors.getDeviceCount(); i++)
        temperature = sensors.getTempCByIndex(1);
        Serial.print("Current temperature at ");
        sensors.getAddress(addr, 1);
        Serial.print(" is: ");
      if(temperature > HIGHTEMP)
        digitalWrite(COMPRESSOR, HIGH);
          Serial.println("Compressor on");
          compressor = true;
      else if(temperature < LOWTEMP)
        digitalWrite(COMPRESSOR, LOW);
          Serial.println("Compressor off");
          compressor = false;
      delay(SLEEP_SEC * 1000);
      runtime += SLEEP_SEC;
      if(compressor) chilltime += SLEEP_SEC;
      Serial.print("Efficiency: Total runtime = ");
      Serial.print(", Chill time = ");
      Serial.print(" (");
      Serial.print(chilltime * 100 / runtime);
      Serial.print("%, ");
      // The compressor wattage is consumption for an hour, so work
      // out how many hours we've been operating for. Then divide by
      // 1000 to get kWh.
      Serial.print(chilltime * COMPRESSOR_WATTAGE / 3600 / 1000);
    // Function to print a one wire device address
    void printAddress(DeviceAddress deviceAddress)
      for (uint8_t i = 0; i < 8; i++)
        // zero pad the address if necessary
        if (deviceAddress[i] < 16) Serial.print("0");
        Serial.print(deviceAddress[i], HEX);

The code uses the Miles Burton 1-Wire library, which was easy to use once you figure out his example code has an impossible number for the pin. The code outputs information like this over serial:

    Current temperature at 10FA473500000037 is: 21.62
    Efficiency: Total runtime = 1780, Chill time = 1770 (99%, 0.04kWh)

That's with it on my desk where the "compressor" is permanently "on". I'll let you know how we go with further versions.