Hunter X's Arduino Whole Tank Controller (52K Warning) - Page 11
Planted Tank Forums
Your Tanks Image Hosting *Tank Tracker * Plant Profiles Fish Profiles Planted Tank Guide Photo Gallery Articles

Go Back   The Planted Tank Forum > Specific Aspects of a Planted Tank > DIY


Reply
 
Thread Tools Display Modes
Old 03-20-2014, 02:15 AM   #151
Bryanmc1988
Planted Tank Enthusiast
 
PTrader: (34/100%)
Join Date: Apr 2012
Location: San Diego - CA
Posts: 877
Default

i would like to take a look at this code also if you dont mind sharing... i can take a look and see how this code is constructed...
Bryanmc1988 is online now   Reply With Quote
Sponsored Links
Advertisement
 
Old 03-21-2014, 08:53 AM   #152
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by Fluffles View Post
Thanks everyone!



That would be great! It would be great to see how you approached buttons and LEDs, scheduling, and dosing. I can also share my code if you're interested, but it's still in very early stages.

Right now my code can only keep track of buttons status so there's not much work done with scheduling yet. I'm trying to make it so that each button has 3 states: ON-OFF-AUTO

If a button is depressed, it will turn the relay OFF and LED OFF.
If a button is pressed once, it will turn the relay ON and LED ON
When a button is pressed for a second time, it will allow the relay to enter AUTO mode and let the scheduler take over. But how do you know that relay is in AUTO? The button LED will blink on and off once a second.
In short a button will work like this: ON-OFF-AUTO-OFF-ON-OFF-AUTO...etc
It's been a pain to code, but I think I finally have it working. This should give me absolute control over each relay no matter what the scheduler is trying to do.
Sorry for not replying sooner. I have been TDY with the Army. Now I'm back to Kuwait so this evening I should be able to send my code out. It's complete with the exception of the LED controls. I don't have anything here to trouble shot that so I will wait until I get home.

Fluffles,

You are way over programming those buttons. I'll show you how simple it can be by using booleans. You are going to laugh at how much easier it will be.
HunterX is offline   Reply With Quote
Old 03-21-2014, 08:54 AM   #153
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

I will post my code here so everyone can take a look at it!
HunterX is offline   Reply With Quote
Old 03-21-2014, 03:45 PM   #154
Bryanmc1988
Planted Tank Enthusiast
 
PTrader: (34/100%)
Join Date: Apr 2012
Location: San Diego - CA
Posts: 877
Default

what board are you using for your setup?
Bryanmc1988 is online now   Reply With Quote
Old 03-21-2014, 05:57 PM   #155
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by Bryanmc1988 View Post
what board are you using for your setup?
Mega. The parst list in included in post #13.
HunterX is offline   Reply With Quote
Old 03-21-2014, 06:57 PM   #156
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default Tank Code

Here it is. Enjoy.

Code:
#include <Wire.h>
#include <RealTimeClockDS1307.h> //RealTimeClock RTC;//=new RealTimeClock();
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <elapsedMillis.h>

#define ONE_WIRE_BUS 2 // Temp Sensor Connected to Pin 2 //
#define Display_Clock_Every_N_Seconds 1
#define Display_ShortHelp_Every_N_Seconds 25
//#define TEST_Squarewave
//#define TEST_StopStart
//#define TEST_1224Switch

// Set up a oneWire instance to communicate with any OneWire device//
OneWire ourWire(ONE_WIRE_BUS);

// Tell Dallas Temperature Library to use oneWire Library //
DallasTemperature sensors(&ourWire);

// Define Address for each Tempatature Sensor//
DeviceAddress Probe01 = { 0x28, 0x54, 0xF2, 0x04, 0x05, 0x00, 0x00, 0xF2 }; //box temp address//
DeviceAddress Probe02 = { 0x28, 0x73, 0x05, 0x21, 0x05, 0x00, 0x00, 0xC7 }; //tank temp address//

int count = 0;

int relay1 = 45; // relay 1 connected to digital pin 45 FILTER
int relay2 = 44; // relay 2 connected to digital pin 44 FILTER
int relay3 = 43; // relay 3 connected to digital pin 43 POWERHEAD
int relay4 = 42; // relay 4 connected to digital pin 42 POWERHEAD
int relay5 = 41; // relay 5 connected to digital pin 41 HEATER 
int relay6 = 40; // relay 6 connected to digital pin 40 AIR PUMP
int relay7 = 39; // relay 7 connected to digital pin 39 CO2
int relay8 = 38; // relay 8 connected to digital pin 38

