fridge control (asking for ideas)

Hello. this is the seccond time i have problems with the mechanical thermostat on my fridge, and since they are not that cheap i decided to fix this with an arduino, the reason for this post is that, im not really experienced with arduino and im not an experienced programmer, so im looking forward for sugestions on how to do it..

what i have in my mind is:

  1. temp sensor with lm36
  2. arduino
  3. relay - normal open (mechical or solid state?)

in the code i will set the temp min and max in the range of 3 to 8 Celsius, and have the arduino check this temperature every 10 seconds and make an average every minute (SensedTemp/6)=avgTemp

also, every minute, check avgTemp and:

if its LOWER, turn on green AND yellow leds and STOP_compressor()
if its in the range set a green led on and STOP_compressor()
else, if its higher, START_compressor() and turn on red light

thats the easy and basic part, what im not sure if i need or would be easy to implement is:

  1. turn of compressor if it has been on for X time, and temp still high
  2. dont start it again unless Y time has passed since previous start
  3. call a WTF() function if them is REALLY high for some time (maybe the electricity was cut os something)
  4. allow to "ignore" any of the previous conditions..

well thats all i can think of, what do you people think?

That's all very doable. I can't find any data for an LM36 temp sensor, maybe you meant LM35 or LM34? For your application, I think the LM34 (Fahrenheit) sensor would be better than the LM35 (Celcius) because it provides a greater sensitivity and works without a negative supply voltage at (and even below) around 0degC. You can do the degrees F->C conversion in the Arduino.

For the relay, I would use an SSR, but make sure it's one designed for inductive loads (i.e. with a built-in snubber).

yeah, i meant LM35, sorry.

didnt know about the precision difference within the 34 and the 35, i tought the just did some kind of conversion :S

What I meant was that the LM35 produces 10mv per deg C whereas the LM34 produces 10mV per degree F. The Arduino measures analog inputs with a resolution of about 5mV if using the standard 5v reference. So the LM35+Arduino gives you a resolution of about 0.5 deg C, whereas the LM34+Arduino gives you a resolution of about 0.5 deg F (= 0.28 deg C). You can improve the resolution by using a lower reference voltage (e.g. the 3.3v pin).

Also, the LM35 requires a resistor to a negative voltage supply if you want to measure below +2 deg C, whereas the LM34 is OK down to +5 deg F (= -15C) without that resistor and negative supply.

thanks for that info, i will try to get that version here!

Surely it has GOT to be easier, cheaper and more reliable to use a boring mass-produced mechanical or electrical thermostat rather than build your own using a microcontroller? Nothing wrong with doing this as a fun project if you want, and it needs no more justification than that you want to do it, but if you're taking this approach because you thing it is the most sensible solution to the problem, I'd question your reasoning.

I did not see an electrical one, also i kinda lost my faith in the mechanical thermostat since i had to replace the first in less than a year and the second one might be broken...which makes the fridge work non stop 24/7

Some additional ideas requirements to keep you busy :wink:

    • add a piezo buzzer that sounds if the temperature is above 10C or below freezing. Those buzzers can do a nice morse SOS … — … :wink:
    • add a potmeter to config the temperature e.g. 1…8 C
    • would use a running average for the temperature, is easier .
    • LCD to display status
    • detector if door is open (add a timer to check if door is open too long → alarm )
    • add a RealTime Clock
    • SD card to log all this information
    • stop compressor if temp is too hot for too long (door open too long , compressor broken, etc)

// no complete code but some to get started

int tempConfig = 0;
float alpha = 0.8;
float temperature = 0;
unsigned long lasttime = 0;
bool doorClosed = true; 

void setup()
{
  Serial.begin(115200); // just for debug/development ;)
  temperature = readLM34();  
}

void loop()
{
  state = 0;
  // MEASUREMENT
  tempConfig = readPotMeter();
  temperature = alpha * readLM34() + (1-alpha) * temperature;    // running average -  low pass filter
  doorClosed = readDoor();

  // DISPLAY THE MEASUREMENTS approx once per second
  if (millis() - lasttime > 1000)
  {
    lasttime = millis();
    Serial.print("Config: ");
    Serial.println(tempConfig );
    Serial.print("Temp: ");
    Serial.println(temperature );
    Serial.print("Door: ");
    Serial.println(doorClosed );
  }


  // ACTIONS 
  // ALARM
  if (temperature > 10 || temperature < -1 )  // hardcoded alarm for both too high and too low  
  {
    do_piezo_SOS();
    start_red();
    stop_green();
  } else {
    stop_red();
    start_green();
  }

  // SWITCH COMPRESSOR
  if ( temperature > tempConfig )
  {
    start_compressor();
    start_yellow();
  }
  if ( temperature < tempConfig-1 )  // the -1 takes care that the compressor does not jitters or whatever its called.
  {
    stop_compressor();
    stop_yellow();
  }
}

