Jump to content
Top Shelf Aquatics

My arduino Controller w/ weather patterns/lightning


smorrow5773

Recommended Posts

This code gets you a working controller as long as you change the needed variables for your setup.

I have set up on arduino mega. The weather patterns are created by passing the weather variable a millis time. In this code it is set to change weather patterns every 15 minutes, although I run it to change daily. Depending on the random number returned by "weather", it will create increasing/decreasing passing clouds and when in mode 4 or 5 will create lightning at random intervals depending on the delay and number of numbers passed to random. I still have not finished setting up the lcd keypad menus at this time. I need to finish that as well as finish up water change mode, and create storm swells during the storm mode(s) I will eventually set up a very rare hurricane mode to really get things stirred up, too. Stay tuned for more.

 

 

//********TESTED/WRITTEN ON ARDUINO 0017**************************

 

#include <LiquidCrystal.h>

#include <WString.h>

#include <stdio.h>

#include <OneWire.h>

#include <WProgram.h>

#include <Wire.h>

#include <DS1307.h> 

//********************************************************************LCD/KEYPAD INFO********

#define rightKey  0

#define upKey     1

#define downKey   2

#define leftKey   3

#define selectKey 4

#define NUM_KEYS  5

LiquidCrystal lcd(32, 33, 34, 35, 36, 37);

//*********************************************************************ONEWIRE INF

O***********

#define TEMP_PIN  2

    void OneWireReset(int Pin);

    void OneWireOutByte(int Pin, byte d);

    byte OneWireInByte(int Pin);

//*********************************************************************ANALOG*****

********

int heatsink = 1; //cooling fan LM34 control input

int ph_probe = 3;

int SignBit, Whole, Fract; //PHPROBE

//*********************************************************************DIGITAL****

********

int heater = 22;

int sump = 23;

int coolingfans = 24;

int ato = 25;

int ato_input = 38;

//*********************************************************************PWM DIGITAL

******************

int ledfan = 8;

int blueled = 6; //currently controlling both PWM

int whiteled = 7;

//*********************************************************************PLACEHOLDER

S/MISC*************

int moonphase;

#define SS 15  //Sector size minutes

#define NUMREADINGS 10

int heater_on_temp = 7850;

int heater_off_temp = 7950;

int tempF = 0; //heatsink temperature variable

int fan_on_temp = 8150; // cooling fans

int fan_off_temp = 8050; // cooling fans

int keypad_delay = 15;

int counter_delay =0;

int feed_time = 5; // number minutes

int water_change = 20; //number minutes

int pumps_off = -10; // Placeholder --don't change

int min_cnt ;

long weatherstate;

int lights_on = 500;

int lights_off = 2200;

long previousMillis = 0;

long prevMillis = 0;

long preMillis = 0;

byte bled[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0-3:45

                0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 23, 23, 23, 23, //4 - 7:45

                0, 0, 0, 0, 0, 0, 0, 0, 23, 30, 40, 50, 60, 70, 80, 90, //8 - 11:45

                100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 220, 240,

 240, 240, 240,  //12 - 3:45 PM

                255, 255, 255, 255, 240, 230, 220, 210, 200, 200, 180, 160, 150,

 140, 130, 120, //4 - 7:45 PM

                110, 100, 75, 50, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0   //8 - 11:45 PM

                };  

int bled_out;

byte wled[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0 - 3:45

                0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 23, 23, 23, 23, //4 - 7:45

                0, 0, 0, 0, 0, 0, 0, 0, 23, 30, 40, 50, 60, 70, 80, 90, //8 - 11:45

                100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 220, 240,

 240, 240, 240,  //12 - 3:45 PM

                255, 255, 255, 255, 240, 230, 220, 210, 200, 200, 180, 160, 150,

 140, 130, 120, //4 - 7:45 PM

                110, 100, 75, 50, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0   //8 - 11:45 PM

                };  

int wled_out ;