int buttonLed1 = 22; // button 1 LED connected to digital pin 22  All use a 220 Ohm resistor
int buttonLed2 = 23; // button 2 LED connected to digital pin 23
int buttonLed3 = 24; // button 3 LED connected to digital pin 24
int buttonLed4 = 25; // button 4 LED connected to digital pin 25
int buttonLed5 = 26; // button 5 LED connected to digital pin 26
int buttonLed6 = 27; // button 6 LED connected to digital pin 27
int buttonLed7 = 28; // button 7 LED connected to digital pin 28
int buttonLed8 = 29; // button 8 LED connected to digital pin 29
int interuptLed1 = 48; //system interupt led connected to digital pin 48
int interuptLed2 = 49; // light interupt led connected to digital pin 49

int button1 = 30; // button 1 connected to digital pin 30  All use a 10K Ohm Resistor
int button2 = 31; // button 2 connected to digital pin 31
int button3 = 32; // button 3 connected to digital pin 32
int button4 = 33; // button 4 connected to digital pin 33
int button5 = 34; // button 5 connected to digital pin 34
int button6 = 35; // button 6 connected to digital pin 35
int button7 = 36; // button 7 connected to digital pin 36
int button8 = 37; // button 8 connected to digital pin 37
int button9 = 46; // system interupt button connected to digital pin 46
int button10 = 47; // light interupt button connected to digital pin 47

int macro1 = 14;   // dc motor 1 connectd to digital pin 30 - MACRO FERTS
int micro2 = 15;   // dc motor 1 connectd to digital pin 31 - MICRO FERTS
int fe3 = 16; // dc motor 1 connectd to digital pin 32 - FE FERTS
int fan4 = 17;   // dc motor 1 connectd to digital pin 33 - BOX Cooling Fan

int led1 = 8;  //led tank lights 1 connnected to PWM pin 8   Warm White 3200K (growth spectrum)
int led2 = 9;  //led tank lights 2 connnected to PWM pin 9   Cool WHite 6500K (base white spectrum)
int led3 = 10; //led tank lights 3 connnected to PWM pin 10  Deep Red / Royal Blue (enhanced growth and color)
int led4 = 11; //led tank lights 4 connnected to PWM pin 11  Cool WHite 6500K (base white spectrum)
int led5 = 12; //led tank lights 5 connnected to PWM pin 12  Warm White 3200K (growth spectrum)

//elapsedMillis timer0;
//#define interval 30000

char formatted[] = "00-00-00 00:00:00x";
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

boolean feeding = false;         // boolean used to tell system if feeding or not
boolean systemInterupt = false;  // boolean used to tell if system interupt button is pressed
boolean lightInterupt = false;   // boolean used to tell if light interupt button is pressed
boolean butt1 = false;           // boolean used to tell if button 1 is pressed
boolean butt2 = false;           // boolean used to tell if button 2 is pressed
boolean butt3 = false;           // boolean used to tell if button 3 is pressed 
boolean butt4 = false;           // boolean used to tell if button 4 is pressed
boolean butt5 = false;           // boolean used to tell if button 5 is pressed
boolean butt6 = false;           // boolean used to tell if button 6 is pressed
boolean butt7 = false;           // boolean used to tell if button 7 is pressed
boolean butt8 = false;           // boolean used to tell if button 8 is pressed

////////////////////////////////////////////////
//                SETUP BEGINS                //
////////////////////////////////////////////////

void setup()
{
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(relay5, OUTPUT);
  pinMode(relay6, OUTPUT);
  pinMode(relay7, OUTPUT);
  pinMode(relay8, OUTPUT); 
  
  pinMode(macro1, OUTPUT);
  pinMode(micro2, OUTPUT);
  pinMode(fe3, OUTPUT);
  pinMode(fan4, OUTPUT); 
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  
  pinMode(buttonLed1, OUTPUT);
  pinMode(buttonLed2, OUTPUT);
  pinMode(buttonLed3, OUTPUT);
  pinMode(buttonLed4, OUTPUT);
  pinMode(buttonLed5, OUTPUT);
  pinMode(buttonLed6, OUTPUT);
  pinMode(buttonLed7, OUTPUT);
  pinMode(buttonLed8, OUTPUT);
  pinMode(interuptLed1, OUTPUT);
  pinMode(interuptLed2, OUTPUT);
  
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
  pinMode(button5, INPUT);
  pinMode(button6, INPUT);
  pinMode(button7, INPUT);
  pinMode(button8, INPUT);  
  pinMode(button9, INPUT);
  pinMode(button10,INPUT); 
  
 
  
  digitalWrite(relay1, HIGH); // Wired as normally closed //
  digitalWrite(relay2, HIGH); // Wired as normally closed //
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
  digitalWrite(relay5, HIGH);
  digitalWrite(relay6, HIGH);
  digitalWrite(relay7, HIGH);
  digitalWrite(relay8, HIGH);  

  sensors.begin();
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  Wire.begin();
  Serial.begin(9600);  
  lcd.begin(20,4);          //initialize LCD for 20 CHAR 4 lines, turn on backlight
  
  for(int i = 0; i< 3; i++) //3 quick blinks of backlight
    {
      lcd.backlight();
      delay(250);
      lcd.noBacklight();
      delay(250);
    }  
  lcd.backlight();         // finish with back light on
  
  lcd.setCursor(3,1);      //Start character 3 on line 1
  lcd.print("Darrin's Tank");
  delay(1000);
  lcd.setCursor(2,2);
  lcd.print("Controller 1.0");
  delay(4000); 
  lcd.clear();   
}

