G'Day Gang,
I have just finalised the Arduino code to run a 12v bilge pump to circulate fish tank water through a modified solar collector. (I replaced copper with poly tubeing) I am using DS18B20 one wire temp sensors to check fish tank temp and differential temp between solar discharge and inlet to collector. I will feed the PWM signal to a MOSFET to run the pump.
I am going to upgrade the LCD to a 20x4 so I can fit more info to see how the system is running.
When I have the whole system running I will post an update.
Cheers
Dennis
Note: if you intend to use this code you will need to adjust the delay to suit your system.
Code:
/*
Thanks to http://www.hobbytronics.co.uk for help with differential temp and onewire setup.
Thanks to the gang at http://forum.arduino.cc (Special thanks to PaulS)for help with PWM
control issues.
Also Jeremy Blum's Tutorials http://www.jeremyblum.com
*/
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
byte degree[8] = { //Degree character
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
};
int backLight = 13; // pin 13 will control the backlight
// Data wire is plugged into pin 7 on the Arduino
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
const int motorPin = 9;
int i = 65;
void setup(void)
{
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.createChar(0, degree); //Create Degree character
pinMode(motorPin, OUTPUT);
Serial.begin(9600); // start serial port
sensors.begin(); // Start up the library
}
void loop()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
int SolarTemp = sensors.getTempCByIndex(0);
int PondTemp = sensors.getTempCByIndex(1);
int CompareTemps = (SolarTemp - PondTemp); // Collector temp compared to Pond Temp
int val = i; //Store last motorPin value
int pct = map(i,0,255,0,100); //Calculate PWM percentage
Serial.print("SolarTemp ");
Serial.print(SolarTemp);
Serial.print(" PondTemp ");
Serial.print(PondTemp);
if (PondTemp >= 25)
{
if(i > 0)
{
i = 0;
}
analogWrite (motorPin, i);
Serial.print (" Set Temp Achieved "); //If pond temp 25Deg or higher turn pump off.
}
else if (CompareTemps > 13) /* If collector 13Deg higher than inlet
...increase motor speed by 10
*/
{
if(i <= 245)
{
i = i + 10;
}
analogWrite (motorPin, i);
Serial.print(" Pump Increasing ");
}
else if ((CompareTemps > 10) && (CompareTemps <= 13) && (i >75)) /*If SolarTemp not changing more
than 3Deg , don't increase
or decrease speed.
*/
{
if (i <= 255)
{
i = val;
}
analogWrite (motorPin, i);
Serial.print(" Pump Stable ");
}
else if ((CompareTemps >= 7) && (CompareTemps <= 10) && (i >75)) /*If temp difference less than 10
but greater than 7 Decrease
motor speed by 10
*/
{
{
i = i - 10;
}
analogWrite (motorPin, i);
Serial.print(" Pump Decreasing ");
}
else if (CompareTemps >= 5 ) /*If collector temp 5Deg higher than inlet temp
then Start Motor at 25%
*/
{
analogWrite (motorPin, i = 65);
Serial.print(" Pump Minimum ");
}
else
{
{
i = 0;
}
analogWrite (motorPin, i);
Serial.print(" Pump Off ");
}
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Pond Temp "); // Print Pond Temp
lcd.print(PondTemp);
lcd.write((byte)0);
lcd.print("C");
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print("Pump Speed "); // Pump Speed
lcd.print(pct);
lcd.print("%");
Serial.print(pct); // Print PWM percentage (Thanks wildbill)
Serial.println("%");
Serial.println();
delay (1000);
}