int flash[] = {255, 0, 0, 255,50,225, 0,0,0, 0, 200,0, 0, 0, 0, 23,0, 0, 23, 0, 0, 0,0, 50,0,0,0};

int ledmode ;

int flashvalue;

int lightningstate ;

int cloudstate;

int lastKeyEvent = 0;

int curKeyEvent = 0;

int keyToReturn = 0;

boolean keyToProcess = false;

int adc_key_in = 0;

int adc_key_val[NUM_KEYS] ={ 30, 150, 360, 535, 760 };

 //********************************************************************************

****SETUP****************************************************

 

  void setup(){

   

  Serial.begin(9600);

  lcd.begin(4, 20);

  Wire.begin(); // Initialize the I2C bus

  int on_minute = 1; //first time through the program.

                      //********************************************initialize inputs/outputs**********************

  pinMode(ledfan, OUTPUT); //LED HEATSINK PWM4

  pinMode(coolingfans, OUTPUT);

  pinMode(blueled, OUTPUT);

  pinMode(whiteled, OUTPUT);

  pinMode(ato_input, INPUT);

                  //**********************************************************RELAY CONTROLS******

  pinMode(sump, OUTPUT); // digital pin for skimmer as output

  pinMode(ato, OUTPUT); // digital pin for auto top off as output

  pinMode(heater, OUTPUT); // digital pin for heater as output

  pinMode(coolingfans, OUTPUT);

  //pinMode(ph_1, OUTPUT); // digital pin for power head 1 as output

  //pinMode(ph_2, OUTPUT); // digital pin for power head 2 as output

  //int weatherstate = 0;

  int keyEvent = -1;

  int lastEvent = -1;

  int countEvent = 0;

  randomSeed(analogRead(6));

  char msgs[5][15] = {"> ",

                    "^ ",

                    "v ",

                    "< ",

                    "*" };

  

 //Un-comment to set the time

  /* RTC.stop();

  RTC.set(DS1307_SEC,01);        //set the seconds

  RTC.set(DS1307_MIN,56);     //set the minutes

  RTC.set(DS1307_HR,17);       //set the hours (military)

  RTC.set(DS1307_DOW,6);       //set the day of the week

  RTC.set(DS1307_DATE,9);       //set the date

  RTC.set(DS1307_MTH,1);        //set the month

  RTC.set(DS1307_YR,10);         //set the year

  RTC.start();*/

int ledmode = 1 ; //auto mode =1, manual =2

weatherstate = 2;

}

    

//********************************************************************************

*****MAIN LOOP*****************************************************  