int readPotmeter()
{
  return 1 + analogRead(POTMETERPIN)/128;  // gives 1..8
}

// returns temp in celsius
float readLM34()
{
  float F = analogRead(LM34PIN) * factor ; // to be elaborated
  return (F-32)/1.8;
}

... additional functions here

robtillaart:
Some additional ideas requirements to keep you busy :wink:

    • add a piezo buzzer that sounds if the temperature is above 10C or below freezing. Those buzzers can do a nice morse SOS ... --- ... :wink:
    • add a potmeter to config the temperature e.g. 1..8 C
    • would use a running average for the temperature, is easier .
    • LCD to display status
    • detector if door is open (add a timer to check if door is open too long -> alarm )
    • add a RealTime Clock
    • SD card to log all this information
    • stop compressor if temp is too hot for too long (door open too long , compressor broken, etc)

// no complete code but some to get started

nice, thanks for that code, it will get me started soon, i have yet to figure what dc24 said about my sensor and the negative voltage,and the farenheit version, which i think it will be almost impossible to get in argentina, im also thinking on buying the one wire sensor, its not cheap here, but it might be a bether option compared to one component i can not find here.

about your ideas, 1) is a good one i did not think in that, 2 could be made with a rotary encoder to have more precise control, but if i put static temps i can not figure any problems, since once i have found the temp i like i dont see any need for changing it...
3) good one too, did not know how to make that, thanks for the code
4) of course!!!
6-7) if its not too expensive i will
8) yes, i have yet to figure how to contemplate weird cases like a few hour with no electricity or if i want to defrost the fridge...after this process end the compressor would need to be on for a few hours non'stop

I did not see an electrical one, also i kinda lost my faith in the mechanical thermostat since i had to replace the first in less than a year and the second one might be broken…which makes the fridge work non stop 24/7

You really need to trouble shoot your refrigerator. Mine kept frosting up, causing it to run all the time and gradually get warm inside. Key parts are the temperature control thermostat, the defrost thermostat, and the defrost timer. I replaced my defrost timer, which didn’t help (you can actually manually turn it inside the refigerator to test, which I didn’t know until I got a new one), then the thermostat, which didn’t help, finally to test the defrost thermostat, which wasn’t working to energize the defrost heater. Replacing the defrost thermostat makes every thing work fine and saved me a lot of $$$ for a repairman or a new fridge. I’ve attached the schematic for my fridge for reference.

zoomkat:

I did not see an electrical one, also i kinda lost my faith in the mechanical thermostat since i had to replace the first in less than a year and the second one might be broken...which makes the fridge work non stop 24/7

You really need to trouble shoot your refrigerator. Mine kept frosting up, causing it to run all the time and gradually get warm inside. Key parts are the temperature control thermostat, the defrost thermostat, and the defrost timer. I replaced my defrost timer, which didn't help (you can actually manually turn it inside the refigerator to test, which I didn't know until I got a new one), then the thermostat, which didn't help, finally to test the defrost thermostat, which wasn't working to energize the defrost heater. Replacing the defrost thermostat makes every thing work fine and saved me a lot of $$$ for a repairman or a new fridge. I've attached the schematic for my fridge for reference.

thanks for your help, sadly my fridge is really basic compared to that, mine has only one thermostat, door light and compressor with a temp sensor on it...no more, no lees. so there is only one part to blame here, also, i do not know if there are any electronic thermostat on the local market, thats why i want to make an arduino version, also it would be a lot easier to debug any problems :stuck_out_tongue:

You don't give a make or model, so you are pretty much on your own (I'm in the US and got my parts on line). I remember when my parents got a refrigerator that actually had a freezer section instead of just a small area in the inside top for ice trays (no place for ice cream or frozen food). Those old refrigerators (like our Gibson) only had a thermostat/off control and had to be turned off ~once a week to defrost the ice tray section.

A DIY frigde temperature control. That is an interesting project. I may have to do that, because the fridge temperature control at the cottage is "not reliable" Heh ! it a 25 year old fridge. I have a old fridge ( from the 1960's or 1970's ) still work pretty good at my place.

@LuisManson

I just bought this part from HVW -- > http://www.hvwtech.com/products_view.asp?ProductID=1215, It does work at temperature lower than 0 Celsius according to the datasheet. You only mesure the output voltage of the sensor, input that voltage into an analog pin, translate into Celsius for display, compare the out voltage point ( temperature setting ) to a potentiometer output voltage point for your turn on/off of the compressor. And please use a strong "biffy" relay rating ( 10 A to 20 A at 250 V AC ) to control the compressor - they have a high current spike when they started.

