@alwaysared
Fridge Fans
If uses a Arduino Uno, Dallas Temp Sensor, Liquid Crystal Display, Relay Board, Three Fans and a Switch with 4 positions
Code is simple enough and nice thing about Arduino is the bits and pieces are not expensive. Arduino software is free and works on IMac, Linux and Windows. Ideal if you want something to have a play with. The four position switch is to switch it off, Automatic, Fans Minimum, Fans Maximum. I always like to have a backup plan just in case something packs up I can switch the fans on manually. Winter project 3 years ago.
This is the code I have running at the moment.
#include <DallasTemperature.h>
#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
// Define Relay Ports and I/O ports for relays
#define relay1 6
#define relay2 7
#define BUS 2
OneWire oneWire(BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x3F for a 16 chars and 2 line display
// Define Variables
int show;
int i,v;
int probe;
void setup() // Start setup for UNO Board
{
sensors.begin();
Wire.begin();
Wire.beginTransmission(0x3F);
i = 20; // Set any temp to start
// Initalize the lcd
lcd.begin(16, 2);
lcd.home(); lcd.clear();
lcd.print("FRIDGE TEMP");
displayTemp(i);
// Setup the relay pins for driving relays and switch fans off
pinMode(relay1,OUTPUT);
digitalWrite(relay1,HIGH);
pinMode(relay2,OUTPUT);
digitalWrite(relay2,HIGH);
// fanState(3); // Used to update display
} // end setup()
void loop() // Start of Main Program
{
// Display flashs so we only change the display when we have to
v = checkSensor(); // get the Temp
if ( v != i ) // if v and i are different then the temp has changed
{
// Ok v is different to i so set i for next time we check;
i = v;
displayTemp(i);
// Work out what the temp is and act accordingly
if ( i < 25 ) { fanState(3); }
if (( i > 24 ) && ( i < 30 )) { fanState(1); }
if ( i > 29 ) { fanState(2); }
} // end if statement temp different
delay ( 5000 ); // not necessary to check every couple of seconds
} // End void loop()
int checkSensor()
{
sensors.requestTemperatures(); // Ask nicely for temperature
delay(50);
return sensors.getTempCByIndex(0); // Return with temp
} //end checkSensor
int displayTemp(int i) // Sets up and displays temp
{
lcd.setCursor(12,0);
lcd.print(" ");
lcd.setCursor(12,0);
lcd.print(i);
lcd.write(223); // Degree Symbol
lcd.print("C");
} //end displayTemp
int fanState(int i) // Display and Set FAN State 1 - 3
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
switch (i) {
case 1:
lcd.print("FANS MINIMUM");
digitalWrite(relay1,LOW);
digitalWrite(relay2,HIGH);
break;
case 2:
lcd.print("FANS MAXIMUM");
digitalWrite(relay1,HIGH);
digitalWrite(relay2,LOW);
break;
case 3:
lcd.print("FANS OFF");
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
break;
break;
}
} //end fanState