void loop(){

      int hour = RTC.get(DS1307_HR,true); // military time

      int day = RTC.get(DS1307_DOW,false);

      int minute = RTC.get(DS1307_MIN,false);

      int second = RTC.get(DS1307_SEC,false);

      int month = RTC.get(DS1307_MTH,false);

      int date =RTC.get(DS1307_DATE,false);

      int year = RTC.get(DS1307_YR,false);

      int mil_time = (hour * 100) + minute; //military time output

      min_cnt= (hour*60)+ minute; 

      print_time ();

      weather ();

              if (weatherstate == 1) //bright,sunny day

               { clouds (600000,5); } //random at 10mins,5variables

              if (weatherstate == 2) //partly cloudy

                {clouds (600000,4);}  //random at 10mins,4variables

              if (weatherstate ==3) //mostly cloudy

               { clouds (300000,3); } //random at 5mins,3variables

              if (weatherstate ==4) //overcast, rain

                {clouds (60000,3); // random at 1min,2variables

                lightning (6000,15);}

              if (weatherstate ==5) //thunderstorms

                {clouds (60000,2); //random at 1 min

                lightning (6000,9);}  //random at 30 sec

      lifesupport (); 

      printledtemp ();

      GetPhase ();  

 

      

      int keyEvent = detectKey();

                    if (keyEvent >= 0)

                      { switch (keyEvent)

                         //******************************************

                          {case upKey:

                                    {lcd.clear ();

                                     print_time ();      //0,0

                                     printwatertemp (); //0,1

                                     printledtemp ();   //10,1

                                     //printph (); //10,0

                                     if (detectKey() == 2) //downkey

                                         {break;}

                                    }//end upkey

                         //*******************************************

                           case downKey:

                                     {lcd.clear ();

                                      print_time ();

                                      lcd.setCursor (0,1);

                                      lcd.print ("FEED MODE?");

                                      if (detectKey() == 4)//SELECTKEY

                                          {standby ();}

                                      if (detectKey() == 2) //downkey

                                         {break;}

                                    }//end downkey

                          //******************************************

                           case leftKey:

                                      {lcd.clear ();

                                      print_time ();

                                      lcd.setCursor (3,2);

                                      lcd.print ("LIGHTING MENU");

                                      if (detectKey() == 4)//SELECTKEY

                                                          { lcd.setCursor (3,3);

                                                            lcd.print ("OPTIONS");

                                                            switch (keyEvent)

                      

                                                                    {case upKey:

                                                                                

{lcd.clear ();

                                                                                

 lcd.setCursor (0,0);

                                                                                

 lcd.print ("AUTO UP");

                                                                                

 lcd.setCursor (0,1);

                                                                                

 lcd.print ("MAN DWN");

                                                                                

 if (detectKey() == 1) //UPKEY AUTO

                                                                                

     {ledmode == 1;

                                                                                

     Serial.println ("ledmode auto");

                                                                                

     lcd.clear ();

                                                                                

     lcd.setCursor (0,0);

                                                                                

     lcd.print ("AUTO SET");

                                                                                

     delay (2000);

                                                                                

    break;}

                                                                                

 if (detectKey () == 2)//downkey manual

                                                                                

     {ledmode ==0;

                                                                                

     Serial.println ("ledmode manual");

                                                                                

     lcd.clear ();

                                                                                

     lcd.setCursor (0,0);

                                                                                

     lcd.print ("MAN SET");

                                                                                

     delay (2000);

                                                                                

    break;}

                                                                                

  }//end upkey

                                                                      

                                                                    

                                                                       case leftKey:

                                                                                

  lcd.clear (); {break;}}

                                                         

                                                              } //end options

                                      if (detectKey() == 3)//leftkey

                                                              {lcd.clear (); break;}

                                      }//end lighting menu

                                 

                          //******************************************

                           case rightKey:

                                      {

                         

                         

                                      } //end rightkey

                                  break;

                           //********************************************

                            case selectKey:

                                      {

                           

                           

                                      } //end selectkey

                                  break;

                            //********************************************

                  }//end switch

                       } //end if

   

      

int on_minute = 0; //signals that the program has been run once

       

     

}//end loop

//*************************************************************FUNCTIONS**********

***********************************************

 

 

 

//*************************************************

int get_key(unsigned int input){

                        int k;

                        for (k = 0; k < NUM_KEYS; k++)

                          {if (input < adc_key_val[k])

                                return k;}

                        if (k >= NUM_KEYS)

                            k = -1; 

                        return k;

                      }

 

//************************************************

int detectKey(){

                        keyToReturn = -1;

                        adc_key_in = analogRead(0); // read the value from the sensor

                        curKeyEvent = get_key(adc_key_in);  // convert into key press

                        if (curKeyEvent != lastKeyEvent)

                          {if (!keyToProcess)

                            {lastKeyEvent = curKeyEvent; keyToProcess = true;}

                          else

                           {keyToReturn = lastKeyEvent; lastKeyEvent = -1; keyToProcess = false;}}

                        return keyToReturn;

                      } 

//*****************************************************        

          

