⚠️ This forum has been restored as a read-only archive so the knowledge shared by the community over many years remains available. New registrations and posting are disabled.

All times are UTC + 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sep 21st, '13, 16:33 
Xtreme Contributor
Xtreme Contributor
User avatar

Joined: Jan 25th, '09, 16:50
Posts: 224
Gender: Male
Location: Bindoon Western Australia
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);
 
}


Top
 Profile  
Reply with quote  
    Advertisement
 
PostPosted: Nov 6th, '13, 00:23 
Newbie
Newbie

Joined: Sep 19th, '13, 02:49
Posts: 30
Gender: Male
Are you human?: YES
Location: Utrecht, Netherlands
Looks like some nice Sketch code! Are these algorithms working? Did you have to make any adjustments?

Any photos of the final kit?

I am curious how you wired everything up with the onewire sensors.

As i understand your code, you are using Digital Pin 7 to control the OneWire temperature sensors. Normally onewire works with a unique mac address of each onewire device. You seem to be referencing them as 0 and 1.

I have been using the http://owfs.org libraries with the Raspberry Pi and a Dallas DS2482 i2c to 1Wire bridge. It renders the 1W devices as directories with the ID as the directory name. I really like all the Dallas 1W sensors!

Great stuff Curnow!


Top
 Profile  
Reply with quote  
PostPosted: Nov 6th, '13, 06:50 
Xtreme Contributor
Xtreme Contributor
User avatar

Joined: Jan 25th, '09, 16:50
Posts: 224
Gender: Male
Location: Bindoon Western Australia
GDay,

The one thing I do need to do is add some error handling. The basic code works well but reverts to 0% if it gets a false reading. It then ramps up again. I still have it running on a breadboard and I think there some spike issues that gives the false readings.
I am out of the loop a bit at the moment as we have started harvesting. I will have a bit more time in 5 or so weeks.

Cheers
Dennis


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 8 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group
Portal by phpBB3 Portal © phpBB Türkiye
[ Time : 0.036s | 13 Queries | GZIP : Off ]