/////////////////////////////////////////////////
//                LOOP BEGINS                  //
/////////////////////////////////////////////////
 
void loop() 
{    
  RTC.readClock(); 
  
  //******************* display time on lcd +++++++++++++++++++++++++ 
  lcd.setCursor(8,3);
  if (RTC.getHours()<10)         //adds a "0" in front of all numbers less than 10
    {     
    lcd.print(0);
    }
  lcd.print(RTC.getHours());     //gets hour from RTC and displays on LCD    
  lcd.setCursor(10,3); 
  lcd.print(":");
  lcd.setCursor(11,3);
  if (RTC.getMinutes()<10)       //adds a "0" in front of all numbers less than 10
    {
    lcd.print(0);
    }
  lcd.print(RTC.getMinutes());   //gets minutes from RTC and displays on LCD
 
  //++++++++++++++++++ displays temp on LCD ++++++++++++++++++++++++++
  sensors.requestTemperatures();  // Send the command to get temperatures
  float temperature1 = sensors.getTempFByIndex(1); // Tank Temp
  float temperature0 = sensors.getTempFByIndex(0); // Box Temp  
  lcd.setCursor(0,0);
  lcd.print("H2O:");
  lcd.setCursor(4,0);    
  lcd.print(temperature1);  //displays TANK temp in F on LCD
  lcd.setCursor(0,1);
  lcd.print("Box:");
  lcd.setCursor(4,1);  
  lcd.print(temperature0);   //displays BOX temp in F on LCD
  
  //+++++++++++++++++++ functions ++++++++++++++++++++++++++++++++++++
    //heater();      //function used to display "HEATING" when relay5 (heater) is on
    sysInterupt(); 
    liteInterupt(); 
    
  //++++++++++++++++++ setup relay/outlet timers ++++++++++++++++++++
  //++++ Relay 1,2 will always be on and do not need a timer ++++++++
  //++++ Relay 4 is controlled by temp; does not need timer +++++++++
  if(feeding||systemInterupt||butt1)      //+++++ relay1 (Filter) ++++++
    {
    digitalWrite(relay1, LOW);
    digitalWrite(buttonLed1, LOW);   
    }
  else
    {
    digitalWrite(relay1, HIGH);
    digitalWrite(buttonLed1, HIGH);    
    }
  if(feeding||systemInterupt||butt2)      //+++++ relay2 (Filter) ++++++
    {
    digitalWrite(relay2, LOW); 
    digitalWrite(buttonLed2, LOW);  
    }
  else
    {
    digitalWrite(relay2, HIGH);
    digitalWrite(buttonLed2, HIGH);    
    }  
  if((RTC.getHours() >= 06 && RTC.getHours() <= 17)&&(!systemInterupt)&&(!feeding)&&(!butt3))  //+++++ relay3 (POWERHEAD) ++++++
    {
    digitalWrite(relay3, LOW);
    digitalWrite(buttonLed3, HIGH);   
    }
  if((RTC.getHours() >=18||RTC.getHours() <=05)||(systemInterupt)||(feeding)||(butt3))
    {
    digitalWrite(relay3, HIGH);
    digitalWrite(buttonLed3, LOW);
    }  
  if((RTC.getHours() >= 18 || RTC.getHours() <= 05)&&(!systemInterupt)&&(!feeding)&&(!butt4))   //+++++ relay4 (POWERHEAD) ++++++
    {
    digitalWrite(relay4, LOW);
    digitalWrite(buttonLed4, HIGH);  
    }
  if((RTC.getHours()>=06 && RTC.getHours() <=17)||(systemInterupt)||(feeding)||(butt4))
    {
    digitalWrite(relay4, HIGH);
    digitalWrite(buttonLed4, LOW);
    } 
  if(temperature1 < 78.00 && (!systemInterupt) && (!butt5) && (!feeding))     //+++++ relay5 (Heater) +++++++++++++
    {
    digitalWrite(relay5, LOW);
    digitalWrite(buttonLed5, HIGH);
    lcd.setCursor(12,0);
    lcd.print("HEATING");
    }
    else if(temperature1 > 79.50 || (systemInterupt) || (butt5) || (feeding))
    {
    digitalWrite(relay5, HIGH);
    digitalWrite(buttonLed5, LOW);
    lcd.setCursor(10,0); 
    lcd.print("          ");
    }    
  if((RTC.getHours() >= 18 || RTC.getHours() <= 06)&&(!systemInterupt)&&(!butt6)&&(!feeding)) //+++++ relay6 (Air Pump) ++++++
    {
    digitalWrite(relay6, LOW);
    digitalWrite(buttonLed6, HIGH);    
    }
  else if((RTC.getHours() >= 07 || RTC.getHours() <= 17)||(systemInterupt)||(butt6)||(feeding))
    {
    digitalWrite(relay6, HIGH);
    digitalWrite(buttonLed6, LOW);    
    }
  if((RTC.getHours() >= 07 && RTC.getHours() <= 16)&&(!systemInterupt)&&(!butt7)&&(!feeding))  //+++++ relay7 (CO2)++++++
    {
    digitalWrite(relay7, LOW);
    digitalWrite(buttonLed7, HIGH);    
    }
  if((RTC.getHours() >= 17 || RTC.getHours() <= 06)||(systemInterupt)||(butt7)||(feeding))
    {
    digitalWrite(relay7, HIGH); 
    digitalWrite(buttonLed7, LOW);   
    } /* 
  if((RTC.getHours() >= 18 && RTC.getMinutes() >= 00)||(!systemInterupt)||(!butt8))  //+++++ relay8 ++++++
    {
    digitalWrite(relay8, LOW);
    digitalWrite(buttonLed8, HIGH);
    }
  if((RTC.getHours() >= 24 && RTC.getMinutes() >= 45)||(systemInterupt)||(butt8))
    {
    digitalWrite(relay8, HIGH);
    digitalWrite(buttonLed8, LOW);
    }  */
    
//+++++++++++++++++++++ Control For Box Fan) +++++++++++++++++++++++++   
  
  if(temperature0 > 77.00)      
    {
    digitalWrite(fan4, HIGH);    
    }
    else if(temperature0 < 74.00)
    {
    digitalWrite(fan4, LOW);    
    }       
   
//++++++++++++++++++++ SETUP DOSING PUMP TIMER ++++++++++++++++++++++
  if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
  &&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10))    //+++++ dose macro ferts on MON, WED, FRI
    { 
      digitalWrite(macro1, HIGH);      
    }
    else
    {
      digitalWrite(macro1, LOW);
    }  
  if((RTC.getDayOfWeek() ==3 || RTC.getDayOfWeek()==5 || RTC.getDayOfWeek()==7)&&(RTC.getHours()==6)
  &&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10))   //+++++ dose micro ferts on TUE, THUR, SAT
    { 
      digitalWrite(micro2, HIGH);
    }
    else
    {
      digitalWrite(micro2, LOW);
    } 
   if((RTC.getDayOfWeek() ==3 || RTC.getDayOfWeek()==5 || RTC.getDayOfWeek()==7)&&(RTC.getHours()==6)
   &&(RTC.getMinutes()==5)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10))
    { 
      digitalWrite(fe3, HIGH);
    }
    else
    {
      digitalWrite(fe3, LOW);
    }  