void LED_levels_output(){

                        int sector, sstep, t1, t2 ;

                        if (min_cnt>=1440) {min_cnt=1;} // 24 hours of minutes

                            sector = min_cnt/15;    // divided by gives sector -- 15 minute

                            sstep = min_cnt%15;     // remainder gives add on to sector value

                            t1 =sector; 

                        if (t1==95) {t2=0;}

                        else {t2 = t1+1;}

                        if (sstep==0)

                             {bled_out = bled[t1];

                              wled_out = wled[t1];}

                        else { bled_out = check(&bled[t1], &bled[t2], sstep);

                              wled_out = check(&wled[t1], &wled[t2], sstep);}

                         if (lightningstate == 1){

                              int i = 0;

                              for (i=0;i<26;i++)

                               {flashvalue = flash

                               analogWrite (whiteled, flashvalue);

                               analogWrite (blueled, flashvalue);

                                delay(125);}}

                        if (cloudstate == 1){

                              int i = 0;

                              for (i=(bled_out);i>=26;i-=3)

                                  {analogWrite (blueled,i);delay (750);

                                  analogWrite (whiteled,i);delay (750);}

                              for (i=26;i<=(bled_out);i+=3)

                                  {analogWrite (blueled,i);delay (750);

                                  analogWrite (whiteled,i);delay (750);}}

                        if (weatherstate ==5){

                            if (bled_out >=50) { bled_out=(bled_out/2);

                            if (bled_out >=50) { wled_out=(wled_out/2); }}

                        analogWrite(blueled, bled_out);

                        analogWrite(whiteled, wled_out);

                       }}

//********************************************************************************

**************         

  

  byte check( byte *pt1, byte *pt2, int lstep){

                        byte result; float fresult;

                        if (*pt1==*pt2) {result = *pt1;} // No change

                        else if (*pt1<*pt2) //Increasing brightness

                             {fresult = ((float(*pt2-*pt1)/15.0) * float(lstep))+float(*pt1);

                               result = byte(fresult);}

                        else {fresult = -((float(*pt1-*pt2)/15.0) * float(lstep))+float(*pt1); //Decreasing brightness

                            result = byte(fresult);}

                        return result;

                      }

//********************************************************************************

*****************************         

 

void OneWireReset(int Pin) {

                       digitalWrite(Pin, LOW); pinMode(Pin, OUTPUT); delayMicroseconds(500);

                       pinMode(Pin, INPUT); delayMicroseconds(500);

                      }

 

//********************************************************************************

*************************

void OneWireOutByte(int Pin, byte d){

                       byte n;

                       for(n=8; n!=0; n--)

                         { if ((d & 0x01) == 1)

                            {digitalWrite(Pin, LOW);pinMode(Pin, OUTPUT);delayMicroseconds(5);

                             pinMode(Pin, INPUT);delayMicroseconds(60);}

                          else

                          {digitalWrite(Pin, LOW); pinMode(Pin, OUTPUT); delayMicroseconds(60);

                             pinMode(Pin, INPUT);}

                          d=d>>1; }

                     }

//********************************************************************************

*****************************

 

byte OneWireInByte(int Pin){

                      byte d, n, b;

                      for (n=0; n<8; n++)

                        {digitalWrite(Pin, LOW); pinMode(Pin, OUTPUT); delayMicroseconds(5);

                          pinMode(Pin, INPUT); delayMicroseconds(5);

                          b = digitalRead(Pin); delayMicroseconds(50);

                          d = (d >> 1) | (b<<7); }

                      return(d);

                    }

 

//********************************************************************************

**************************

 

void watertemp (){

                int HighByte, LowByte, TReading, Tc_100 ;

            

                        OneWireReset(TEMP_PIN);

                        OneWireOutByte(TEMP_PIN, 0xcc);

                        OneWireOutByte(TEMP_PIN, 0x44); 

                        OneWireReset(TEMP_PIN);

                        OneWireOutByte(TEMP_PIN, 0xcc);

                        OneWireOutByte(TEMP_PIN, 0xbe);

                        LowByte = OneWireInByte(TEMP_PIN);

                        HighByte = OneWireInByte(TEMP_PIN);

                        TReading = (HighByte << 8) + LowByte;

                        SignBit = TReading & 0x8000;  // test most sig bit

                        if (SignBit) {TReading = (TReading ^ 0xffff) + 1; }

                        Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

                        Tc_100 = (Tc_100 * 9/5) + 3200;  //Convert to fahrenheit, comment this out to display in celcius

                        Whole = Tc_100 / 100;  // separate off the whole and fractional portions

                        Fract = Tc_100 % 100;

                    } 

    