I think i got my replacement parts from below. Worse case, I'd open up the old thermostat, clean the contacts if still useable, and lube any moving parts. then put it back together (might have to use epoxy).

http://www.partstore.com/Content/CategoryPages/Kitchen-Refrigerators.aspx

Here is my play code, seems to be working just fine:
i have yet to modify this code and the components to add two dioes and a resistence to conform the figure 7 from the datasheet and this code:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1265548225

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!
#define SPKR 10

int pin = 0; // analog pin
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;
int ledPin = 13; 
int TempMax = 35;
int TempMin = 28;

void setup()
{
  Serial.begin(9600); // start serial communication
  pinMode(ledPin, OUTPUT);
  analogReference(EXTERNAL);
  pinMode(SPKR, OUTPUT);
}

void loop()
{
 
digitalWrite(ledPin, HIGH); 
for(i=0; i<=7;i++){ // gets 8 samples of temperature
 
  samples[i] = ( aref_voltage * analogRead(pin) * 100.0) / 1024.0;
  tempc = tempc + samples[i];
  delay(1000);

}
digitalWrite(ledPin, LOW);    // sets the LED off
  

tempc = tempc/8.0; // better precision
tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit

if(tempc > maxi) {maxi = tempc;} // set max temperature
if(tempc < mini) {mini = tempc;} // set min temperature

Serial.print(tempc,DEC);
Serial.print(" Celsius, ");

Serial.print(analogRead(pin),DEC);
Serial.print(" lect -> ");

Serial.print(maxi,DEC);
Serial.print(" Max, ");
Serial.print(mini,DEC);
Serial.println(" Min");
if ( tempc > TempMax )
  {
    Serial.println(" Alert MAX");
    beep1();
  }

if ( tempc < TempMin )
  {
    Serial.println(" Alert MIN");
    beep2();
  }


tempc = 0;

delay(500); // delay before loop
}


// beep 1,2 y 3

void beep1()
{

for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
  digitalWrite(SPKR, HIGH);
  delayMicroseconds(250);
  digitalWrite(SPKR, LOW);
  delayMicroseconds(250);
  }
}


void beep2()
{
for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
  digitalWrite(SPKR, HIGH);
  delayMicroseconds(250);
  digitalWrite(SPKR, LOW);
  delayMicroseconds(500);
  }
}

void beep3()
{
for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
  digitalWrite(SPKR, HIGH);
  delayMicroseconds(500);
  digitalWrite(SPKR, LOW);
  delayMicroseconds(500);
  }
}

// FIN beep 1,2 y 3

zoomkat, the fridge is a Peabody, its VERY basic like most fridges here in Argentina, the thermostar is: rc24522 PDF: http://mail4.ansal.com.ar/Documentacion/pdfs/490062.pdf weird thing is it states "normal position, desconection: -23 because -23 is very low, and the capillar goes into the fridge, not the freezer
Also, the fridge i have does not exist in the place you pointed me at :frowning:

Techone: i will go for the 18b20, since i can find it here :smiley:

With regard to temperature sensors - I'd avoid the LM35! I bought a bunch of them and found them to be a real pain. I never got the same result twice so had to take an average. I then tried the Dallas DS18B20 digital temperature based on gmcmicken's recommendation and was impressed!

From the datasheet: It has an operating temperature range of -55°C to +125°C and is accurate to
±0.5°C over the range of -10°C to +85°C.

They also have up to 9-12bit resolution and are a doddle to use with the Temperature library.

OneWire oneWire(7);
DallasTemperature sensors(&oneWire);
DeviceAddress thermometerAddress;

void setup()
{
	
	// Begin temperature sensors
	sensors.begin();
	sensors.getAddress(thermometerAddress, 0);

	Serial.begin(9600);

}

void loop()
{
	char msg[8];

	// Retrieve temperature
	sensors.requestTemperatures();

	// Convert temperature to string with 1 decimal place
	dtostrf(sensors.getTempC(thermometerAddress), 0, 1, msg);

	Serial.println(msg);

}

thanks supercrab, thats the one i think i might be able to get somewhere :smiley:

You won't be disappointed with the Dallas DS18B20 :slight_smile: It's about the same price as the LM35, only requires 3 connections (or 2 if powered in parasite mode) and because it uses the one wire protocol you could have any number on the same input pin. You could also have another sensor outside the fridge so if it's a hot day outside it could detect this and make extra ice! Also, add an ethernet shield and log the temperature and send you a text if something's gone wrong and it's got too warm inside! You don't want your food defrosting! You could also use the Prowl App on your iPhone with some PHP code to send you push notifications! 8)

lol, i will get that sensor, i hope i could buy some shield, im currently looking on a DIY SD shield just to log, this kind of stuff is not very affordable here :S

seems like the fridge temp is near 13C...maybe its running low in gas