//++++++++++++++++++++SETUP AUTO FEEDER SCHEDULE ++++++++++++++++++++
  if((RTC.getHours() == 7 || RTC.getHours() == 17)&&(RTC.getMinutes() >= 30)&&(RTC.getMinutes() <= 34))
      {
      feeding = true;     
      lcd.setCursor(12,1);
      lcd.print("FEEDING");
      }
    else
      {
      feeding = false;   
      lcd.setCursor(12,1);
      lcd.print("       ");
      } 
    
//+++++++++++++++++++SETUP BUTTON STATES ++++++++++++++++++++++++++++
  int buttonstate1 = 0;
  buttonstate1 = digitalRead(button1);
  if(buttonstate1 == HIGH)
    {
      butt1=true;      
    }
    else if (buttonstate1 == LOW)
    {
      butt1=false;      
    }  
  int buttonstate2 = 0;
  buttonstate2 = digitalRead(button2);
  if(buttonstate2 == HIGH)
    {
      butt2=true;      
    }
    else if (buttonstate2 == LOW)
    {
      butt2=false;      
    }  
  int buttonstate3 = 0;
  buttonstate3 = digitalRead(button3);
  if(buttonstate3 == HIGH)
    {
      butt3=true;      
    }
    else if (buttonstate3 == LOW)
    {
      butt3=false;      
    }  
  int buttonstate4 = 0;
  buttonstate4 = digitalRead(button4);
  if(buttonstate4 == HIGH)
    {
      butt4=true;      
    }
    else if (buttonstate4 == LOW)
    {
      butt4=false;      
    }   
  int buttonstate5 = 0;
  buttonstate5 = digitalRead(button5);
  if(buttonstate5 == HIGH)
    {
      butt5=true;      
    }
    else if (buttonstate5 == LOW)
    {
      butt5=false;      
    }   
  int buttonstate6 = 0;
  buttonstate6 = digitalRead(button6);
  if(buttonstate6 == HIGH)
    {
      butt6=true;      
    }
    else if (buttonstate6 == LOW)
    {
      butt6=false;      
    }   
  int buttonstate7 = 0;
  buttonstate7 = digitalRead(button7);
  if(buttonstate7 == HIGH)
    {
      butt7=true;      
    }
    else if (buttonstate7 == LOW)
    {
      butt7=false;      
    }
  int buttonstate8 = 0;
  buttonstate8 = digitalRead(button8);
  if(buttonstate8 == HIGH)
    {
      butt8=true;      
    }
    else if (buttonstate8 == LOW)
    {
      butt8=false;      
    }