//********************************************************************************

******************************       

 

      

void printwatertemp (){

     

                      lcd.setCursor(12,1);

                      lcd.print(Whole, DEC); delay(keypad_delay);

                      lcd.print("."); delay(keypad_delay);

                      if (Fract < 10)

                        {lcd.print("0"); delay(keypad_delay);}

                        lcd.print(Fract, DEC); delay(keypad_delay);

                        lcd.write(0xDF); delay(keypad_delay);

                        lcd.print("F "); delay(keypad_delay);

                      }

//********************************************************************************

*******************************

//void wavemaker (){}

                      /*if(second <= 30) { digitalWrite(ph_1, LOW); digitalWrite(ph_2, HIGH); delay(keypad_delay);}

                        else { digitalWrite(ph_1, HIGH); digitalWrite(ph_2, LOW)

; delay(keypad_delay);}}

                      }*/

//********************************************************************************

********************************

void print_time (){

                        int hour = RTC.get(DS1307_HR,true); // military time

                        int day = RTC.get(DS1307_DOW,false);

                        int minute = RTC.get(DS1307_MIN,false);

                        int second = RTC.get(DS1307_SEC,false);

                        int month = RTC.get(DS1307_MTH,false);

                        int date =RTC.get(DS1307_DATE,false);

                        int year = RTC.get(DS1307_YR,false);

                        int mil_time = (hour * 100) + minute; //military time output

                        lcd.setCursor(0,0);

                          switch (day) {

                            case 1: lcd.print("Mon"); break;

                            case 2: lcd.print("Tue"); break;

                            case 3: lcd.print("Wed"); break;

                            case 4: lcd.print("Thu"); break;

                            case 5: lcd.print("Fri"); break;

                            case 6: lcd.print("Sat"); break;

                            case 7: lcd.print("Sun"); break;}

                         lcd.print (" "); lcd.print (month); lcd.print ("/");

                         if (date < 10) {lcd.print (" ");}

                         lcd.print (date); lcd.print(" ");

                          lcd.setCursor (12,0);

                          if((hour < 10 && hour > 0) || (hour > 12 && hour - 12 < 10))

                            {lcd.print(" "); delay(keypad_delay);}

                          if(hour > 12)

                            {lcd.print(hour - 12, DEC); delay(keypad_delay); }

                          if(hour == 0)

                            {lcd.print(12, DEC); delay(keypad_delay);}

                          if(hour > 0 && hour < 13)

                            {lcd.print(hour, DEC); delay(keypad_delay); }

                          lcd.print(":"); delay(keypad_delay);

                          if(minute < 10)

                             {lcd.print("0"); delay(keypad_delay); }

                          lcd.print(minute, DEC); delay(keypad_delay);

                          if(hour < 12 || hour == 0)

                            {lcd.print("AM"); delay(keypad_delay);}

                          else

                            {lcd.print("PM"); delay(keypad_delay);}

                        }

//********************************************************************************

***********************

void autotopoff (){int hour;int ato_time = 5;

                    long interval = (1000 * ato_time);

                    int ato_hour = hour;

                    if(digitalRead(ato_input) == LOW && ato_hour != hour)

                      {digitalWrite(ato, HIGH);

                         if (millis() - previousMillis > interval) {

                           previousMillis = millis();

                           digitalWrite(ato, LOW); } }

                    }

//********************************************************************************

*************************                  

int ledtemp (){

                    int samples[16];

                    int i = 0;

                      for (i = 0;i<=15;i++) // get averages

                        {samples = ( 4.72 * analogRead(heatsink) * 100.0) / 1024.0;

                        tempF = tempF + samples;delay (10);} tempF = tempF/16.0;

                     return tempF;

                }

