All times are UTC + 8 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mar 5th, '14, 08:55 
Newbie
Newbie
User avatar

Joined: Sep 9th, '13, 09:28
Posts: 14
Gender: Male
Are you human?: Only after coffee.
Location: Werribee, Victoria, Australia
I have been running a solar powered system for the last eighteen months and have recently updated the Arduino based control system to switch up to four pumps (I only use two currently) and monitor the solar panel output to detect nighttime.

The circuit of the daughter board:

Image


Arduino code:

Code:
/* Two Pump Aquaponics Control with Night Detection
 
 Turns on and off two pumps connected to FET interfaces on D12 and D13.
 Changes the off time if no PV charge is occurring.
 
 The circuit:
 * FET Switches interface attached to pin 10 to 13.
 * Day Program indicator LED attached to pin 8.
 * Night Program indicator LED attached to pin 9.
 * Voltage sample of PV cell attached to A5
 * Voltage sample of Battery voltage attached to A4
 
 Originally based on the public domain BlinkWithoutDelay
 created 2005
 by David A. Mellis
 modified Oct13
 by Shane Duggan
 
 
 */

// Constants
// set pin numbers:
#define  Pump_One        13           // FET #1 control pin
#define  Pump_Two        12           // FET #2 control pin
#define  Pump_Three      11           // FET #3 control pin
#define  Pump_Four       10           // FET #4 control pin
#define  Night_LED        8           // Night cycle indicator control Pin
#define  Day_LED          9           // Day cycle indicator control Pin
#define  BATT_V          A4           //Assign A4 to monitor supplied DC voltage
#define  PV_IN           A5           //Assign A5 to the PV cell input


// Variables:
int PumpState = LOW;              // PumpState used to switch pump
int Current_Pump = Pump_One;      //Start with Pump 1

//Timing variables
long previousMillis = 0;         // will store last time LED was updated
unsigned long onmillis = 0;
unsigned long offmillis = 0;

int ontime = 8;              // On time in minutes
int offtime = 7;             //Off time in minutes
int nightontime = 8;         //On time for night operation
int nightofftime = 22;        //Off time for night operation


byte DayTime = true;            //Flag to show if PV voltage is previously detected

int nightlevel = 11;
int daylevel = 12;

float PV_Volt = 0.0;            //The output voltage of the PV cell at pin A0
float Batt_Volt = 0.0;

void setup() {

  pinMode(Pump_One, OUTPUT);      //Pump_One is an output
  pinMode(Pump_Two, OUTPUT);      //Pump_Two is an output
  pinMode(Night_LED,OUTPUT);
  pinMode(Day_LED,OUTPUT);
  pinMode(PV_IN, INPUT);        //PV_IN is an input
  pinMode(BATT_V,INPUT);

  Serial.begin(9600);         //Set serial comms at 9600 Baud for debugging

  onmillis = 60000 * ontime;      //Convert on time minutes to millis
  offmillis = 60000 * offtime;      //Convert off time minutes to millis

  Current_Pump = Pump_One;              //Initially turn on pump
  PumpState = HIGH;
  digitalWrite(Current_Pump, PumpState);
 
  digitalWrite(Day_LED, HIGH);
  digitalWrite(Night_LED, LOW);
}

void loop()
{

  unsigned long currentMillis = millis();


  PV_Volt=((1023-analogRead(PV_IN))*.058)+3.5;      //Read the LDR_Volt input and covert to voltage representation
  Batt_Volt=((1023-analogRead(BATT_V))*.058)+3.5;   //Read the supplied DC volt input and covert to voltage representation
 
 Serial.print("Batt Voltage: ");          //debug
  Serial.print(Batt_Volt, DEC);          //debug
  Serial.print("  PV Voltage: ");          //debug
  Serial.println(PV_Volt, DEC);          //debug

  // If we are not getting any charge from the PV Cell ie night time, lengthen the off time to conserve battery voltage.
 
  if ((DayTime == true) && (PV_Volt < nightlevel)){
    offmillis = (60000 * nightofftime);
    onmillis = (60000 * nightontime);
    DayTime = false;
    digitalWrite(Day_LED, LOW);
    digitalWrite(Night_LED, HIGH);
  }
  else{
    if ((DayTime == false) && (PV_Volt > daylevel)){
      offmillis = 60000 * offtime;
      onmillis = 60000 * ontime;
      DayTime = true;
      digitalWrite(Day_LED, HIGH);
      digitalWrite(Night_LED, LOW);
    }
  }


  // Check to see that the currentMillis has not counted out
  if (currentMillis < previousMillis) {
    previousMillis = 0;
  }


  // if the Pump is off turn it on and vice-versa:
  if (PumpState == LOW){
    if (currentMillis - previousMillis >= offmillis){
      previousMillis = currentMillis;
      PumpState = HIGH;
 
      // set the pump with the PumpState of the variable:
      digitalWrite(Current_Pump, PumpState);
    }
  }
  else if (PumpState == HIGH){
    if (currentMillis - previousMillis >= onmillis){
      previousMillis = currentMillis;
      PumpState = LOW;
 
      // set the pump with the PumpState of the variable:
      digitalWrite(Current_Pump, PumpState);

      //Toggle pump control to the other pump
      if (Current_Pump == Pump_One){
        Current_Pump = Pump_Two;
      }
      else{
        Current_Pump = Pump_One;
      } 

    }
  }
}





Cheers

Shane


Top
 Profile  
Reply with quote  
    Advertisement
 
PostPosted: Mar 5th, '14, 10:20 
Bordering on Legend
Bordering on Legend
User avatar

Joined: Feb 22nd, '13, 04:35
Posts: 276
Gender: Male
Are you human?: yes
Location: Oklahoma, USA
I am just starting my arduino research to learn to control my AP system.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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.047s | 13 Queries | GZIP : Off ]