//++++++++++++++++++++ USED TO CONTROL DS1307 RTC +++++++++++++++++++

  /*if(Serial.available())  +++++ Commented out to free up Serial Monitor for Debugging Must be active to set time
  {
    processCommand();
  }
  delay(1000);*/
  
  /*count++;
  if(count % Display_Clock_Every_N_Seconds == 0)
  {    
    Serial.print(count);
    Serial.print(": ");
    RTC.getFormatted(formatted);
    Serial.print(formatted);
    Serial.println();       
  }
  
  if(count % Display_ShortHelp_Every_N_Seconds == 0)
  {
    Serial.println("Send ? for a list of commands.");
  }
  
#ifdef TEST_Squarewave
if(count%10 == 0)
{
  switch(count/10 % 6)
  {
    case 0:
    Serial.print("Squarewave disabled (low impedance): ");
    RTC.sqwDisable(0);
    Serial.println((int) RTC.readData(7));
    break;
    case 1:
    Serial.print("Squarewave disabled (high impedance): ");
    RTC.sqwDisable(1);
    Serial.println((int) RTC.readData(7));
    break;
    case 2:
    Serial.println("Squarewave enabled at 1 Hz");
    RTC.sqwEnable(RTC.SQW_1Hz);
    break;
    case 3:
    Serial.println("Squarewave enabled at 4.096 kHz");
    RTC.sqwEnable(RTC.SQW_4kHz);
    break;
    case 4:
    Serial.println("Squarewave enabled at 8.192 kHz");
    RTC.sqwEnable(RTC.SQW_8kHz);
    break;
    case 5:
    Serial.println("Squarewave enabled at 32.768 kHz");
    RTC.sqwEnable(RTC.SQW_32kHz);
    break;
    default:
    Serial.println("Squarewave test not defined");
  }//switch
}
#endif

#ifdef TEST_StopStart
if(count%10 == 0)
{
  if(!RTC.isStopped()) 
  {
    if(RTC.getSeconds() < 45) 
    {
      Serial.println("Stopping clock for 10 seconds");
      RTC.stop();
    }//if we have enough time
  } else {
    RTC.setSeconds(RTC.getSeconds()+11);
    RTC.start();
    Serial.println("Adding 11 seconds and restarting clock");
  }
}//if on a multiple of 10 counts
#endif 

#ifdef TEST_1224Switch  
  if(count%10 == 0)
  {
    if(count %20 == 0)
    {
      Serial.println("switching to 12-hour time");
      RTC.switchTo12h();
      RTC.setClock();
    }
    else
    {
      Serial.println("switching to 24-hour time");
      RTC.switchTo24h();
      RTC.setClock();
    }
  } 
#endif  +++++ Commented out to free up Serial Monitor for Debugging Must be active to set time */
} 

/////////////////////////////////////////////////
//             FUNCTIONS BEGINS                //
/////////////////////////////////////////////////

//++++++++++++++++++ AUTO FEEDER FUNCTION +++++++++++++++++++++++++++
/*
void autoFeeder()
    {    
      lcd.setCursor(12,1);
      lcd.print("FEEDING");
    } 
 */ 
//++++++++++++++++++ HEATER FUNCTION++++++++++++++++++++++++++++++++
/*void heater()
    {
     if (digitalRead (relay5) == LOW)
      {
       lcd.setCursor(12,0);
       lcd.print("HEATING");
      }
     else
      {
       lcd.setCursor(10,0); 
       lcd.print("          ");
      }
    } */