//********************************************************************************

**************************        

void printledtemp (){

                    lcd.setCursor(7, 1); lcd.print ("HS"); delay (keypad_delay);

                    lcd.print (" "); delay (keypad_delay);

                    lcd.print (tempF, DEC); lcd.write(0xDF); delay(keypad_delay);

                  }

//********************************************************************************

******************************      

void ledfancontrol (){

                    if (tempF >= 111)

                      {analogWrite(ledfan, 255) ;lcd.setCursor (0,3);lcd.print("FnHi"); } //led fan on HIGH

                    if ((tempF >= 96) && (tempF <=110))

                      {analogWrite(ledfan, 175) ;lcd.setCursor (0,3);lcd.print("FnMd"); } //led fan on MED

                    if ((tempF >= 90) && (tempF <=95))

                      {analogWrite(ledfan, 100) ;lcd.setCursor (0,3);lcd.print("FnLo");} //led fan on LOW

                    if (tempF <= 89)

                      {analogWrite(ledfan, 0) ; lcd.setCursor (0,3); lcd.print (" ");} //led fan off

                  }

//********************************************************************************

*****************************      

void heatercontrol (){

                    int watertemp = watertemp; //**********************???????POINTER TO INTEGER??????????TEST......TEST

                    if(watertemp > fan_on_temp)

                      {digitalWrite(coolingfans, HIGH); lcd.setCursor (5,3);lcd.print("CF");}

                    if(watertemp < fan_off_temp)

                      {digitalWrite(coolingfans, LOW);lcd.setCursor (5,3);lcd.print(" ");}

                    if (watertemp >= heater_on_temp)

                      {digitalWrite (heater, HIGH); lcd.setCursor (8,3);lcd.print("HT");}

                    if (watertemp <= heater_off_temp)

                      {digitalWrite (heater, LOW); lcd.setCursor (8,3);lcd.print (" ");}

                  }

 //********************************************************************************

*****************************

void ph_value (){

                      long ph_val;

                      int readings[NUMREADINGS]; // the readings from the analog input

                      int index = 0; // the index of the current reading

                      int total = 0; // the running total

                      int average = 0;

                      total -= readings[index]; // subtract the last reading

                            readings[index] = analogRead(ph_probe); // read from the sensor

                            total += readings[index]; // add the reading to the total

                            index = (index + 1); // advance to the next index

                        

                            if (index >= NUMREADINGS) // if we're at the end of the array...

                            index = 0; // ...wrap around to the beginning

                        

                            average = total / NUMREADINGS; // calculate the average

                        

                            ph_val = (-1.47 * average + 1300); // pH is stored 100 times value

                        

                            Whole = (ph_val / 100); // separate off the whole and fractional portions

                            Fract = (ph_val % 100);

                          }

//********************************************************************************

*******************************              

void printph (){

                      lcd.setCursor(0,1); lcd.print("pH="); delay(keypad_delay);

                      if (Whole < 10){lcd.print(" "); delay(keypad_delay);}

                      lcd.print(Whole, DEC); delay(keypad_delay);

                      lcd.print("."); delay(keypad_delay);

                      if (Fract < 10){ lcd.print("0"); delay(keypad_delay);}

                      lcd.print(Fract, DEC); delay(keypad_delay);

                }

                    

 //********************************************************************************

***************************

