Home Brew Forums > Home Brewing Beer > DIY Projects > Fermenters > My arduino fridge control build.
Reply
 
Thread Tools
Old 01-09-2009, 05:29 AM   #1
simpleton
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2008
Location: Texas
Posts: 31
Default My arduino fridge control build.

Howdy folk, I've been working on setting up an arduino to manage the temp in my fridge and I thought I would chronicle my adventure. What I have is rough but I think it will work. My setup is as follows:


1 x Arduino clone(freeduino, works the same)
1 x LM35 temp sensor
1 x P2N2222A transistor
1 x 1N4004 diode
1 x 1K resistor
1 x PB134005 relay

I'll post the schematic if someone needs it.

The LM35 output goes to analog 0
The relay for the fridge is on pin 13


Here is my arduino code.

float tempC;
float tempF;
int tempPin = 0;
int ledPin = 13;

void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps

}

void loop()
{
tempC = analogRead(tempPin); //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0; //convert the analog data to temperature
tempF = (tempC * 9)/ 5 + 32; // converts to fahrenheit
Serial.print ((int) tempC ); //send the data to the computer

Serial.print(" Celsius, ");
Serial.print ((int) tempF ); //send the data to the computer
Serial.print(" Fahrenheit, -> ");
delay(1000); //wait one second before sending new data
digitalWrite(ledPin, HIGH); // sets the LED on

if (tempF < 71) digitalWrite(ledPin, HIGH);
if (tempF < 71) Serial.println ("fridge on");
if (tempF > 69) digitalWrite(ledPin, LOW);
if (tempF > 69) Serial.println ("fridge off");


This code was stolen from a number of arduino forums, mixed and matched, and then further mangled by me. I am not a programmer. Eventually I would like to have a computer log temprature, compresser state, and be able to adjust the min and max temp, and make all of this via a web page. For now I just need it to hold my fridge at 70F.

Next will be building temp probes like in Yuri's howto then wiring the relay into my fridge.


Simpleton


simpleton is offline
 
Reply With Quote
Old 01-09-2009, 03:50 PM   #2
Brewers Hardware
Sponsor
HBT_SPONSOR.png
Vendor Ads 
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2008
Location: Huntington Beach, CA, 92649
Posts: 455
Liked 6 Times on 5 Posts

Default

Nice. Do you have this working? I'm doing something similar with an Arduino to control my brewery. I found that the LM34's needed to have a resistor-capacitor for remote sensing. You may discover the same with the LM35.


Brewers Hardware is offline
 
Reply With Quote
Old 01-09-2009, 04:00 PM   #3
Brewers Hardware
Sponsor
HBT_SPONSOR.png
Vendor Ads 
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2008
Location: Huntington Beach, CA, 92649
Posts: 455
Liked 6 Times on 5 Posts

Default

oops. This line of code here:

Code:
digitalWrite(ledPin, HIGH); // sets the LED on
Is going to turn your fridge on as well since you're using pin13 for the fridge. Also, since you're controlling a fridge compressor you should add a short-cycle delay to prevent slugging the compressor.
Brewers Hardware is offline
 
Reply With Quote
Old 01-09-2009, 04:40 PM   #4
simpleton
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2008
Location: Texas
Posts: 31
Default

Yeah, I noticed that this morning. There are a couple of other things I need to fix. After looking at it for hours last night I stared missing obvious things. It also looks like I have the fridge on/off backwards.... Doh!
simpleton is offline
 
Reply With Quote
Old 01-09-2009, 05:40 PM   #5
Brewers Hardware
Sponsor
HBT_SPONSOR.png
Vendor Ads 
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2008
Location: Huntington Beach, CA, 92649
Posts: 455
Liked 6 Times on 5 Posts

Default

For some reason I couldn't let go of this. I started thinking about how I would do it and thought well this is so simple I'll just bang out some code. Turns out there was a little more too it than I thought by adding the short-cycle delay and also reducing the output to the serial. While the computer will have no problem accepting a stream of data every second, it's overkill and a gets hard to read, so I increased it to 10 seconds.

That brought up another problem though of accepting a setpoint if the program was delaying 10 seconds every cycle. So I thought interrupts might be an ideal way to handle this. If you wire two momentary switches on pins 2 and 3 (must be 2 and 3 as these are interrupts 0 and 1) to ground, you can depress either button at anytime to increment or decrement the setpoint. At least I think so. I compiled and uploaded this code and tested it, but my interrupts are hooked up to a rotary encoder and one is always low so I couldn't test that portion. It's commented out.

The short cycle looks like it works just fine. My LM34 temp probes are not near me so I just let the input float to test it. I adapted this from my contoller, so there might be extra variables or code that aren't needed....
Code:
#define relayPin 12
#define tempUpPin 2
#define tempDownPin 3
#define ledPin 12
#define tempPin 0


float tempC;
float tempF;
int setPoint = 70;                            // Initializes set point at 70*
long time = 0;
long offTime = 0;
boolean relayOn = false;

void setup()
{
Serial.begin(9600);                           //opens serial port, sets data rate to 9600 bps
pinMode (relayPin, OUTPUT);
pinMode (ledPin, OUTPUT);
pinMode (tempUpPin, INPUT);
pinMode (tempDownPin, INPUT); 
digitalWrite (tempUpPin, HIGH);              // turn on internal pull-up resistor
digitalWrite (tempDownPin, HIGH);            // turn on internal pull-up resistor
//attachInterrupt (0, doTempUp, LOW);          // attach interrupt 0 on pin2 to doTempUp 
//attachInterrupt (1, doTempDown, LOW);        // attach interrupt 1 on pin3 to do temp down

}// end setup

void loop()
{
tempC = analogRead(tempPin);                   //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;          //convert the analog data to temperature
tempF = (tempC * 9)/ 5 + 32;                   // converts to fahrenheit
Serial.print ((int) tempC );                   //send the data to the computer

Serial.print(" Celsius, ");
Serial.print ((int) tempF );                   //send the data to the computer
Serial.print(" Fahrenheit, -> ");
Serial.print (" Current Setpoint -> ");
Serial.print (setPoint);
time = millis() / 1000;                                 // Sets time to the current total program runtime in seconds.  
if (tempF > setPoint ) {                                // Compare temp: Temperature is above setpoint
  if ( time - offTime > 300)  {                         // Check to confirm compressor has been off at least 5 minutes set to # of seconds
  digitalWrite( relayPin, HIGH);                        // Turn fridge on
  Serial.print (" fridge on ");
  relayOn = true;
  }
  else {                                                // 5 minute delay is not over
    Serial.print (" Short-cycle delay enabled ");
    }
  }    
else  {                                                 // Temperature is below setpoint
  if (relayOn)  {                                       // Confirm relay is currently on
    digitalWrite( relayPin, LOW);                       // Turn fridge Burner Off.
    Serial.println (" fridge off ");
    relayOn = false;                                    // Set HLT Burner Status to off
    offTime = time;                                     // Time stamps the off time for Burner.
  }
}
Serial.println();  
delay(10000);                                   //wait ten seconds before sending new data

}// end loop
/*
void doTempUp() {
  setPoint ++;                                          // increment setpoint by 1
  Serial.print ("New Setpoint -> ");                    // display to serial  
  Serial.println (setPoint);                                    
  delay (2000);                                          // allow 2 seconds to read message
}// end doTempUp

void doTempDown() {
  setPoint --;                                          // deincrement setpoint by 1
  Serial.print ("New Setpoint -> ");                    // display to serial  
  Serial.println (setPoint);                                    
  delay (2000);                                          // allow 2 seconds to read message
}// end doTempDown
*/



Brewers Hardware is offline
 
Reply With Quote
Reply


Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arduino Stir Plate (digital speed control) Yuri_Rage Chillers and Stir Plates 14 10-16-2014 02:13 AM
Gonna build an Electric Boiler...how to control? ApolloSpeed Brew Stands 55 04-22-2011 08:30 PM
BrewTroller Control Panel Build jcdillin Brew Stands 79 07-20-2010 11:35 AM
Arduino for kegerator temperature control. Orfy Kegerators and Keezers 19 04-21-2010 12:18 PM
Fridge temp control..... EamusCatuli Equipment/Sanitation 9 11-21-2008 02:35 AM


Forum Jump

Newest Threads

LATEST SPONSOR DEALS