//+++++++++++++++++ SYSTEM INTERUPT FUNCTION +++++++++++++++++++++++
void sysInterupt()
   {
     int buttonstate = 0;
     buttonstate = digitalRead(button9);
   if (buttonstate == HIGH)
     {
       systemInterupt = true;
       digitalWrite(interuptLed1, HIGH);
       lcd.setCursor(10,0);
       lcd.print("*INTERUPT*");
       
     }
   else if (buttonstate == LOW)
     {   
       systemInterupt = false;
       digitalWrite(interuptLed1, LOW);
     }
   } 

//+++++++++++++++++ LIGHT INTERUPT FUNCTION +++++++++++++++++++++++   

void liteInterupt()
   {
     int buttonstate = 0;
     buttonstate = digitalRead(button10);
   if (buttonstate == HIGH)
     {
       lightInterupt = true;
       digitalWrite(interuptLed2, HIGH);
       analogWrite(led1, 0);
       analogWrite(led2, 0);
       analogWrite(led3, 0);
       analogWrite(led4, 0);
       analogWrite(led5, 0);
     }
   else 
     {   
       lightInterupt = false;
       digitalWrite(interuptLed2, LOW);
     }
   }  
   
//+++++++++++++++++ RTC Process Command FUNCTION +++++++++++++++++++++++     
void processCommand()
{
  if(!Serial.available()) { return; }
  char command = Serial.read();
  int in,in2;
  switch(command)
  {
    case 'H':
    case 'h':
    in=SerialReadPosInt();
    RTC.setHours(in);
    RTC.setClock();
    Serial.print("Setting hours to ");
    Serial.println(in);
    break;
    case 'I':
    case 'i':
    in=SerialReadPosInt();
    RTC.setMinutes(in);
    RTC.setClock();
    Serial.print("Setting minutes to ");
    Serial.println(in);
    break;
    case 'S':
    case 's':
    in=SerialReadPosInt();
    RTC.setSeconds(in);
    RTC.setClock();
    Serial.print("Setting seconds to ");
    Serial.println(in);
    break;
    case 'Y':
    case 'y':
    in=SerialReadPosInt();
    RTC.setYear(in);
    RTC.setClock();
    Serial.print("Setting year to ");
    Serial.println(in);
    break;
    case 'M':
    case 'm':
    in=SerialReadPosInt();
    RTC.setMonth(in);
    RTC.setClock();
    Serial.print("Setting month to ");
    Serial.println(in);
    break;
    case 'D':
    case 'd':
    in=SerialReadPosInt();
    RTC.setDate(in);
    RTC.setClock();
    Serial.print("Setting date to ");
    Serial.println(in);
    break;
    case 'W':
    Serial.print("Day of week is ");
    Serial.println((int) RTC.getDayOfWeek());
    break;
    case 'w':
    in=SerialReadPosInt();
    RTC.setDayOfWeek(in);
    RTC.setClock();
    Serial.print("Setting day of week to ");
    Serial.println(in);
    break;
    
    case 't':
    case 'T':
    if(RTC.is12hour()) {
      RTC.switchTo24h();
      Serial.println("Switching to 24-hour clock.");
    } else {
      RTC.switchTo12h();
      Serial.println("Switching to 12-hour clock.");
    }
    RTC.setClock();
    break;
    
    case 'A':
    case 'a':
    if(RTC.is12hour()) {
      RTC.setAM();
      RTC.setClock();
      Serial.println("Set AM.");
    } else {
      Serial.println("(Set hours only in 24-hour mode.)");
    }
    break;
    
    case 'P':
    case 'p':
    if(RTC.is12hour()) {
      RTC.setPM();
      RTC.setClock();
      Serial.println("Set PM.");
    } else {
      Serial.println("(Set hours only in 24-hour mode.)");
    }
    break;

    case 'q':
    RTC.sqwEnable(RTC.SQW_1Hz);
    Serial.println("Square wave output set to 1Hz");
    break;
    case 'Q':
    RTC.sqwDisable(0);
    Serial.println("Square wave output disabled (low)");
    break;
    
    case 'z':
    RTC.start();
    Serial.println("Clock oscillator started.");
    break;
    case 'Z':
    RTC.stop();
    Serial.println("Clock oscillator stopped.");
    break;
    
    case '>':
    in=SerialReadPosInt();
    in2=SerialReadPosInt();
    RTC.writeData(in, in2);
    Serial.print("Write to register ");
    Serial.print(in);
    Serial.print(" the value ");
    Serial.println(in2);
    break;    
    case '<':
    in=SerialReadPosInt();
    in2=RTC.readData(in);
    Serial.print("Read from register ");
    Serial.print(in);
    Serial.print(" the value ");
    Serial.println(in2);
    break;

    default:
    Serial.println("Unknown command. Try these:");
    Serial.println(" h## - set Hours       d## - set Date");
    Serial.println(" i## - set mInutes     m## - set Month");
    Serial.println(" s## - set Seconds     y## - set Year");
    Serial.println(" w## - set arbitrary day of Week");
    Serial.println(" t   - toggle 24-hour mode");
    Serial.println(" a   - set AM          p   - set PM");
    Serial.println();
    Serial.println(" z   - start clock     Z   - stop clock");
    Serial.println(" q   - SQW/OUT = 1Hz   Q   - stop SQW/OUT");
    Serial.println();
    Serial.println(" >##,###  - write to register ## the value ###");
    Serial.println(" <##      - read the value in register ##");
    
  }//switch on command  
}