float GetPhase ()//(int year, int month, int day) // calculate the current phase of the moon

                      {int hour, yyear, day, minute, second, month, date, year;

                      yyear = (2000 + year);

                      float phase;

                      double AG, IP;

                      long YY, MM, K1, K2, K3, JD;

                      YY = yyear - floor((12 - month) / 10);

                      MM = month + 9;

                      if (MM >= 12)

                          {MM = MM - 12;}

                      K1 = floor(365.25 * (YY + 4712));

                      K2 = floor(30.6 * MM + 0.5);

                      K3 = floor(floor((YY / 100) + 49) * 0.75) - 38;

                      JD = K1 + K2 + day + 59;

                      if (JD > 2299160)

                          {JD = JD - K3;}

                      IP = MyNormalize((JD - 2451550.1) / 29.530588853);

                      AG = IP*29.53;

                      phase = 0;

                      if ((AG < 1.) && (phase == 0))

                          {phase = 0; }//new; 0% illuminated

                      if ((AG < 1.84566) && (phase == 0))

                          {phase = 12; }//new; 0% illuminated

                      if ((AG < 5.53699) && (phase == 0))

                          {phase = 25;} //Waxing crescent; 25% illuminated

                      if ((AG < 9.922831) && (phase == 0))

                          {phase = 50;} //First quarter; 50% illuminated

                      if ((AG < 12.91963) && (phase == 0))

                          {phase = 75; }//Waxing gibbous; 75% illuminated

                      if ((AG < 16.61096) && (phase == 0))

                          {phase = 100; }//Full; 100% illuminated

                      if ((AG < 20.30228) && (phase == 0))

                          {phase = 75; }//Waning gibbous; 75% illuminated

                      if ((AG < 23.99361) && (phase == 0))

                          {phase = 50; }//Last quarter; 50% illuminated

                      if ((AG < 27.68493) && (phase == 0))

                          {phase = 25; }//Waning crescent; 25% illuminated

                      if (phase == 0)

                          {phase = 0; }//default to new; 0% illuminated

                   moonphase = phase;

                 return phase; }

//********************************************************************************

************              

                 

 

double MyNormalize(double v)

                    {v = v - floor(v);

                    if (v < 0)

                    v = v + 1;

                    return v;

                    } 

                    

//********************************************************************************

************

 

void standby (){

                  int minute, second;

                  int interval = 1000;

                  lcd.clear();

                     lcd.setCursor(0,0); lcd.print("Feed mode active !");

                      digitalWrite(heater, LOW);

                      digitalWrite(coolingfans, LOW);

                      //digitalWrite(ph_1, LOW);

                      //digitalWrite(ph_2, LOW);

                      digitalWrite(sump, LOW);

                  lcd.setCursor(0, 1); lcd.print("Time left: ");

                      counter_delay = feed_time * 60; // Number of seconds for feed mode

                      while(counter_delay >= 0){

                            lcd.setCursor(12,1);

                            minute = counter_delay / 60;

                            second = counter_delay % 60;

                            lcd.print(minute,DEC); delay(keypad_delay);

                            lcd.print(":");

                            if(second < 10) { lcd.print("0"); delay(keypad_delay);}

                            lcd.print(second,DEC);

                            if (millis() - previousMillis > interval) {

                                 previousMillis = millis();

                                 counter_delay = counter_delay -1; }           

                            if (detectKey() == 3) {break;}

                            }

                    counter_delay = 0; lcd.clear();

                  }

//********************************************************************************

*****************************                

void lifesupport (){ //**********RUNS IN BACKGROUND/ MAIN PROGRAM********************

                      

                    LED_levels_output ();

                    ledtemp ();

                    ledfancontrol ();

                    watertemp ();

                    autotopoff ();

                    heatercontrol ();

                    //wavemaker ();

                    ph_value ();  

                  }

 //********************************************************************************

****************************

void logdata (){ int minute, second;

                    if ((minute == 10,20,30,40,50,0) && (second == 30)){ watertemplog (); heatsinklog ();}

                  }

 

//********************************************************************************

****************************

void watertemplog (){

                    Serial.print(Whole);Serial.print(".");

                    if (Fract < 10){Serial.print("0");}

                    Serial.println(Fract);

                    }

 //********************************************************************************

***************************

void heatsinklog (){

                    Serial.println(tempF, DEC);}

//********************************************************************************

****************************

void weather (){long interval = 999000;

                    if (millis() - prevMillis > interval) {

                     prevMillis = millis();

                      weatherstate = random(1,5);

                      Serial.print ("weather");

                      Serial.println (weatherstate);}

                  }

                  

  //********************************************************************************

**************************

void lightning (long interval,int l){

                  if (millis() - previousMillis > interval) {

                   previousMillis = millis(); lightningstate = random(l);}

                 }

 //********************************************************************************

***************************

void clouds (long interval,int c){

                  if (millis() - preMillis > interval) {

                   preMillis = millis(); cloudstate = random©;

                     Serial.print ("Clouds"); Serial.println (cloudstate);}

                   }

 //********************************************************************************

**************************

Link to comment

Nice, bookmarked for next time I feel like messing with my arduino (I hate it so bad because it is hard for me lol.) I have a controllable pump and dimmable LEDs and I have a ton of things I want to do with the weather.

Link to comment

Quick question to all you guys messing with arduino.

Im curious to know what you guys do for a living and what degree's you hold under your belts ?

Link to comment
Quick question to all you guys messing with arduino.

Im curious to know what you guys do for a living and what degree's you hold under your belts ?

Well, I have no degrees, and well.......I cut wood for a living :o

I just did my research and hacked away at it, once you "get it" it is actually VERY easy.

Link to comment
what kind of lights are you controlling?

 

LEDs have the ability to have variable light output. Each LED can be anywhere from 0 output to 100% output, based upon the current that powers them.

 

Other lights don't really have this, without sequentially turning lights on or off for an overall effect(say a sunrise or sunset).

 

So what does the arduino do?

 

An Arduino is a small inexpensive controller, it has the ability to be programmed to provide variable outputs to the LED power supply, in this case.

 

They can also be used to control temps, lights, alarms, automatic top offs, dosers, pH, ORP, or just about anything that you can think of.

Link to comment

Smorrow, could you post some pictures of your layout and a FTS? I'm interested in your LCD/Keypad placement.

 

Also, did you do your research on Arduino playground? Where'd you do your research to get some awesome results like that?

Link to comment
  • 1 year later...

Have you tried changing up the following:

 

byte bled[96] = {  1, 1, 1, 1, 1, 1, 1, 1,  //0 - 1  1, 1, 1, 1, 1, 1, 1, 1,  //2 - 3  1, 1, 1, 1, 3, 15, 15, 15,  //4 - 5  23, 23, 23, 23, 23, 30, 30, 30,  //6 - 7  30, 50, 70, 90, 110, 130, 130, 130,  //8 - 9  150, 150, 150, 230, 230, 230, 230, 230,  //10 - 11  230, 230, 230, 230, 230, 230, 230, 230,  //12 - 13  230, 230, 230, 230, 230, 230, 230, 230,  //14 - 15  230, 230, 230, 230, 230, 230, 230, 230,  //16 - 17  110, 90, 70, 50, 30, 10, 10, 10,  //18 - 19  1, 1, 1, 1, 1, 1, 1, 1,  //20 - 22  1, 1, 1, 1, 1, 1, 1, 1	//22 - 23};  byte wled[96] = {  0, 0, 0, 0, 0, 0, 0, 0,  //0 - 1  0, 0, 0, 0, 0, 0, 0, 0,  //2 - 3  0, 0, 0, 0, 2, 4, 24, 24,  //4 - 5  30, 30, 30, 35, 35, 35, 40, 40,  //6 - 7  40, 60, 60, 80, 80, 100, 100, 100,  //8 - 9  120, 140, 160, 200, 200, 200, 200, 200,  //10 - 11  200, 200, 200, 200, 200, 200, 200, 200,  //12 - 13  200, 200, 200, 200, 200, 200, 200, 200,  //14 - 15  200, 200, 200, 200, 200, 200, 200, 200,  //16 - 17  80, 80, 60, 40, 40, 20, 20, 20,  //18 - 19  0, 0, 0, 0, 0, 0, 0, 0,  //20 - 22  0, 0, 0, 0, 0, 0, 0, 0	//22 - 23};  //White LED array in RAMbyte bled_out;byte wled_out;

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recommended Discussions

×
×
  • Create New...