//read in numeric characters until something else
//or no more data is available on serial.
int SerialReadPosInt() 
 {
  int i = 0;
  boolean done=false;
  while(Serial.available() && !done)
  {
    char c = Serial.read();
    if (c >= '0' && c <='9')
    {
      i = i * 10 + (c-'0');
    }
    else 
    {
      done = true;
    }
  }
  return i;
}
HunterX is offline   Reply With Quote
Old 03-21-2014, 09:43 PM   #157
Bryanmc1988
Planted Tank Enthusiast
 
PTrader: (34/100%)
Join Date: Apr 2012
Location: San Diego - CA
Posts: 877
Default

so from looking at the code it seems as if the auto dosing just checks and see's if the time and date matches with the set time/date in the script then turns it on?

my question is why not make it to where you can set/ change all this in the lcd and save it to the eeprom? wouldnt this save time from having to always upload and reload the script every time you want to change the date and time?


another question i have is how do you know how long the pump stays on or how many ml of dosing it will pump?

Quote:
if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
&&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&( RTC.getSeconds()<=10)) //+++++ dose macro ferts on MON, WED, FRI
{
digitalWrite(macro1, HIGH);
}
else
{
digitalWrite(macro1, LOW);
}
as you can see it just says "High" or "Low" - i am assuming this just means "High" is sending 5vdc to the doing pump and "Low" means turn off the pump or provide 0vdc to the pump... but with the "Else" in between it will just check and if its on or off right? and if its off it will turn on and if its on it will turn off...


kinda confusing sorry if you dont understand what i am trying to ask xD... but shouldnt it be more like this?

Quote:
if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
&&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&( RTC.getSeconds()<=10)) //+++++ dose macro ferts on MON, WED, FRI
{
digitalWrite(macro1, HIGH);
delay(1000); //delay for 1sec in millsec - this would keep the pump powered for 1 sec while its dosing...
digitalWrite(macro1, LOW);
}
else
{
digitalWrite(macro1, LOW);
}
Bryanmc1988 is online now   Reply With Quote
Old 03-21-2014, 10:48 PM   #158
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by Bryanmc1988 View Post
so from looking at the code it seems as if the auto dosing just checks and see's if the time and date matches with the set time/date in the script then turns it on?

my question is why not make it to where you can set/ change all this in the lcd and save it to the eeprom? wouldnt this save time from having to always upload and reload the script every time you want to change the date and time?


another question i have is how do you know how long the pump stays on or how many ml of dosing it will pump?



as you can see it just says "High" or "Low" - i am assuming this just means "High" is sending 5vdc to the doing pump and "Low" means turn off the pump or provide 0vdc to the pump... but with the "Else" in between it will just check and if its on or off right? and if its off it will turn on and if its on it will turn off...


kinda confusing sorry if you dont understand what i am trying to ask xD... but shouldnt it be more like this?
Look at the last part of my code. It is asking that if seconds is greater than or equal to 5 and less than or equal to 10, the pump will stay on. Effectively the pump will stay on for 6 seconds. That way I do not have to use a delay command. During a delay command the whole Arduino just waits. That means nothing else can happen while the delay is going on. They way I wrote the code always the Arduino to continue to cycle. It does not slow the program down. Why is that important? Say I want to push the button to shut one of the filters off while it is dosing FERTS. The Aruduino would not be able to read the button state and shut the filter off while stuck in a delay command.

As far as why do I have it on for 6 seconds. Based on test, it takes 6 seconds to pump the amount of fert I need.
HunterX is offline   Reply With Quote
Old 03-21-2014, 11:20 PM   #159
Bryanmc1988
Planted Tank Enthusiast
 
PTrader: (34/100%)
Join Date: Apr 2012
Location: San Diego - CA
Posts: 877
Default

with that being said it makes lots of sense... but i'm not an expert on arduino and so how does the last part of your code work? i got a little confused trying to figure how that plays out lol sorry noob talk here xD

Quote:
if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
&&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&( RTC.getSeconds()<=10)) //+++++ dose macro ferts on MON, WED, FRI
Quote:
It is asking that if seconds is greater than or equal to 5 and less than or equal to 10, the pump will stay on
why does it need to be greater then or qual to 5 and less then or equal to 10? confused me here - wouldnt this only keep the pump on for 5 sec not 6?
Bryanmc1988 is online now   Reply With Quote
Old 03-21-2014, 11:29 PM   #160
bigd603
Planted Member
 
PTrader: (1/100%)
Join Date: May 2011
Location: Portland, OR
Posts: 263
Default

No worries Bryan, we're here to help you learn! So everytime the Arduino runs through the loop and it hits this if statement it is checking the day of the week, the hour, the minute, and the seconds. This code is telling the arduino that as long as the day is Monday, wednesday, or friday, the hour is 6am, the minute is thirty, and the second is ANYTHING BETWEEN AND INCLUDING 5 through 10 it will execute this if statement. When the arduino runs through the loop and the second is no longer between 5 and 10, it will not execute, move on to the else statement where the PWM is set to 0 effectively only allowing it to run for 6 seconds. The six seconds would have come from Hunter testing his pumps to determine how long it takes them to dose the proper amount of ferts.
bigd603 is online now   Reply With Quote
Old 03-21-2014, 11:35 PM   #161
bigd603
Planted Member
 
PTrader: (1/100%)
Join Date: May 2011
Location: Portland, OR
Posts: 263
Default

Quote:
Originally Posted by Bryanmc1988 View Post
why does it need to be greater then or qual to 5 and less then or equal to 10? confused me here - wouldnt this only keep the pump on for 5 sec not 6?
When counting the seconds you have to also include second 5. So seconds 5, 6, 7, 8, 9, and 10.
bigd603 is online now   Reply With Quote
Old 03-22-2014, 12:26 AM   #162
Bryanmc1988
Planted Tank Enthusiast
 
PTrader: (34/100%)
Join Date: Apr 2012
Location: San Diego - CA
Posts: 877
Default

ok that makes lots of sense now... thanks for clearing that up guys... xD i will need to put this doing code into a script for my arduino some time this week with a touch screen lcd tho menu and everything... no i am no expert but i will try and hope for the best lol

Quote:
Originally Posted by bigd603 View Post
No worries Bryan, we're here to help you learn! So everytime the Arduino runs through the loop and it hits this if statement it is checking the day of the week, the hour, the minute, and the seconds. This code is telling the arduino that as long as the day is Monday, wednesday, or friday, the hour is 6am, the minute is thirty, and the second is ANYTHING BETWEEN AND INCLUDING 5 through 10 it will execute this if statement. When the arduino runs through the loop and the second is no longer between 5 and 10, it will not execute, move on to the else statement where the PWM is set to 0 effectively only allowing it to run for 6 seconds. The six seconds would have come from Hunter testing his pumps to determine how long it takes them to dose the proper amount of ferts.
but i would like to know tho is why between 5-10 sec's? why not just do 1-6 sec then?
Bryanmc1988 is online now   Reply With Quote
Old 03-22-2014, 04:03 AM   #163
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by bigd603 View Post
No worries Bryan, we're here to help you learn! So everytime the Arduino runs through the loop and it hits this if statement it is checking the day of the week, the hour, the minute, and the seconds. This code is telling the arduino that as long as the day is Monday, wednesday, or friday, the hour is 6am, the minute is thirty, and the second is ANYTHING BETWEEN AND INCLUDING 5 through 10 it will execute this if statement. When the arduino runs through the loop and the second is no longer between 5 and 10, it will not execute, move on to the else statement where the PWM is set to 0 effectively only allowing it to run for 6 seconds. The six seconds would have come from Hunter testing his pumps to determine how long it takes them to dose the proper amount of ferts.
Well Said Big D! Thanks
HunterX is offline   Reply With Quote
Old 03-22-2014, 04:04 AM   #164
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by Bryanmc1988 View Post
ok that makes lots of sense now... thanks for clearing that up guys... xD i will need to put this doing code into a script for my arduino some time this week with a touch screen lcd tho menu and everything... no i am no expert but i will try and hope for the best lol



but i would like to know tho is why between 5-10 sec's? why not just do 1-6 sec then?
Sure. That would work fine as well. It doesn't really matter.
HunterX is offline   Reply With Quote
Old 03-22-2014, 05:03 AM   #165
Bryanmc1988
Planted Tank Enthusiast
 
PTrader: (34/100%)
Join Date: Apr 2012
Location: San Diego - CA
Posts: 877
Default

Ok just wondering if it was something that couldn't be done but I got it now thanks guys lets hope this works out xD
Bryanmc1988 is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright Planted Tank LLC 2012