PDA

View Full Version : (Another) DIY LED Controller - Simple Arduino Style


Pages : 1 2 3 4 5 [6] 7

crazyreef09
02/16/2012, 12:17 PM
int blueramptime = 60 ; // time for blue LEDs to dim on and off in minutes
int whiteramptime = 120 ; // time for white LEDs to dim on and off in minutes
int photoperiod = 240 ; // amount of time array is on at full power in minutes
int ontime = 12 ; // time of day (hour, 24h clock) to begin photoperiod

So from here the blue light starts at 12 and fades in for the first 60 minutes and then what? Does the White light starts fading in at this point or does the 120 minutes are counted from 12 pm? The white will start ramping in after the 60min mark. Then it will continue to ramp up for the next 120 min. I am confused, can anyone clarify this?

then after the white have fully ramp up, it will stay there for the next 4 hours. Then it will start to ramp down, white first for 2 hours then blue for 1 hour.

Hope this helps.

Thanks a lot for the help katchupoy, this clarifies my problem.

As for problem #2 for the temperature probe I am still having problems, yesterday I had it all working and today the temperature was basically stuck at 76 and when I uploaded a new code it showed 185F. Can the probe be bad? I did wire the 4k7 resistor. Any help will be appreciated.

crazyreef09
02/16/2012, 01:46 PM
I think I figured out what my problem with the temperature is.
The temperature readings are getting stuck once the arduino is doing the fading of the blues and whites, once that is done and the leds are at 0 or 255 the temp readings become actual temp readings. So whatever the last temp reading was when the fading starts is the reading that will be shown until the fading is over. The alarm will not even respond during this stage even if the temp shown is lower than the set temp for the alarm.

Did anybody else notice this? I am using Version_1_00_16x2. Do the other versions have the same problem or was it fixed? Thanks.

katchupoy
02/16/2012, 09:30 PM
I think I figured out what my problem with the temperature is.
The temperature readings are getting stuck once the arduino is doing the fading of the blues and whites, once that is done and the leds are at 0 or 255 the temp readings become actual temp readings. So whatever the last temp reading was when the fading starts is the reading that will be shown until the fading is over. The alarm will not even respond during this stage even if the temp shown is lower than the set temp for the alarm.

Did anybody else notice this? I am using Version_1_00_16x2. Do the other versions have the same problem or was it fixed? Thanks.

I will bump this for you so that others can see your issues. I am sorry that I cannot help you with this since my original build does not have this feature.
Hope others can help you.

buck27
02/21/2012, 11:34 AM
I just ordered a bunch of stuff so I will be trying to build a controller as well. I hope you don't mind alot of questions and providing some help as I have zero experience with programming and zero experience with electronics but if I ask the right questions and get the right guidance I should be able to this (I hope) thanks guys.

katchupoy
02/21/2012, 12:07 PM
Im sure what you are looking for is here somewhere. Just keep on reading, i guess.

Dan_Cochran
02/27/2012, 03:17 PM
katchupoy, Very long, but Very informative thread. Nice Job to all ! Thank you!

I have never worked with a arduino before, and so far there is so much info here my controller is almost complete.

main parts i have are SainSmart Arduino Uno w/ the 16x2 button sheld, SainSmart 4 relay 5v module, rtc. 2 temp from ebay, and cree led, three 48p drivers 12 white 24 blue and the 10v wall plug from rapid

I still am in the process of putting everything in the radio shack project box's, but have some Questions.

I have not tested the drivers yet with this but the relays are giving me issues. relay 1 and 2 seem to click on and off correct, but 3 and 4 have issues.
but temps and clock works

digital
pin 13 relay 1 Powerhead
pin 12 open
pin 11 led white
pin 3 led blue
pin 2 relay 2 other powerhead
pin 1 temps
pin 0 moon or sump light "not installed yet on tank, another non dim driver cree led"


analog
a1 "set to ph, have no clue when i would build this"
a2 "want for relay 3" for fuge light
a3 Relay 4 " to fun my fans"
a4 and a5 for RTC


i will post the code in a min. see is anyone can fix a few issues. Thanks

Dan_Cochran
02/27/2012, 03:19 PM
code i am having issues with

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h> // Comunication I2C
#include <LiquidCrystal.h>
#include <DS1307.h>
#include "RTClib.h"
#define DS1307_I2C_ADDRESS 0x68 //set rtc
#define ONE_WIRE_BUS 1 //Define the pin of the DS18B20

#define DISPLAYTIMEOUT 2000 // every second next screen
unsigned long lastDisplay = 0;

int screenID = 0;

/************************************************* H A R D W A R E **********************************************************************/

int fuge = A2; // fuge light power relay connected to analog pin 1
int heater = 31; // Heater
int fan = A3; // Fan power relay connected to analog pin 0 is pin2
int moon = 0; // moon light connected to digital pin 3
int ph_probe = 28; // pH probe on Analog 1
int orp_probe = 29; // ORP probe on Analog 2
int alarm = 41; // Alarm

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| R E L A Y P A R T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S I M P L E O N A N D O F F F E A T U R E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



const int ledPin1 = 13; // pin number for relay 1
const int ledPin2 = 2; // pin number for relay 2


int ledState1 = LOW;
int ledState2 = HIGH;
long previousMillis1 = 0;
long previousMillis2 = 0;
long interval1 = 3000; // interval at which to blink (milliseconds) for RELAY1
long interval2 = 3000; // interval at which to blink (milliseconds) for RELAY2


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L E D D I M M I N G P A R T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| F A D E S I N A N D O U T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



int blueramptime = 60 ; // time for blue LEDs to dim on and off in minutes
int whiteramptime = 120 ; // time for white LEDs to dim on and off in minutes
int bluemin = 0 ; // minimmum dimming value of blue LEDs, range of 0-255
int bluemax = 255 ; // maximum dimming value of blue LEDs, range of 0-255
int whitemin = 0 ; // minimum dimming value of white LEDs, range of 0-255
int whitemax = 255 ; // maximum dimming value of white LEDs, range of 0-255
int photoperiod = 360 ; // amount of time array is on at full power in minutes
int ontime = 7 ; // time of day (hour, 24h clock) to begin photoperiod fade in
int blue = 3; // blue LEDs connected to digital pin 3 (pwm)
int white = 11; // white LEDs connected to digital pin 11 (pwm)


//int bluepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 }; // this line is needed if you are using meanwell ELN60-48D
//int whitepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 }; // these are the values in 10% increments

int bluepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 }; // this line is needed if you are using meanwell ELN60-48P
int whitepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 }; // these are the values in 10% increments

/*************************************************************************** A T O *******************************************************/
int ato_time_day = 0; // Number of seconds the ATO runs each time during day time.
int ato_time_night = 0; // Number of seconds the ATO runs each time during night time.
int ato_time = 0; // Number of seconds for the ATO to run each time the switch is on.
int ato_count = 0; // Counts how many time ATO is active (ato_count X 50 ml = ml/day)
int ato_hour = 0;




#define NUMREADINGS_ph 60
int readings_ph[NUMREADINGS_ph]; // The readings from the analog input
#define NUMREADINGS_orp 60
int readings_orp[NUMREADINGS_orp]; // The readings from the analog input

int index_ph = 0; // The index of the current pH reading
int index_orp = 0; // The index of the current ORP reading

int total_orp = 0;
int total_ph = 0;

int average_orp = 0;
int average_ph = 0;
int orp_val = 350; // Comment out after done testing
int orp_Low, orp_High, ph_val, ph_Low, ph_High, Whole, Fract;


LiquidCrystal lcd(8,9,4,5,6,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);
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| R T C C L O C K D S 1 3 0 7 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



byte decToBcd(byte val) // Convert normal decimal numbers to binary coded decimal
{
return ( (val/10*16) + (val%10) );
}


byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers
{
return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : O N E S E C O N D |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



void onesecond() //function that runs once per second while program is running
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if (millis() - lastDisplay > DISPLAYTIMEOUT )
{
lastDisplay = millis();
doDisplay();
}
lcd.setCursor(0, 0);
if(hour>0)
{
if(hour<=12)
{
lcd.print(hour, DEC);
}
else
{
lcd.print(hour-12, DEC);
}
}
else
{
lcd.print("12");
}
lcd.print(":");
if (minute < 10) {
lcd.print("0");
}
lcd.print(minute, DEC);
//lcd.print(":");
//if (second < 10) {
// lcd.print("0");
//}
//lcd.print(second, DEC);
if(hour<12)
{
lcd.print("AM");
}
else
{
lcd.print("PM");
}
lcd.print(" ");

lcd.setCursor(8,0);
lcd.print(month,DEC);
lcd.print("/");
lcd.print(dayOfMonth,DEC);
lcd.print("/");
lcd.print(year,DEC);
lcd.print(" ");
delay(1000);
}


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S C R O L L P A R T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void doDisplay()
{
screenID = constrain(screenID, 0, 5);
switch(screenID)
{
case 0 : lcd.clear();
lcd.setCursor(0, 1);
lcd.print("W Temp: ");
lcd.print(sensors.getTempFByIndex(0));
lcd.print((char)223);
lcd.print("F");

break;
case 1 : lcd.clear();
lcd.setCursor(0, 1);
lcd.print("L Temp: ");
lcd.print(sensors.getTempFByIndex(1));
lcd.print((char)223);
lcd.print("F");
break;
case 2 : lcd.clear();
lcd.setCursor(0,1);
lcd.print("Heat:");
lcd.setCursor(5,1);
if(digitalRead(heater) == HIGH){lcd.print("On");}
else{lcd.print("Off");}
lcd.setCursor(9, 1);
lcd.print("Fan:");
lcd.setCursor(13,1);
if(analogRead(fan) == 255){lcd.print("On");}
else{lcd.print("Off");}
break;
case 3 : lcd.clear();
lcd.setCursor(0,1);
lcd.print("Moon:");
lcd.setCursor(5,1);
if(digitalRead(moon) == HIGH){lcd.print("On");}
else{lcd.print("Off");}
lcd.setCursor(8, 1);
lcd.print("Fuge:");
lcd.setCursor(13,1);
if(analogRead(fuge) == 255){lcd.print("On");}
else{lcd.print("Off");}
break;
case 4 : lcd.clear();
lcd.setCursor(0,1);
lcd.print("pH:");
if (Whole >= 10) {
Whole = 9;
}
lcd.print(Whole, DEC);
lcd.print(".");
if (Fract < 10){
lcd.print("0");
}
lcd.print(Fract, DEC);
break;
case 5 : lcd.clear();
lcd.setCursor(1,1);
lcd.print("ORP:");
//lcd.print("Do Not Touch !");
lcd.setCursor(5,1);
lcd.print(orp_val);
lcd.setCursor(8,1);
lcd.print("mV");
break;

default: // should not happen => reset screenID
screenID = 0;
break;
}
screenID++; // sert next screen
if (screenID > 5) screenID = 0; // wrap around if all screens done
}



/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : F U G E L I G H T O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void FugeOn()
{
//digitalWrite(fuge, HIGH);
analogWrite(fuge, 255);
//lcd.setCursor(7, 3);
//lcd.print("On ");


}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : F U G E L I G H T O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void FugeOff()
{
//digitalWrite(fuge, LOW);
analogWrite(fuge, 0);
//lcd.setCursor(7, 3);
//lcd.print("Off");


}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOn()
{
digitalWrite(moon, HIGH);
//lcd.setCursor(8, 1);
//lcd.write(4);
//lcd.write(5);


}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOff()
{
digitalWrite(moon, LOW);
//lcd.setCursor(8, 1);
//lcd.write(6);
//lcd.write(7);


}

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : R E L A Y 1 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

void relay1() //FUNCTION TO TURN ON AND OFF RELAY 1.
{
unsigned long currentMillis = millis();

if(currentMillis - previousMillis1 > interval1)
{
previousMillis1 = currentMillis;
if (ledState1 == LOW)
ledState1 = HIGH;
else
ledState1 = LOW;
digitalWrite(ledPin1, ledState1);
}
}



/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : R E L A Y 2 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

void relay2()
{
unsigned long currentMillis2 = millis();

if(currentMillis2 - previousMillis2 > interval2)
{
previousMillis2 = currentMillis2;
if (ledState2 == LOW)
ledState2 = HIGH;
else
ledState2 = LOW;
digitalWrite(ledPin2, ledState2);
}
}

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S E T U P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

void setup(){

pinMode(ledPin1, OUTPUT); // set the digital pin as output:
pinMode(ledPin2, OUTPUT); // set the digital pin as output:
pinMode(heater, OUTPUT); //Set Heater Relay
pinMode(fan, OUTPUT); // Set analog pin 0 as a output 2
pinMode(fuge, OUTPUT); // Set analog pin 1 as a output 3
pinMode(moon, OUTPUT); // Set analog pin 3 as a output
pinMode(alarm, OUTPUT); // digital pin for alarm as output


digitalWrite(alarm, LOW); // set Alarm low

sensors.begin(); // Start up the DS18B20 Temp library

for (int i = 0; i < NUMREADINGS_ph; i++) /* reset vector values */
readings_ph[i] = 0;
for (int i = 0; i < NUMREADINGS_orp; i++) /* reset vector values */
readings_orp[i] = 0;

delay(1000);

int High = 0;
int Low = 10000;

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S E T U P - D I S P L A Y |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



byte second, minute, hour, dayOfWeek, dayOfMonth, month, year, mil_time;
Wire.begin();

mil_time = (hour + minute); // Create military time output [0000,2400)
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 00;
minute = 02;
hour = 10;
dayOfWeek = 4; // Sunday is 0
dayOfMonth = 23;
month = 2;
year = 12;
//Use the next line for setting the clock setDateDs1307(sec
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

analogWrite(blue, bluemin);
analogWrite(white, whitemin);

lcd.begin(16, 2); // set up the LCD's number of rows and columns:
// Print a message to the LCD.
lcd.setCursor(1, 0);
lcd.print("My Reef Tank");
lcd.setCursor(2, 1);
lcd.print("Ver 2.00");
delay(5000);
lcd.clear();

//lcd.setCursor(7, 1);
//lcd.print("M:");



}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/




void loop()
{
onesecond();
relay2();
relay1();





/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - D I M F U N C T I O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

float fSecond, fHour, fMinute; //turn the times read from the RTC into float for math ops
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; //declare variables to hold the times

getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); //read the RTC times
int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes


int bluerampup;
if (daybyminute >= (ontime*60))
bluerampup = (((ontime*60) + blueramptime) - daybyminute);
else
bluerampup = blueramptime;

int whiterampup;
if (daybyminute >= (ontime*60 + blueramptime))
whiterampup = (((ontime*60) + blueramptime + whiteramptime) - daybyminute);
else
whiterampup = whiteramptime;

int whiterampdown;
if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
whiterampdown = (((ontime*60) + photoperiod + blueramptime + 2*whiteramptime) - daybyminute);
else
whiterampdown = whiteramptime;

int bluerampdown;
if (((ontime * 60) + photoperiod + blueramptime + 2*whiteramptime) <= daybyminute)
bluerampdown = (((ontime*60) + photoperiod + 2*blueramptime + 2*whiteramptime) - daybyminute);
else
bluerampdown = blueramptime;






/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - F A D E I N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


if (daybyminute >= (ontime*60))
{
if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime/10*9))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
{

// Turn the fuge off.
FugeOff();
// Turn the moon lights off.
MoonOff();
// fade blue LEDs in from min to max.

for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0%
{
analogWrite(blue, bluepercent[i]);
//lcd.setCursor(10, 0);
//lcd.print(i);
//lcd.print(" ");

int countdown = ((bluerampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay2();
relay1();
}
}

// fade white LEDs in from min to max.
for (int i = 1; i <= 10; i++) // setting i value for 10% increment. Start with 0%
{
analogWrite(white, whitepercent[i]);
//lcd.setCursor(14, 0);
//lcd.print(i);
//lcd.print(" ");

int countdown = ((whiterampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay2();
relay1();
}
}
}
}


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - M A X V A L U E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



if (daybyminute >= ((ontime * 60) + blueramptime + whiteramptime))
{
if ( daybyminute < ((ontime * 60) + blueramptime + whiteramptime + photoperiod)) // if time is in range of photoperiod, turn lights on to maximum fade value
{

// Turn the fuge off.
FugeOff();
// Turn the moon lights off.
MoonOff();

analogWrite(blue, 255);
//lcd.setCursor(10, 0);
//lcd.print(10);
//lcd.print(" ");
analogWrite(white, 255);
//lcd.setCursor(14, 0);
//lcd.print(10);
//lcd.print(" ");

}
}



/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - F A D E O U T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
{
if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/10*9)) >= daybyminute)
{

// Turn the fuge off.
FugeOff();
// Turn the moon lights off.
MoonOff();

// fade white LEDs out from max to min in increments of 1 point:
for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
{
analogWrite(blue, 255);
//lcd.setCursor(10, 0);
//lcd.print(10);
//lcd.print(" ");

analogWrite(white, whitepercent[i]);
//lcd.setCursor(14, 0);
//lcd.print(i);
//lcd.print(" ");

int countdown = ((whiterampdown*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay2();
relay1();
}

}

// fade blue LEDs out from max to min in increments of 1 point:
for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
{
analogWrite(blue, bluepercent[i]);
//lcd.setCursor(10, 0);
//lcd.print(i);
//lcd.print(" ");

int countdown = ((bluerampdown*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay2();
relay1();
}
}
}
}

// DS18B20 display
sensors.requestTemperatures(); // Send the command to get temperatures
delay(250);


float temp1=0, temp2=0;

//lcd.setCursor(13, 1);
//lcd.print("Led Temp:");
temp1= sensors.getTempFByIndex(1);
//lcd.print(sensors.getTempFByIndex(1));
//lcd.print((char)223);
//lcd.print("F");

// lcd.setCursor(2, 1);
// lcd.print("Tank Temp: ");
temp2= sensors.getTempFByIndex(0);
// lcd.print(sensors.getTempFByIndex(0));
// lcd.print((char)223);
// lcd.print("F");

if ( (temp1) > 81 )
{
// digitalWrite(fan, HIGH);
analogWrite(fan, 255);
digitalWrite(alarm, HIGH);
delay(1000);
digitalWrite(alarm, LOW);
}
else if ( (temp1) < 77 )
{
//digitalWrite(fan, LOW);
analogWrite(fan, 0);
}

if ( (temp2) < 78 )
{
digitalWrite(heater, HIGH);
digitalWrite(alarm, HIGH);
delay(1000);
digitalWrite(alarm, LOW);
}
else if ( (temp2) > 80 )
{
digitalWrite(heater, LOW);
}
// lcd.print(sensors.getTempCByIndex(0));
// lcd.print((char)223);
// lcd.print("C");


/* ORP on line 1 ****************************************************************************************/
if((second % 10) == 0) {
total_orp -= readings_orp[index_orp]; // subtract the last reading
readings_orp[index_orp] = analogRead(orp_probe); // read from the sensor
total_orp += readings_orp[index_orp]; // add the reading to the total
index_orp = (index_orp + 1); // advance to the next index
if (index_orp >= NUMREADINGS_orp) { // if we're at the end of the array...
index_orp = 0;
} // ...wrap around to the beginning
average_orp = total_orp / NUMREADINGS_orp; // calculate the average
orp_val = (1.15 * average_orp);
orp_Low = min(orp_Low, orp_val);
orp_High = max(orp_High, orp_val);
}

//lcd.setCursor(1,2);
//lcd.print("ORP:");
//lcd.setCursor(5,2);
//lcd.print(orp_val);
//lcd.setCursor(8,2);
//lcd.print("mV");


//Display Low ORP ***************************************************************************************
//lcd.setCursor(1,10);
//lcd.print(orp_Low, DEC);
//lcd.setCursor(1,14);
//lcd.print("-");

//Display High ORP **************************************************************************************
//lcd.setCursor(1,16);
//lcd.print(orp_High, DEC);




/***********PH Probe**********************************************************************************************/
// To calibrate ph probe set 7ph to 2V and 10PH to 1V

total_ph -= readings_ph[index_ph]; // subtract the last reading
readings_ph[index_ph] = analogRead(ph_probe); // read from the sensor
total_ph += readings_ph[index_ph]; // add the reading to the total
index_ph = (index_ph + 1); // advance to the next index
if (index_ph >= NUMREADINGS_ph) { // if we're at the end of the array...
index_ph = 0;
} // ...wrap around to the beginning
average_ph = total_ph / NUMREADINGS_ph; // calculate the average
ph_val = (-1.47 * average_ph + 1300); // ph is stored 100 times value
ph_Low = min(ph_Low, ph_val);
ph_High = max(ph_High, ph_val);
Whole = (ph_val / 100); // separate off the whole and fractional portions
Fract = (ph_val % 100);

//lcd.setCursor(11,2);
//lcd.print("pH:");
//if (Whole >= 10) {
//Whole = 9;
//}
//lcd.print(Whole, DEC);
//lcd.print(".");
//if (Fract < 10){
//lcd.print("0");
//}
//lcd.print(Fract, DEC);

//*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Night Time |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

if (((ontime * 60) + photoperiod + (2 * blueramptime) + (2 * whiteramptime)) < daybyminute)
{

FugeOn();
MoonOn();
// digitalWrite(fan, HIGH);
}
// if (daybyminute < (ontime*60))
//{
//
// FansOn();
//
//}

} // END LOOP

Dan_Cochran
02/27/2012, 03:50 PM
well, i guess my temps are not working, they stay the same now, but before i was playing with the code they did work

katchupoy
02/27/2012, 08:33 PM
maybe the same issue with crazyreef at post #1252 ???

SchnitzelReef
02/27/2012, 09:44 PM
So now the real question...???? How much for you to build one for me?? lol but seriously...? i would def be interested if u were building these and selling them...let me know

Dan_Cochran
02/28/2012, 07:42 AM
maybe the same issue with crazyreef at post #1252 ???

it could be, ill take a look and see if mine does the same..

ok, with the A removed

int fuge = 2; // implace of A2
int fan = 3; // inplace of A3

the relay board leds on relay 3 and 4 shut off and temps read 185 either way, if i unplug them temps, i get -196.60
but with A2 and A3 the leds light on relay 3 and 4

I dont think im switching from analog and digital correct in the code somewhere.
after leds are done ramp i will check again. I did find out im not that great at understanding the code.

Dan_Cochran
02/28/2012, 09:17 AM
I know i have been playing with the code trying to get relay 3 and 4 to work, and tried a different copy of the temp library, but all at about 10 pm temps started working again

crazyreef looks not to be alone

wardda
02/28/2012, 09:32 AM
I am working on getting my LED controller running and I'm reading through the original katchupoy sketch listed on the google source site and I see there are a couple of relays listed ledPin1 and ledPin2. I'm assuming these are physical relays that are turning the meanwells on and off is that correct?

Dan

Dan_Cochran
02/28/2012, 09:40 AM
ok, I think i am getting on to somthing.

I dont think this should be working like this, its like the uno is confused on what pins i am saying what is on.

I was playing around and when i had issues with temps and changed the delay that i thought was for getting temps.

while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay2();
relay1();
}
}
}
}

// DS18B20 display
sensors.requestTemperatures(); // Send the command to get temperatures
delay(100); // This is what i changed, it was 250

float temp1=0, temp2=0;

//lcd.setCursor(13, 1);
//lcd.print("Led Temp:");
temp1= sensors.getTempFByIndex(1);
//lcd.print(sensors.getTempFByIndex(1));
//lcd.print((char)223);
//lcd.print("F");

// lcd.setCursor(2, 1);
// lcd.print("Tank Temp: ");
temp2= sensors.getTempFByIndex(0);
// lcd.print(sensors.getTempFByIndex(0));
// lcd.print((char)223);
// lcd.print("F");

if ( (temp1) > 81 )
{
// digitalWrite(fan, HIGH);
analogWrite(fan, 255);
digitalWrite(alarm, HIGH);
delay(1000);
digitalWrite(alarm, LOW);
}

when i changed it, relay 4 on the board pin a3 ,it shut on and off faster
temps still work.

I simply dont think the code is telling the uno to use the correct pins for stuff going from analog to digital.

katchupoy
02/28/2012, 10:44 AM
@wardda...

In my orginal sketch. I have 4 pins assigned.

Two pins will be assigned on pwm that will control the drivers. This also means it will only control two channels. White and Blue.

Another two (analog) pins are used to control relays. These relays are meant for physical 5 volt relays that control power heads. This will simulate wavemaker.

Hope this helps.

@Dan....

I wish I could help. But the original sketch of mine did not include temp on it. Like what I've told wardda, my limited knowledge only extends to controlling the light via PWM and controlling powerheads via analog thru 5v relays.

katchupoy
02/28/2012, 11:03 AM
Dan if you look at my original sketch (http://66.213.194.54/__CADDNIMA/myreef/IMAGES/2011-01-30%20-%20ARDUINO/2011-02-26%20-%20LED%20Controller.txt). I believe the only way to incorporate something without it waiting for the whole thing to finish is to incorporate it within the "LOOP"

Example, I created/defined a "function" relay1 and relay2. If I will add this after the loop, then what happens is it will wait for the whole light function to finish and then it will run relay1 and relay2.

Again, this is coming from a person who has very limited knowlede with sketching...

So I ended up doing is,

1) define the function. (in your case... your temp)

void relay1() //FUNCTION TO TURN ON AND OFF RELAY 1.
{
unsigned long currentMillis = millis();

if(currentMillis - previousMillis1 > interval1)
{
previousMillis1 = currentMillis;
if (ledState1 == LOW)
ledState1 = HIGH;
else
ledState1 = LOW;
digitalWrite(ledPin1, ledState1);
}
}


2) then insert it inside the "LOOP"


........ int countdown = ((whiterampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay2();
relay1();
}
}
}
}

katchupoy
02/28/2012, 11:08 AM
I apologize if I am no help. I was not able to follow the more advanced sketches because they went so fast and I got left behind. Im beginning to get the itch again, maybe I will have courage to move to the next level...

I want, temp controller and maybe a PH monitor or something. Im not even sure if this is possible. I already have the PH probe, so I guess why not?

katchupoy
02/28/2012, 11:36 AM
katchupoy, Very long, but Very informative thread. Nice Job to all ! Thank you!

I have never worked with a arduino before, and so far there is so much info here my controller is almost complete.

main parts i have are SainSmart Arduino Uno w/ the 16x2 button sheld, SainSmart 4 relay 5v module, rtc. 2 temp from ebay, and cree led, three 48p drivers 12 white 24 blue and the 10v wall plug from rapid

I still am in the process of putting everything in the radio shack project box's, but have some Questions.

I have not tested the drivers yet with this but the relays are giving me issues. relay 1 and 2 seem to click on and off correct, but 3 and 4 have issues.
but temps and clock works

digital
pin 13 relay 1 Powerhead
pin 12 open
pin 11 led white
pin 3 led blue
pin 2 relay 2 other powerhead
pin 1 temps
pin 0 moon or sump light "not installed yet on tank, another non dim driver cree led"


analog
a1 "set to ph, have no clue when i would build this"
a2 "want for relay 3" for fuge light
a3 Relay 4 " to fun my fans"
a4 and a5 for RTC


i will post the code in a min. see is anyone can fix a few issues. Thanks

Dan,

Let me explain you something. Im not sure im correct, but it is how i understand it.... maybe this will help you?????


Look at this picture...
http://arduino.cc/en/uploads/Main/ArduinoUno_R3_Front.jpg


Pay special attention on the digital pins on the top... specially the ones with "~" this means that these are the PWM pins very important and very short supply, thats why we need this for PWM purposes only.

And see the lower right corner... it says "ANALOG IN" Im not sure you can use it for controlling too...

So going back to your pin assignments above...
Powerhead relay can be assigned to non pwm pins and not pin13.
Pin1 i believe cannot be used and its reserved


Let me show you what i did on mine.

Pin0 - reserved
Pin1 - reserved
Pin2 - relay1
Pin3 - Blue LED driver (PWM)
Pin4 - LCD
Pin5 - LCD (PWM)
Pin6 - LCD (PWM)
Pin7 - LCD
Pin8 - relay2
Pin9 (free PWM)
Pin10 (free PWM)
Pin11 - White LED driver (PWM)
Pin12 - LCD
Pin13 - LCD

So right now I have Pin 9 & 10, both PWM still free for other use.

Hope this helps.




.

wardda
02/28/2012, 11:40 AM
I apologize if I am no help. I was not able to follow the more advanced sketches because they went so fast and I got left behind. Im beginning to get the itch again, maybe I will have courage to move to the next level...

I want, temp controller and maybe a PH monitor or something. Im not even sure if this is possible. I already have the PH probe, so I guess why not?

If you go for the PH probe and temp controller I would love to see it outlined here with your normal step by step attention to detail.

Thanks again for all you have done for this project.

katchupoy
02/28/2012, 12:26 PM
@wardda,

If you ask me concerning lights and relay, then I can help you.... just no temps and PHs for now.

Dan_Cochran
02/28/2012, 01:12 PM
I am working on getting my LED controller running and I'm reading through the original katchupoy sketch listed on the google source site and I see there are a couple of relays listed ledPin1 and ledPin2. I'm assuming these are physical relays that are turning the meanwells on and off is that correct?

Dan

the physical relays 1 and 2 are my wave maker power heads.

I just checked back, and thanks for the info katchupoy.

I think i might just have it. " I also did Alot of google on how arduino code works"
I have been cleaning things up in the code that i will not be using for a while or at all.

So far relay 1 and 2 are on pin 13 and 12 "I changed them", they now are working, along with temps and the fan relay turns on, and off if temp1 or temp2 gets to hot, and shuts fans off at anything under 77

I have not adjusted clock yet to test the relay 4 for sump lights or my led drivers, but that is next.

my pins are now

pin 13 = relay 1
pin 12 = relay 2
pin 11 = led white driver
pin 3 = led blue drivers
pin 2 = open
pin 1 = temps
pin 0 = Moon //not installed on tank yet

pin A0/ 14 i did not use
Pin A1/ 15 open
Pin A2/ 16 Relay 4 for fuge/sumplight
Pin A3/ 17 Relay 3 for Fans
Pin A4 and A5/ 18 & 19 RTC

I found if I use the number 17 for a pin in-place of A3 things seam to work.

In the code I did a search and // a bunch of stuff like PH
All of that stuff i might try later but not for now, I'm too new to the code stuff.

But so far I like the scroll screen option.

One day I might play around and learn how to make a menu option for effects on demand.

I will let you know how everything works out if the other relay for sump light and Led stuff works, I have the full day to play around with it and finish things off.

here is a pic of what i have so far, sorry a little fizzy

http://dancochran.net/wp-content/uploads/2012/02/IMAG0203.jpg

katchupoy
02/28/2012, 03:32 PM
Dan,
what pins are you using for your LCD? Thanks.

Dan_Cochran
02/28/2012, 05:14 PM
LiquidCrystal lcd(8,9,4,5,6,7);

http://dancochran.net/wp-content/uploads/2012/02/lcd-16x2-300x267.jpg

i did not need to wire any of that lcd stuff.

across the top it said 13,12,11,3,2,1,0 open

bottom all the power pins, then No A0, but A1,A2,A3,A4,A5 open

Dan_Cochran
02/28/2012, 05:41 PM
katchupoy, thanks for the idea about the loop

My temps were froze at 185 after i pluged it back in from adding more cords.

this is what i did.




void loop()
{
onesecond();
relay2();
relay1();
sensors.getTempFByIndex(0); // I added this in the LOOP

so far it works, but if it don't, i think it is on the right track

Dan_Cochran
02/28/2012, 09:49 PM
katchupoy, i tried your 2 min led run threw, Post #235

everything works.

My relay and outlet box is not done yet but everything is wired up, tomorrow i should see my led's running off from my arduino.

I don't have anything mounted in my stand yet, but with any luck it should be done tomorrow.


Me and my wife was talking about a switch to bypass the pwm, but later on this week i might look into what kind of code i can find that might allow me to turn lights on 75% or something from using one of the buttons, Just in case I want lights on for a min or 2 after hours, "new frag or something I bring home at night"



For anyone just visiting this thread, There is Alot of info in these 50+ pages.
this is where I got 98% of my info. Take note's as you read them and print the how to wire pics, it will help out Alot when build time comes.
But that is just how I did it.

katchupoy, One Big Hi-Five to you! And everyone else, even the people that only asked questions " it saved me time of asking ;) "

fishyj
02/28/2012, 10:45 PM
I did change it so my lights are controlled by a relay. Everything is working great. I also am using a 20x4 lcd, Here's a copy of my sketch:
/*

REEFCONTROLLER
Orginally by unknown source, modified by Jim H.

*/

#include <OneWire.h>
#include <DallasTemperature.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 //set rtc
#include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins
#define ONE_WIRE_BUS 8 //Define the pin of the DS18B20


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| R E L A Y P A R T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S I M P L E O N A N D O F F F E A T U R E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



const int ledPin1 = A2; // pin number for relay 1 was digital pin 2
const int ledPin2 = A3; // digital pin 3


int ledState1 = LOW;
int ledState2 = LOW;
long previousMillis1 = 0;
long previousMillis2 = 0;
long interval1 = 15000; // interval at which to blink (milliseconds) for RELAY1
long interval2 = 20000;

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L E D D I M M I N G P A R T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| F A D E S I N A N D O U T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



int blueramptime = 0 ; // time for blue LEDs to dim on and off in minutes
int whiteramptime = 0 ; // time for white LEDs to dim on and off in minutes
int bluemin = 0 ; // minimmum dimming value of blue LEDs, range of 0-255
int bluemax = 255 ; // maximum dimming value of blue LEDs, range of 0-255
int whitemin = 0 ; // minimum dimming value of white LEDs, range of 0-255
int whitemax = 255 ; // maximum dimming value of white LEDs, range of 0-255
int photoperiod = 540 ; // amount of time array is on at full power in minutes
int ontime = 12 ; // time of day (hour, 24h clock) to begin photoperiod fade in
int blue = 9; // blue LEDs connected to digital pin 9 (pwm)
int white = 7; // white LEDs connected to digital pin 7 (pwm)
int heater = A0; // heater relay , digital pin 0
int moon = A1; // moon light relay connected to analog pin 1
int heater_on_temp = 78; //Turn on heater at this temp
int heater_off_temp = 80; //turn heater off once below this temp
int backLight = 13;

int bluepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 }; // this line is needed if you are using meanwell ELN60-48D
int whitepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 }; // these are the values in 10% increments


LiquidCrystal lcd( 12, 11, 10, 5, 4, 3, 2); // typically 8, 9, 4, 5, 6, 7
// have to change to free up more pwm pins
// open pins

// 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);

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| R T C C L O C K D S 1 3 0 7 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



byte decToBcd(byte val) // Convert normal decimal numbers to binary coded decimal
{
return ( (val/10*16) + (val%10) );
}


byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers
{
return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}



/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : O N E S E C O N D |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



void onesecond() //function that runs once per second while program is running
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.setCursor(0, 0);
if(hour>0)
{
if(hour<=12)
{
lcd.print(hour, DEC);
}
else
{
lcd.print(hour-12, DEC);
}
}
else
{
lcd.print("12");
}
lcd.print(":");
if (minute < 10) {
lcd.print("0");
}
lcd.print(minute, DEC);
//lcd.print(":");
//if (second < 10) {
// lcd.print("0");
//}
//lcd.print(second, DEC);
if(hour<12)
{
lcd.print("AM ");
}
else
{
lcd.print("PM ");
}
//lcd.print(" ");
delay(1000);
}


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : H E A T E R O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void HeaterOn()
{
digitalWrite(heater, HIGH);
lcd.setCursor(9, 2);
lcd.print("ON ");
//analogWrite(fan, 255);

}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : H E A T E R O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void HeaterOff()
{
digitalWrite(heater, LOW);
lcd.setCursor(9, 2);
lcd.print("OFF");
//analogWrite(fan, 0);

}


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOn()
{
digitalWrite(moon, HIGH);
lcd.setCursor(6,3);
lcd.print("ON ");


}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOff()
{
digitalWrite(moon, LOW);
lcd.setCursor(6,3);
lcd.print("OFF");


}

void backlight()
{
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : R E L A Y 1 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/




void relay1() //FUNCTION TO TURN ON AND OFF RELAY 1.
{
unsigned long currentMillis = millis();

if(currentMillis - previousMillis1 > interval1)
{
previousMillis1 = currentMillis;
if (ledState1 == LOW)
ledState1 = HIGH;
else
ledState1 = LOW;
digitalWrite(ledPin1, ledState1);
}
}

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : R E L A Y 2 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/




void relay2()
{
unsigned long currentMillis2 = millis();

if(currentMillis2 - previousMillis2 > interval2)
{
previousMillis2 = currentMillis2;
if (ledState2 == LOW)
ledState2 = HIGH;
else
ledState2 = LOW;
digitalWrite(ledPin2, ledState2);
}
}




/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S E T U P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


void setup() {
pinMode(ledPin1, OUTPUT); // set the digital pin as output:
pinMode(ledPin2, OUTPUT);
pinMode (heater, OUTPUT);
pinMode(moon, OUTPUT); // Set analog pin 1 as a output
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
sensors.begin(); // Start up the DS18B20 Temp library

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S E T U P - D I S P L A Y |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();

// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 0;
minute = 27;
hour = 6;
dayOfWeek = 2; // Sunday is 0
dayOfMonth = 23;
month = 2;
year = 12;

//Use the next line for setting the clock
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

analogWrite(blue, bluemin);
analogWrite(white, whitemin);
lcd.begin(20, 4); // set up the LCD's number of rows and columns:
lcd.setCursor(0, 3);
lcd.print("Moon:");
lcd.setCursor(0, 1);
lcd.print("Lights:");
lcd.setCursor(0, 2);
lcd.print("Heater:");
}

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

void loop()
{
onesecond();
relay1();
relay2();


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - D I M F U N C T I O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes


int bluerampup;
if (daybyminute >= (ontime*60))
bluerampup = (((ontime*60) + blueramptime) - daybyminute);
else
bluerampup = blueramptime;

int whiterampup;
if (daybyminute >= (ontime*60 + blueramptime))
whiterampup = (((ontime*60) + blueramptime + whiteramptime) - daybyminute);
else
whiterampup = whiteramptime;

int whiterampdown;
if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
whiterampdown = (((ontime*60) + photoperiod + blueramptime + 2*whiteramptime) - daybyminute);
else
whiterampdown = whiteramptime;

int bluerampdown;
if (((ontime * 60) + photoperiod + blueramptime + 2*whiteramptime) <= daybyminute)
bluerampdown = (((ontime*60) + photoperiod + 2*blueramptime + 2*whiteramptime) - daybyminute);
else
bluerampdown = blueramptime;
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - F A D E I N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


if (daybyminute >= (ontime*60))
{
if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime/10*9))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
{

MoonOff();
for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0%
{
analogWrite(blue, bluepercent[i]);

int countdown = ((bluerampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
relay2();
}
}

// fade white LEDs in from min to max.
for (int i = 1; i <= 10; i++) // setting i value for 10% increment. Start with 0%
{
analogWrite(white, whitepercent[i]);
lcd.setCursor(9, 1);
lcd.print("ON ");

int countdown = ((whiterampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
relay2();
}
}
}
}


/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - M A X V A L U E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



if (daybyminute >= ((ontime * 60) + blueramptime + whiteramptime))
{
if ( daybyminute < ((ontime * 60) + blueramptime + whiteramptime + photoperiod)) // if time is in range of photoperiod, turn lights on to maximum fade value
{

MoonOff();

analogWrite(blue, 255);
analogWrite(white, 255);
lcd.setCursor(9, 1);
lcd.print("ON ");

}
}

/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - F A D E O U T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
{
if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/10*9)) >= daybyminute)
{

MoonOff();


// fade white LEDs out from max to min in increments of 1 point:
for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
{
analogWrite(blue, 255);


analogWrite(white, whitepercent[i]);
lcd.setCursor(9, 1);
lcd.print("OFF ");

int countdown = ((whiterampdown*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
relay2();
}

}

// fade blue LEDs out from max to min in increments of 1 point:
for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
{
analogWrite(blue, bluepercent[i]);
int countdown = ((bluerampdown*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
relay2();
}
}
}
}

// DS18B20 display
sensors.requestTemperatures(); // Send the command to get temperatures
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
//

lcd.setCursor(9, 0);
lcd.print(sensors.getTempFByIndex(0));
lcd.print((char)223);
// lcd.print(" F");
// lcd.setCursor(8, 1);
// lcd.print(sensors.getTempFByIndex(1);
if (sensors.getTempFByIndex(0) < heater_on_temp) HeaterOn();
//lcd.setCursor(9, 2);
// lcd.print("ON");
if (sensors.getTempFByIndex(0) > heater_off_temp) HeaterOff();
lcd.setCursor(9, 2);
// lcd.print("OFF");
delay(1000);
//*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Night Time |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

if (((ontime * 60) + photoperiod + (2 * blueramptime) + (2 * whiteramptime)) < daybyminute)
{
MoonOn();
// analogWrite(white, whitepercent[i]);
lcd.setCursor(9, 1);
lcd.print("OFF ");
}

if (daybyminute < (ontime*60))
MoonOn();
{
}
delay(1000);
} // END LOOP

katchupoy
02/29/2012, 10:03 AM
@Dan_C
I just redid this whole setup not so long ago for a friend of mine, and his turned out better than mine. He asked me if he can do show and tell when his friends come over overiding th program, and I said....

No. If you want me to make it as part of program. Not that good with sketch.

Yes. If I do it my way.....

1) If you follow my wiring diagram, you will notice that everything is wired and switched via ground.
2) and I will assume that you also have that potentiometer (knob) to control intensity.
3) what you need is to simply put a toggle switch shorting the ground before the potentiometer.

I'm on a bus right now going to work. But I will make you a sketch on how to wire them so you can also do a show and tell. Specially important when you need (emergency) lights after the scheduled ramp on and off.

katchupoy
02/29/2012, 10:15 AM
@Dan_c

about the 75% or what ever settings. I just use the knob to control mine. No programming needed.

the key is when setting it first time where you are still adjusting the SVR2... I also tested the knob settings.. After setting the knob 100% max and setting the SVR2 to desirable setting, mine at 1amp for XP-G LEDs... Then I started turning the knob down until I hit let say 250ma on my volt meter. Then I made a mark so I kmow where 250ma on the knob was. Also 250ma is equal to 25% intensity.

just don't rely on the knobs 50% is equal to halfway turn.... Its not linear.... You have to do it via volt reading via resistors and see where 250ma 500ma and 750ma is.... Then with this... Even if you have different series of LEDs for the blue, you can match it with white via ma readings.

example. I can easily set mine... 250ma for blues and 250 ma for white... Even though my blues can only do 750ma max.... While white can do 1000ma max.

at least this way you easily say that this setting is literally 1:1 or 1:2 etc...

hope this helps.

.

katchupoy
02/29/2012, 10:22 AM
@Fishy.

what do you mean you use relay for your lights. Can clarify?

1) if its simply on and off then relay works.
2) if you are using the relay to ramp up or down your lights, I believe relay will not work. Specially applying pwm on it. I think they will not be able to handle ultra fast on and off without burning their coils.

my 2 cents.

MassiveReefer
02/29/2012, 12:51 PM
Hello everyone!

First off, thanks for all of the knowledge! Its been most helpful. I finally signed up at RC once i got through the whole thing.

I have been playing around with my arduino now for about a month figuring things out.
Currently i have:
-arduino uno
-LCD shield with 5 buttons from adafruit.com
-24 CREE LEDS
-2x eln-60-48P drivers
-RTC
-handfull of temp sensors
-2 bags of starbucks coffee and a whole lot of ambition

I have the RTC and LCD shield all working off of two i2c wires. I also have all four temp sensors reading in off of one single wire which is nice. Only 3 pins for all of that! I am building the frame to hold the heatsinks this weekend and will hopefully have the leds all wired up and in testing mode next week. I do plan on using my own sketch however. I am a software developer and think it would be more fun and much easier for me to edit and update code that i have wrote myself. I currently have a functional menu set up and working on my lcd to set time, ramp time, max brightness ect. I do also plan on wiring up some relays soon too. Lights are first though. One thing at a time! If anyone else out there is planning on doing this project I not only recommend reading this WHOLE thread but also play around with every arduino tutorial you can find to familiarize yourself with arduino and its code. :reading:

Once again, thanks for all the help from everyone!

I have two quick questions:
-what is the point of the 1k resistor in line with the npn transistors and the PWM pin on the arduino? Is it needed?
-I have seen some people pointing out some relays, but i was wondering if anyone had any suggestions on how to pick them out. Should i go with a relay board or get individual relays? There were posts a while back about isolated relays also that i was a little confussed with. Could anyone shed any light on this for me?

Thanks again

katchupoy
02/29/2012, 01:22 PM
wow massivereefer....

http://www.reefcentral.org/images/welcome.gif

Thank you for reading my build. Please stay in touch since you are way more knowledgeable than me. I will be having a lot of questions in the very near future. congrats on your project, it looks really cool. One wire, two wire, whew!!!! thats way beyond me...

About your question. Do you mean this one after the transistor???

https://2091659669762213990-a-1802744773732722657-s-sites.googlegroups.com/site/caddnima/arduino%2Btransistor%2Bpot_simple.jpg?attachauth=ANoY7coKc7gT1lGpFy4JUldOIxr-Y_gv-h4d54JVmKIzpsZEmkNdQKzS5_1hZUbobSm-Qm9BZz6R_Ork9N0rHJDS8lZ0ixEOs1hnIULZOROEwOccDwnplw7BWEwCkSTFKjbEdsPlWfcEKtyJvCf-OnJAE7hhq1v0LM8spz9vKob8Gh2ufmqz6VOtqFqCvuaxmmjICoIIvtAXJMoj8UCT0muo97un-x0_5l-pxXPwTg6wRnWvoQhrQ7A%3D&attredirects=0

I really dont know...lol... Please read this one instead... (http://arduino.cc/en/Tutorial/DigitalPins) and scroll down to "Properties of Pins Configured as OUTPUT"

Relays for what? Depends on your use and the relay you select. Some relays can handle a lot of amps. Some are even "optically isolated (http://en.wikipedia.org/wiki/Opto-isolator)" which in simple means, no dangerous feedbacks that can kill your arduino. As you can see, Arduino only have 5 volts DC as output, and if you want to control a 300 watt heater then 5 VDC will not cut it.

Relays are also very helpful in removing HIGH CURRENT AC from our reef tank. Example, if you have a top off switch like these (http://autotopoff.com/products/) then those are just simple switches. But if you use this directly to your 110VAC then there is a big potential that water and the AC can short. It can also shock you. Thats where relay comes in. Relays have two sides. The AC side where you connect your lamp or devices, and the DC side where you power the relay via DC voltage. you can buy them in different voltages, but what I used on mine is the 0-6 VDC coil (https://www.google.com/search?q=relay+6+vdc&hl=en&prmd=imvns&source=lnms&tbm=isch&ei=V3pOT7mICqeWiAK5__TGCw&sa=X&oi=mode_link&ct=mode&cd=2&ved=0CE8Q_AUoAQ&biw=1309&bih=630#hl=en&tbm=isch&sa=X&ei=ZHpOT7GoJuakiQKisvWUCw&ved=0CEYQBSgA&q=relay+6vdc&spell=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=4993d4d452d119bb&biw=1309&bih=630)so i can attach it directly to my arduino with similar diagram like this.

http://www.dd-wrt.com/wiki/images/b/b3/Relay_lamp.gif

and the diode "flyback" to protect your arduino if you dont want to go with "optically isolated" route.
http://andrewmohawk.com/wp-content/uploads/2011/11/arduino-relay.png

S2minute
02/29/2012, 03:09 PM
I was woundering. Can any of you program an Arduio(s) with an LCD to do this:

Hi, i'm involved in a DIY LED light fixture project for a reef aqurium. This fixture is 6' long and has 3 sections.
each section has 48 leds for a total of 144. These leds are arranged in series strings of 6 leds each string. Each string will be driven by a CAT4101. Three of the strings however will be all XM-L LEDs @ 1.5 amps and will need to be driven by 2 CATs as each CAT is limited to 1 AMP. The documentation for the CATs states that 2 CAT drivers can be run together for a total of 2 AMPS. The remaining 21 strings will be driven by their own CAT driver. I have 4 CAT driver boards that have 8 CAT drivers each. The LEDs on each of these strings will all be driven @0.7 MA. The PS for the 3 XM-L LED strings will be a Meanwell SP-100-24 @4.5 amps adj +/- 10%.
The remaining 21 strings will be driven by 2 Meanwell SP-320-24 @13A. 10 strings on one PS, the remaining 11 on the other. The Meanwells run on PWM.
What i'm trying to accomplish with an Arduino(s) is to simulate sunrise/sunset via a realtime clock on a LCD display. I would like to accomplish this by dimming UP from east/west one string then the next as to better sim the sunrise with the 3 XM-L LED strings dimming up last to sim mid-day then dim down as the noon day sun progresses. I can do this as the 3 XM-L strings run perpendicular to the rest of the strings and span the 6' length of the fixture. I would aslo like to sim cloudy days, stomy weather and DEFINATELY the lunar cycle.

I really want this for my new fixture. If anyone can tell me what to script in and what hardware i need, i can put it together myself...i believe :) Or if anyone can do it quick i can send them what they want for their troubles :)
Thanks.

MassiveReefer
02/29/2012, 04:42 PM
Ketchup, the image you posted didn’t show up for me but based on what you described, yes that is the resistor I was talking about. After reading the information from Arduino.cc it doesn’t seem necessary to have it. Other than a short, the only reason for it would then be to protect the board from outputting to much current. Since it is only powering a small transistor I am guessing it is not needed however it still might be a good precautionary measure. I may or may not add it, I’m undecided for now.

As for the relays, I want to be able to turn off everything in my aquarium with them.
-2x powerheads
-heater
-return pump
-skimmer
-lights (which brings up a good point)

Sidetrack: I remember reading that the only way you (or it could have been someone else I don’t remember) turn off your lights was by a zero duty cycle(PWM). I have read that this is a bad idea because the driver itself is still sucking up energy. I read that it still uses like 16V but I have not tested that yet since I don’t have my lights up and running yet. Since we all know the amount of power our tanks can consume running 24/7, I think it would be a good idea to hook the leds up to a relay as well.

Back to the main topic… Relays: I guess I should have been more detailed with my previous question. I was looking at something like the following:
http://arduino-direct.com/sunshop/index.php?l=product_detail&p=156

However, there is so many different relays out there, I don’t know where to start from. It seems like these boards would be a lot easier to deal with than 8 individual relays that I would need to mount to something. However, I don’t know if there is any downside to these or anything else.

As for the using three wires for the LCD RTC and temp sensors, it’s actually really easy. If you would like to learn I could point you in the right direction. You pretty much just need a couple library’s and your set. It’s for the most part all of the same function calls as the liquidCrystal library. Lcd.begin lcd.print(“hello world”) lcd.setCursor(1,1) etc. The shield and code take care of the rest. I was actually using a normal 16X2 lcd the whole time I was writing my menu system and it took me a night to get the new one wired in with the RTC. Truthfully the digital temp sensor was the hardest part. There is not as much documentation online about getting these working. Essentially, every digital device like this has its own 64 bit address burned onto the chip. First you need to write a sketch to read the address of each sensor. Then, with that address you are able to read from multiple sensors on the same pin. Aka give me temp from arduino pin 3 using address A, now give me temp from arduino pin 3 using address b. Its real slick.

katchupoy
02/29/2012, 05:13 PM
I was woundering. Can any of you program an Arduio(s) with an LCD to do this:

Hi, i'm involved in a DIY LED light fixture project for a reef aqurium. This fixture is 6' long and has 3 sections.
each section has 48 leds for a total of 144. These leds are arranged in series strings of 6 leds each string. Each string will be driven by a CAT4101. Three of the strings however will be all XM-L LEDs @ 1.5 amps and will need to be driven by 2 CATs as each CAT is limited to 1 AMP. The documentation for the CATs states that 2 CAT drivers can be run together for a total of 2 AMPS. The remaining 21 strings will be driven by their own CAT driver. I have 4 CAT driver boards that have 8 CAT drivers each. The LEDs on each of these strings will all be driven @0.7 MA. The PS for the 3 XM-L LED strings will be a Meanwell SP-100-24 @4.5 amps adj +/- 10%.
The remaining 21 strings will be driven by 2 Meanwell SP-320-24 @13A. 10 strings on one PS, the remaining 11 on the other. The Meanwells run on PWM.
What i'm trying to accomplish with an Arduino(s) is to simulate sunrise/sunset via a realtime clock on a LCD display. I would like to accomplish this by dimming UP from east/west one string then the next as to better sim the sunrise with the 3 XM-L LED strings dimming up last to sim mid-day then dim down as the noon day sun progresses. I can do this as the 3 XM-L strings run perpendicular to the rest of the strings and span the 6' length of the fixture. I would aslo like to sim cloudy days, stomy weather and DEFINATELY the lunar cycle.

I really want this for my new fixture. If anyone can tell me what to script in and what hardware i need, i can put it together myself...i believe :) Or if anyone can do it quick i can send them what they want for their troubles :)
Thanks.

@S2,

Im not really familiar with your hardware ie: CAT drivers. So I cannot help you with this. But maybe I can point you to these people...

http://www.reefcentral.com/forums/showthread.php?t=1759758

Hope this helps.

katchupoy
02/29/2012, 05:22 PM
@MassiveReefer

As for the relays, I want to be able to turn off everything in my aquarium with them.
-2x powerheads
-heater
-return pump
-skimmer

-lights (which brings up a good point) Only On/Off light ie: refugium...

Sidetrack: I remember reading that the only way you (or it could have been someone else I don’t remember) turn off your lights was by a zero duty cycle(PWM). I have read that this is a bad idea because the driver itself is still sucking up energy.


zero duty, thats why all relays must be assigned to non-pwm pins, so you cannot accidentally issue a pwm command.



Back to the main topic… Relays: I guess I should have been more detailed with my previous question. I was looking at something like the following:
http://arduino-direct.com/sunshop/index.php?l=product_detail&p=156

This looks awesome... go for it. just watch out for signal requirement. I mean, if they will run on 0-5 VDC signal then go for it. If you see something about TTL, then its even better.



However, there is so many different relays out there, I don’t know where to start from. It seems like these boards would be a lot easier to deal with than 8 individual relays that I would need to mount to something. However, I don’t know if there is any downside to these or anything else.

No downside, some may need its own powersupply to run its board, but they are more cleaner I believe. Some are in TTL mode, that only needs 1 pin on your arduino board, like the one wire or something.


If you would like to learn I could point you in the right direction.

I will ask you later when i have time... thank you...

S2minute
02/29/2012, 05:27 PM
ok , ty POYIEE >;)

fishyj
03/01/2012, 05:09 AM
First off, Katchupoy, I'd like to say thanks for starting this thread. It was because of you I became interested in this controller. What I did was change the ramp up time to zero and by changing a couple of other things, I have it where the main lights come on at 10, (both white and blue) and both shut off together at the same time. It basically is a timer now. I can either use the off cycle of the light relay to power my moon lights or a separate relay for this. My heat is controlled by a temp probe that shuts the relay on and off. The wave maker is the same,(controlled by 2 relays). I will eventually be trying my hand at redoing my sketch , that hopefully will include a ph and salinity probes and a doser and ato setup. I was not interested in a cloud or lighting program because I only have a bc29.

katchupoy
03/01/2012, 09:45 AM
fishy... That's really cool... I don't have the cloud either (orig sketch) but still your controller has more features than mine. Congrats again.

may I ask why remove he ramp up and down? Is it because of hardware limitations? Maybe using non dimmanle drivers?

fishyj
03/02/2012, 06:16 AM
Katchupoy, I have dimmable drivers but I like them set where they are and all corals are responding great to them. Since having the led's my anemone's have split, corals have doubled in size and the Coralline algae has begun to spread. Did have a problem with some mushrooms shrinking and disappearing and my zoa's have not responded well (still working on that) but overall the color is what I like and their not turned all the way up. When I set up the 55 for saltwater I will be using the ramp up and ramp down feature. I am trying to write a program for a simple timer for my bc29 tank (still learning how to program) so as of now I can use what I have until I write it. It has been a fun project for me and with all the help I have received here and from arduino forum and hours of searching I have been learning slowly. When done with everything I will be posting pictures and details of my project.

katchupoy
03/02/2012, 11:57 AM
fishy, the reason I asked about the instant on and off, is that there were research before about light shock. At least maybe ramp up in 30 min? Or if you want faster then ramp up 10 min? So that will step up every 1 min in 10 steps.?

anyways, that's just me since you already have the hardware and the code....

very cool.. Hope this helps

c

TheReefNinja
03/03/2012, 10:24 AM
I have been having issues lately with my RTC it wont keep the correct time anymore I can set and start the clock then a day or 2 later it freezes on a time and stays there..... anyone else having this issue?

katchupoy
03/03/2012, 11:46 AM
I been having the same issue since day 1. My fix was put the power supply for arduino in timer. I set it a 15 minute off (the smallest you can find there mechanical) just 1 hour before the light starts.

its like resetting arduino every day. The actual time is not affected since the RTC has its own battery.

hope this helps.

Steedy
03/04/2012, 03:15 AM
Hello first I must say nice work man well done.

Next :

I need SW for my arduino my idea about the functions is this :

http://www.youtube.com/watch?v=vHo7LTgkbZ4

what I have in home :

RTC for Arduino
Arduino Uno
Power 12V for arduino

LED ramps - 5modules(pads). each module have a 3lines of Cree LED , 2line together on the sides - Royal + Blue, in the middle is whites.
each pad have together 18x 3W Cree LEDs , 12pcs RB+B and 6Whites. led will be controlled by Cat4101 , 1pcs on 1line.
Power supply for this led ramps is Meanwell SP 320-24.

Controling wia USB, Ethernet , or BT.

I need do for this setup program can anyone do this?

katchupoy
03/04/2012, 12:50 PM
@ Steedy

That is a very cool demo... very nice indeed. I believe it can be done. But not probably on my thread. Since those are way advance. Maybe we can ask the people here (http://www.reefcentral.com/forums/showthread.php?t=1783536).

But just to give you an idea. You will need 2 channels per pad. 1 to control the blue and the other 1 to control the white. Now multiply that with 5, you will end up with 10 channels.

Arduino uno only have 6 PWM pins. So you will need a much bigger set of PWM pins like the Arduino Mega (http://arduino.cc/en/Main/ArduinoBoardMega) that has 14 PWM pins.

And then, its just a matter of tweaking the sketch/code...

Hope this helps.

Steedy
03/05/2012, 01:40 AM
@ Steedy

That is a very cool demo... very nice indeed. I believe it can be done. But not probably on my thread. Since those are way advance. Maybe we can ask the people here (http://www.reefcentral.com/forums/showthread.php?t=1783536).

But just to give you an idea. You will need 2 channels per pad. 1 to control the blue and the other 1 to control the white. Now multiply that with 5, you will end up with 10 channels.

Arduino uno only have 6 PWM pins. So you will need a much bigger set of PWM pins like the Arduino Mega (http://arduino.cc/en/Main/ArduinoBoardMega) that has 14 PWM pins.

And then, its just a matter of tweaking the sketch/code...

Hope this helps.

Thx for your reply and yours informations.
We will se how it done everything. I post here some pictures or my ramps/pads here.

fishyj
03/07/2012, 11:22 PM
Hi all, I just received my relay board and temp probes from China (after a month of waiting) and wanted to hook them up. Here's a link http://www.ebay.com/itm/4-Channel-5V-Relay-extension-board-for-MCU-AVR-51-PIC-ARM-TTL-Arduino-w-LED-NEW-/251009761722?pt=LH_DefaultDomain_0&hash=item3a715901ba#ht_3793wt_932

Well after looking at board, terminal vcc was my 5 volt supply and gnd was ground. Hooked up and indicator light came on. Next to hook up my heater and nothing. After further investigation I found it only works the relays when a ground is supplied. Any ideas what I can do. My program works on supplying power to a relay to turn on , like a heater. :angryfire:

katchupoy
03/08/2012, 09:55 AM
double post.

katchupoy
03/08/2012, 09:57 AM
After looking at the link and pics you gave us, you should connect 3 points on the dc side... 1) vcc = 5v power supply. 2) ground = that comes from the same 5v power supply in no. 1. 3) is the signal from arduino non pwm pin.

Note. That the ground from arduino and the ground in relay should be connected. To be honest I believe that the 5v from arduino can also be used to supply this relay board.

Now on the AC side. You will have 2 points. You will have to choose either normally on or normally off. I chose normally on. So in case of the relay having issues or dying, the relay will stay on... Ie. For powerheads or something.

Quick question. Do you know how to connect the power head or heater to the relay board? I just want to make sure we are on the same page.

fishyj
03/13/2012, 06:59 AM
Okay, I found out that the vcc is your 5v or power supply and gnd is ground. On this board its activates on low (0 volts) and deactivates on high(5v). I found the info out from the arduino forum. The only thing I need to do is change the high and low on my program to get it working. I should have used the single relays like you did. I plan on ordering them and I think I will make my own board with protecting the arduino. I am still working on the wiring and mounting of the outlets, along with testing before going on my tank. I will be using this setup on my 55 that I am converting over so the good thing is I don't need to rush. I just wish I was better at writing the program.

matiLanza
03/13/2012, 11:00 PM
Is Liquidarts still around ??

katchupoy
03/13/2012, 11:07 PM
Hello to all,

I have been re-reading this thread for the past 5 days, and I must say, you guys rock!!!. I did not realize how much information was included in this thread.

It went so FAST, i got left behind. And I have been trying to catch up for the past few days and still there is so much to digest, whew!. i have been reading, taking notes, reading, and taking notes again.

For those of you who asked question and never got answered, i am so sorry. For those code experts out there that had code C+ awakening, thanks for all your contributions. Amazing code, I might say... menus, storm, lightning, PH, temp and so many things. Thank you guys...

Now Im getting ready to start another thread to continue on PHASE TWO

I hope you can follow me along on my next adventure. I know that most of you already been there done that, but I kinda slow so please bear with me here...

hey BTW, Im not giving this thread up... If you still have questions about the original sketch... Fire away...

.

katchupoy
03/13/2012, 11:21 PM
So here are my notes. For those who are just reading this thread, I beg you to read the firs 5 pages or so. Its a really good read.

But if you dont have time... i created a Frequently Asked Question or lets say an Index so you can find things fast.


Frequently Asked Question

What is Arduino? </font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif">&nbsp; &nbsp;&nbsp;</span><a href="http://arduino.cc/en/" style="font-family:arial,sans-serif" target="_blank">Info here</a><span style="color:rgb(0,0,0);font-family:arial,sans-serif">. &nbsp;</span><a href="http://www.reefcentral.com/forums/showthread.php?t=1987110" style="font-family:arial,sans-serif" target="_blank">Page 1, Post 9</a>. <a href="http://tronixstuff.wordpress.com/tutorials/" target="_blank">Tutorial here</a>.

Where to get the Arduino software so I can load the your sketch? </font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif">&nbsp; &nbsp;&nbsp;</span><a href="http://arduino.cc/en/Main/Software" style="font-family:arial,sans-serif" target="_blank">Download it here</a><span style="color:rgb(0,0,0);font-family:arial,sans-serif">.</span>

How to setup the time on the sketch using DS1307? </font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif">&nbsp; &nbsp;&nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=12" target="_blank">Page 12, Post 298</a></span>

I have the ELN 60-48P driver. I want 255 steps instead of 10 steps. How to do this?</font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif"> &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=15" target="_blank">Page 15, Post 365</a>, &nbsp;</span><a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=35" target="_blank">Page 35, Post 851</a>

I want more features, yours is too basic. Where can i find it? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=15" target="_blank">Page 15, Post 373</a>&nbsp;or go to&nbsp;<a href="http://www.reefledcontroller.com/" target="_blank">ReefLedController</a>.

Where to find temp sensors if I want to add it in the future? &nbsp; &nbsp; <a href="http://arduino-direct.com/sunshop/index.php?l=product_detail&amp;p=151" target="_blank">Buy it here</a>.

Im using Buckpucks instead of meanwells, will this work? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=20" target="_blank">Page 20, Post 488</a>

What is Optically Isolated Relays? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=21" target="_blank">Page 21, Post 506</a>

Can I still use or keep a potentiometer with the arduino installed? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=21" target="_blank">Page 21, Post 520</a>

Which is better? 48P driver or 48D driver? &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=23" target="_blank">Page 23, Post 551 and 570</a>

Can I use the LCD buttons? <a href="http://web1.reefcentral.com/forums/showthread.php?t=1987110&amp;page=24" target="_blank">Page 24. Post 581</a>

Can I connect multiple drivers in one pwm pin/channel? &nbsp;Yes. &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=26" target="_blank">Page 26, Post 628</a>

I have 20x4 lcd. Which pin is for backlighting ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=27" target="_blank">Page 27, Post 663 and 668</a></font></span>

Is it possible to scroll text on the 16x2 screen ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=29" target="_blank">Page 29, Post 724</a></span>

Is there a limit of how many drivers you can connect per pin ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=36" target="_blank">Page 36, Post 899</a>, &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=37" target="_blank">Page 37, Post 919</a>

Can i fade in and out the blue and white parallel ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=37" target="_blank">Page 37, Post 908</a>

How to add temp ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=41" target="_blank">Page 41, Post 1014</a>

Coding for the PH probe ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=41" target="_blank">Page 41, Post 1024</a>

Coding for Weather Pattern ? &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1030</a>

Sketch for GLCD screen ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1035</a>

Centralized location of all sketches ? &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1039</a>, &nbsp;and here &nbsp;<a href="http://code.google.com/p/aquatroller/" target="_blank">Liquidarts</a>

Where to get temp probe ? <a href="http://www.satistronics.com/waterproof-ds18b20-waterproof-stainless-steel-encapsulated-temperature-sensor_p2993.html" target="_blank">Buy here</a>, &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1042</a>

Android App ? &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=46" target="_blank">Page 46, Post 1130</a>

Amazing shield by Saltydogaqua... &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=48" target="_blank">Page 48, Post 1187 and 1193</a>

One channel very simple sketch for small tanks... &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=50" target="_blank">Page 50, Post 1244</a>

Arduino Pin assignments I used on this project... &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=51" target="_blank">Page 51, Post 1268</a>


Pin0 - reserved
Pin1 - reserved
Pin2 - relay1
Pin3 - Blue LED driver (PWM)
Pin4 - LCD
Pin5 - LCD (PWM)
Pin6 - LCD (PWM)
Pin7 - LCD
Pin8 - relay2
Pin9 - (free PWM)
Pin10 - (free PWM)
Pin11 - White LED driver (PWM)
Pin12 - LCD
Pin13 - LCD





.

katchupoy
03/13/2012, 11:24 PM
double post

katchupoy
03/13/2012, 11:26 PM
Also, i took the liberty of cleaning up the original sketch, added some wordings so that we can understand it more. Hoping that people new to arduino sketch wont get lost that much, I hope.... You can always go here to my google site.

CADDnima LED Controller Build (https://sites.google.com/site/caddnima/myreeftank/led_controller)

Hope this helps.

bigguyuk
03/14/2012, 05:31 AM
If anyone is interested I am selling complete fixtures and controllers.
Thanks.

How Much Dude :)
Simon

bigguyuk
03/14/2012, 05:47 AM
So here are my notes. For those who are just reading this thread, I beg you to read the firs 5 pages or so. Its a really good read.

But if you dont have time... i created a Frequently Asked Question or lets say an Index so you can find things fast.


Frequently Asked Question

What is Arduino? </font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif">&nbsp; &nbsp;&nbsp;</span><a href="http://arduino.cc/en/" style="font-family:arial,sans-serif" target="_blank">Info here</a><span style="color:rgb(0,0,0);font-family:arial,sans-serif">. &nbsp;</span><a href="http://www.reefcentral.com/forums/showthread.php?t=1987110" style="font-family:arial,sans-serif" target="_blank">Page 1, Post 9</a>. <a href="http://tronixstuff.wordpress.com/tutorials/" target="_blank">Tutorial here</a>.

Where to get the Arduino software so I can load the your sketch? </font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif">&nbsp; &nbsp;&nbsp;</span><a href="http://arduino.cc/en/Main/Software" style="font-family:arial,sans-serif" target="_blank">Download it here</a><span style="color:rgb(0,0,0);font-family:arial,sans-serif">.</span>

How to setup the time on the sketch using DS1307? </font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif">&nbsp; &nbsp;&nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=12" target="_blank">Page 12, Post 298</a></span>

I have the ELN 60-48P driver. I want 255 steps instead of 10 steps. How to do this?</font></span><span style="color:rgb(0,0,0);font-family:arial,sans-serif"> &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=15" target="_blank">Page 15, Post 365</a>, &nbsp;</span><a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=35" target="_blank">Page 35, Post 851</a>

I want more features, yours is too basic. Where can i find it? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=15" target="_blank">Page 15, Post 373</a>&nbsp;or go to&nbsp;<a href="http://www.reefledcontroller.com/" target="_blank">ReefLedController</a>.

Where to find temp sensors if I want to add it in the future? &nbsp; &nbsp; <a href="http://arduino-direct.com/sunshop/index.php?l=product_detail&amp;p=151" target="_blank">Buy it here</a>.

Im using Buckpucks instead of meanwells, will this work? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=20" target="_blank">Page 20, Post 488</a>

What is Optically Isolated Relays? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=21" target="_blank">Page 21, Post 506</a>

Can I still use or keep a potentiometer with the arduino installed? &nbsp; &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=21" target="_blank">Page 21, Post 520</a>

Which is better? 48P driver or 48D driver? &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=23" target="_blank">Page 23, Post 551 and 570</a>

Can I use the LCD buttons? <a href="http://web1.reefcentral.com/forums/showthread.php?t=1987110&amp;page=24" target="_blank">Page 24. Post 581</a>

Can I connect multiple drivers in one pwm pin/channel? &nbsp;Yes. &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=26" target="_blank">Page 26, Post 628</a>

I have 20x4 lcd. Which pin is for backlighting ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=27" target="_blank">Page 27, Post 663 and 668</a></font></span>

Is it possible to scroll text on the 16x2 screen ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=29" target="_blank">Page 29, Post 724</a></span>

Is there a limit of how many drivers you can connect per pin ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=36" target="_blank">Page 36, Post 899</a>, &nbsp; <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=37" target="_blank">Page 37, Post 919</a>

Can i fade in and out the blue and white parallel ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=37" target="_blank">Page 37, Post 908</a>

How to add temp ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=41" target="_blank">Page 41, Post 1014</a>

Coding for the PH probe ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=41" target="_blank">Page 41, Post 1024</a>

Coding for Weather Pattern ? &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1030</a>

Sketch for GLCD screen ? <a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1035</a>

Centralized location of all sketches ? &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1039</a>, &nbsp;and here &nbsp;<a href="http://code.google.com/p/aquatroller/" target="_blank">Liquidarts</a>

Where to get temp probe ? <a href="http://www.satistronics.com/waterproof-ds18b20-waterproof-stainless-steel-encapsulated-temperature-sensor_p2993.html" target="_blank">Buy here</a>, &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=42" target="_blank">Page 42, Post 1042</a>

Android App ? &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=46" target="_blank">Page 46, Post 1130</a>

Amazing shield by Saltydogaqua... &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=48" target="_blank">Page 48, Post 1187 and 1193</a>

One channel very simple sketch for small tanks... &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=50" target="_blank">Page 50, Post 1244</a>

Arduino Pin assignments I used on this project... &nbsp;<a href="http://reefcentral.com/forums/showthread.php?t=1987110&amp;page=51" target="_blank">Page 51, Post 1268</a>


Pin0 - reserved
Pin1 - reserved
Pin2 - relay1
Pin3 - Blue LED driver (PWM)
Pin4 - LCD
Pin5 - LCD (PWM)
Pin6 - LCD (PWM)
Pin7 - LCD
Pin8 - relay2
Pin9 - (free PWM)
Pin10 - (free PWM)
Pin11 - White LED driver (PWM)
Pin12 - LCD
Pin13 - LCD





.

Many Thanks Dude this Post was so helpful to be able to skip to parts
Thanks again for all your Work and Others
Following a few On the Arduino and its been a very Interesting journey so Far :)
Thanks again :)

Cipher43
03/16/2012, 06:23 AM
Has anyone tried using one of these conrollers on a meanwell HLG driver?
I want to build a controller but need to make sure it will work with my drivers. They are the HLG-150H-48B drivers

katchupoy
03/16/2012, 11:05 AM
Has anyone tried using one of these conrollers on a meanwell HLG driver?
I want to build a controller but need to make sure it will work with my drivers. They are the HLG-150H-48B drivers

I have not tried it personally. But if you look at the cut sheet here (http://www.meanwell.com/search/HLG-150H/HLG-150H-spec.pdf)...

It has a three in one dimming function (1~10Vdc or PWM signal or resistance).

So I believe it should work.

Hopes this helps.

MassiveReefer
03/17/2012, 01:07 AM
Everything should be the same. Take into consideration the gauge of the wire however. A smaller gauge(thicker wire) may be needed.

MassiveReefer
03/17/2012, 01:27 AM
I finally finished the LED's and fixture. Hopefully i will have some pictures pretty soon. Its to late right now. I have been watching the night life in the tank with the moon lights for about the past 4 hours. :) With only my blue LED's i can get my tank so blue its almost white. I can't believe how bright these things are and how much shimmer and pop I get in colors in the tank.

Katch, whenever you start "part two", I'm up to bonce ideas off of each other. I think we are close to being at simular stages in the build although I will be running a completely different sketch. What are your goals for part two? I thought I would list some ideas i plan on/hope to do:
-Add relays to the tank to control ever outlet on the tank.
-Add "feed button" and "silent mode" which would shut off all pumps. I have 3 pumps 2 power heads and now two PC fans on my heatsinks so its a bit noise. I think at night i would like to have things really quite sometimes.
-Be able to fully shut down the drivers instead of just doing a zero duty cycle PWM.
-Add at least one temp prob to the tank(I think you have already done this?).
-I would like to mod my meanwell drivers to mount the svr2 pot on the outside of the driver so i dont always have to pry the thing open to change the max Amps.
-I want to program in a "demo" option in my lcd menu so that i can show a quick 2 minute demo of the ramp up/down.

I think there is more but I am to tired right now. If you start another page for part two, be sure to let us know.

fishyj
03/19/2012, 05:15 AM
Hi all, I just wanted to give everyone the sketch parts for temp. On my program I use this to control my heater, but it can also be adapted to control fans too. Here's all the parts needed to add into your sketch: Just remember you have to put the pieces where they belong, I just copied them out of my sketch. I hope this helps.


#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8 //Define the pin of the DS18B20

int heater = A0; // heater relay , digital pin 0
int heater_on_temp = 78; //Turn on heater at this temp
int heater_off_temp = 80; //turn heater off once below this temp
// 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);

sensors.begin(); // Start up the DS18B20 Temp library

pinMode (heater, OUTPUT);

// DS18B20 display
sensors.requestTemperatures(); // Send the command to get temperatures
lcd.setCursor(9, 0);
lcd.print(sensors.getTempFByIndex(0));
lcd.print((char)223);
if (sensors.getTempFByIndex(0) < heater_on_temp) HeaterOn();
if (sensors.getTempFByIndex(0) > heater_off_temp) HeaterOff();

Barteks
03/23/2012, 05:22 PM
Hello,

Hi Tom,

First of all thank you for the whole thread regarding arduino led controller. I was able to get it work for me. However I am interested in bluetooth module and android app for my mobile. Is it possible that you can send me the sketch that includes BT control as long as android application? My email:
barteks@btopenworld.com

Best regards,

Bart

wardda
03/26/2012, 07:29 AM
Hello,

Basic question, is there a reason to do ramp up of blue to the top level and then start the white?

Just wondering if ramping both at the same time or blue up to 30% then starting white at 10% is also a good option or if there is some theory behind doing blue all the way to top then starting the whites?

Thanks,
Dan

katchupoy
03/26/2012, 09:16 AM
Dan, its really up to you. Its more like a controllers limitation actually.

let me explain, I'm sure that what ever you are planning can be done thru sketch. Unfortunately, I can't do it because I'm limited to know how in programing. But its doable. Its even easier if you want both of them ramp up and down at the same time. You just put all of them in one channel.

now going back to your question why blue first and then white.

simple answer, we are trying to simulate dusk dawn effect. Years ago, you only have vho's and mh's. Normally you cannot dim them so you just put everything on timers. Which actinics goes first and then mh.

Dan, I'm sure it can be done... I just don't kmow how to do it. Lol

katchupoy
03/26/2012, 09:17 AM
double post again

wardda
03/26/2012, 09:28 AM
OK, thanks. In my opinion the XTE royal blues are just crazy intense and I would like to do a blending with the white to balance them out, but i didn't want to be entering into the "ooh dude what were you thinking, with whites on that early/long you would obviously have [insert really bad tank catastrophy here]".

I have no problem bending the sketch to make that happen. So I will go that route.

Thanks again.

katchupoy
03/26/2012, 10:18 AM
Wardda,

I believe somewhere on this thread we talked about the same thing about ramping two channels at the same time. I believe the "typhon" project did it already. Maybe you can start from there so not to start from scratch.

I just want to understand how it is done so i can incorporate it on my original sketch... everytime i look at it, my head spins...lol...

here is the sketch i believe... (https://sites.google.com/site/caddnima/my-files/typhon.txt?attredirects=0&d=1)

Hope this helps.

wardda
03/26/2012, 10:42 AM
katchupoy,

Thanks i'll take a look at it.

matiLanza
03/26/2012, 10:01 PM
hey is anyone out there using the BNC shield that liquidarts had ? i bought one from him but contacting him is a slow process and i need this shield working. For some reason the positive pines never change from 4.22 without the probe to a negative number with the probe as they should? anyone please help

SchnitzelReef
03/27/2012, 01:48 AM
Well after spending about 2 hours reading thru this thread,(which is awesome!) I never found an exact answer to....WILL THE TYPHON DIMM THE ELN 60-48D?? A few people have said yes, some have said maybe....i don't understand. The typhon is supposed to be PWM, and the eln D is 0-10v analog...so technically it shouldnt...right? And if it does work will you explain how to hook it up. Also if it does DIMM, will it DIMM gradually from 5%-100%? Or will it only DIMM in steps?? Thanks for any help

MassiveReefer
03/27/2012, 11:52 AM
SchnitzelReef, Read the whole thread.... Everything is answered in here. I know its a long one, but its way better to do to much research on a topic before you start than it is to do to little and mess up half way through.

Long story short, according to katchupoy and others, yes PWM works with the d's but it is not recomended and might shorten the drivers life.

As for how to hook it up... READ THE THREAD. Katchupoy has both a p and a d and he has them both hooked up the same way both using pwm and they both work.

katchupoy, any response to my above post regarding phase two?

Mati, can you please explain your problem in a little more detail, and maybe post a link to what shield you are talking about? I dont understand your question regarding 4.22. Are you talking about volts? What are you trying to accomplish and what is your problem? I dont have the same shield but i can try to help. I bought this one (http://www.adafruit.com/products/714) which i highly recommend to anyone just starting out. You get an lcd screen(its a little small but worth it), 6 buttons including a reset, a pot for backlight adjustment and you can do this all through only two pins plus pos and neg power.

MassiveReefer
03/27/2012, 12:00 PM
mati, sorry I didnt realize the shield wasnt an lcd shield. I just found this that seems like a simple how to...
https://github.com/practicalmaker/BNC-Shield

katchupoy
03/28/2012, 09:00 PM
Well after spending about 2 hours reading thru this thread,(which is awesome!) I never found an exact answer to....WILL THE TYPHON DIMM THE ELN 60-48D?? A few people have said yes, some have said maybe....i don't understand. The typhon is supposed to be PWM, and the eln D is 0-10v analog...so technically it shouldnt...right? And if it does work will you explain how to hook it up. Also if it does DIMM, will it DIMM gradually from 5%-100%? Or will it only DIMM in steps?? Thanks for any help

Thanks for reading my thread.
1) Will the Typhon dim the ELN? I believe this is the wrong thread to ask this, there is another humongous thread about the typhon. But on top of my head, I believe they were able to make the typhon work for 0-10 volt configuration. I believe Boostled which is also a typhon can do this. I dont know if they tweaked it or native to typhon.

2) Typhon is PWM and D is analog. Yes you are correct, it will dim but not natively like PWM in 255 steps. The top end part (50-100%) is no t a problem, you can have as many step as you want here. But on the low end, (5-50%) this is where we ran out of values to use. the "D" is not linear in terms of dimming. In other words, Im using arduino PWM to run 2 "D" drivers i have together with one "P" driver and it worked. I believe the "HLG" series can accept 3 ways of dimming. Resistance, Volts and PWM. So im assuming that these ELN's are the same.

3) The wiring for the "P" and the "D" is basically identical. The only difference is how they react to the signal. The "D" reacts to volts as in 1 volt = 5% and 10 volts = 100%. Unfortunately 2 volts is not 15 or 20%. It just jumps to something 30 and above. So if you have 10 steps, thats ok. 20 steps maybe ok also, but like I said, the resolution on the low end is not that great.

All in all, its not really that bad, unless you are so anal with the steps. In my case, Im just trying to get out of the instant on and off schedule, and 10 steps with it is not bad at all.

Hope this helps.

katchupoy
03/28/2012, 09:03 PM
katchupoy, any response to my above post regarding phase two?

Just trying to find time... been busy recently. My apology.

Cesar

matiLanza
03/29/2012, 08:39 PM
mati, sorry I didnt realize the shield wasnt an lcd shield. I just found this that seems like a simple how to...
https://github.com/practicalmaker/BNC-Shield

i have that exact shield set up and i am testing with his sample code but it just simple doesnt work. When you read the volts on the pin it should be 4.22V then with the BNC probe in, the Volts should go negative but they dont. When connected to the display, when i insert the positive from the meter it turns my ph reading to 7.0 and it wont move from there

MassiveReefer
03/30/2012, 11:55 PM
Mati, you need to be a little be more detailed in your explanation(remember, I have never used this shield so I need as many details as you can give me if you want me help). What steps have you done prior too? Have you configured everything? Have you taken your voltage readings and input them into the sketch, etc.... Did you watch the instructional videos on the web site I posted for you? I understand what needs to be done based on the videos, but I am still lost at what you are hung up on. Are you trying to configure the shield by trimming the pots and the volts don't change? Sorry, but without more details I will be of no help.

MassiveReefer
03/31/2012, 12:22 AM
Just trying to find time... been busy recently. My apology.

No worries Cesar! I know how life goes. :spin1: I haven't even found the time to take some simple pictures for people yet. Plus it seems like you have finished your lights quite a while ago and I am still "fresh" to the project. I give you credit for simply sticking with the thread for so long. :thumbsup: My girlfriend will be out of town this weekend so maybe I will find some time to post some pictures then. I have been slowly adding more and more features to my LCD menu. Now that I at lease have a stable build of my sketch I will most likely start slowing down my addiction with this project as well. I finished a "demo" option to the menu today so i can show people a time laps of the tank in two or five minutes. I also think i just ironed out the rest of the bugs to get my manual moon lights working to turn them on "after hours" so to speak. When I turn them on from the LCD menu, I allow the user to set a timer for how long they should stay on for (So i dont have to remember to turn them off when the night is over!!! :) ) I also added to the menu the ability to manually set the max PWM value for both the blue's and the white's. If i change them when the lights are on full daylight, you will see the change directly, and if you change the values while the lights are either ramping up or down, it will dynamically change the values of the current "ramp up/down PWM values" so you will still see the affects. Its pretty slick. If anyone has any good ideas for cool features for these lights I would be interested in hearing them. Might be nice to start gathering ideas for phase two. Unless of course you(Cesar) want to wait until then(I don't want to intrude the thread if you want to just keep it simple for this one). Time to make a drink and enjoy the moonlights!

Patzig
03/31/2012, 02:02 PM
http://i862.photobucket.com/albums/ab187/patzig/0003.jpg

I just got my relay power strip up. I managed to cram in 6 solid state relays into this strip. I don't have the model numbers on me right now, but they are 5 amp (roughly 600 watt) AC solid state relays. Powered on by 3-8 v DC. I was told they draw very little current so I didn't need any resistors and plugged them straight into digital pins. Works great. Probably gonna use the 6 channels for fuge light, heater, led lights (to fully shut off drivers, not just 0 pwm), circulation(all power heads and return pump), skimmer and gfo.

Massive, I'm interested in the feed mode (shutting off circulation for a given time) and the demo modes you are thinking about. Besides these 2 thinks I think I have my code mostly done. I plan to add keypad and menu control later.

Patzig
03/31/2012, 09:50 PM
@MassiveReefer
zero duty, thats why all relays must be assigned to non-pwm pins, so you cannot accidentally issue a pwm command.


Katchupoy - Are you saying that relay's should be connected only through non-pwm pins only because someone could accidently send a pwm signal in the code somewhere? Or are you saying that pwm pins could somehow output voltage even when the digitalWrite(x, LOW) is given? I thought the digitalWrite(x, LOW) or digitalWrite(x, HIGH) would be the final say thus giving that pin either 0v or 5v regardless of whether that pin has pwm capabilities.

MassiveReefer
04/01/2012, 01:24 AM
Correct me if I am wrong Katchupoy, but I believe he was trying to imply that one should only hook relays up to non PWM so that you don't accidently send an analog signal to something that is expecting a digital signal. With will written code, one wouldn't have to worry about this however. :)

MassiveReefer
04/01/2012, 01:50 AM
Patzig, that's really cool you were able fit the relays in that power strip. Were the relays individual relays or all on a relay board? How much did you pay for them? I am looking to do the same thing except maybe with something like this (http://www.musiciansfriend.com/pro-audio/american-dj-pc-100a-8-switch-on-off-power-center). That way i could cut individual power both programmatically and manually.
In my drunken stuper, gazzing at my moon light tank, I came to the conclution that i am really unhappy with how low i can turn my Blues before they turn off with the meanwell drivers. I have 12 3W royal blue cree LED's running at around 400 mA and when my blues go from the lowest to off, it is way to drastic for me. Also, when it is late night like right now(2:30AM) and i turn on my moon lights, i want them to be barely on. To solve this, I am going to replace the 5k pots in the Meanwell driver with digital pots. Its funny because i have already replaced them once because the dumb things were so cheap i broke them on both drivers turning them to hard(and by to hard I mean barely turning them at all. Cheap pieces of...). This way i will be able to adjust my max current through the meanwell. If my daylights are on, i will set it to whatever resistance is needed for ~400mA's of current. Then, if i only have my moonlights on(and maybe even during my ramp up/down to get a smoother transition) I can set the max current to say 50-200 mA's. That way when I am running my lowest PWM value in which my drivers will stay on, the blues will in effect be much lower. If i ever build another lighting system, I will for sure design my own drivers for that very purpose. I was looking into building a voltage regulator to do this, but I ended up going the lazy way out. Does anyone have any opinions on this idea? I don't know anything about digital pots which makes now a perfect time to learn. :) From a real quick look up, it looks like they use I2C which means i will be able to hook up my LCD, 5 buttons(6 including reset), my clock, and this new digital pot all to the same two pins. Once again.... I'm liking it. I really thought i was going to have to go to the arduino mega, but it looks like I wont after all, even with 6-8 relays.

MassiveReefer
04/01/2012, 02:03 AM
Sorry for the double post, but i just found IC's to also digitally control resistors through PWM instead of the analog pins, so it looks like it could be done both ways. I have to assume that i would choice to go analog though so i could save that extra digital pin.

MassiveReefer
04/01/2012, 02:07 AM
O, and another thing I plan on doing is hooking my PC fans up to some transistors so when i have both my drivers running, my fans with be running at either 5 or 10V and when just my blues are running they would be running at around 3.3 volts or so and when the lights are off, the fans will shut off. Currently my lights stay on until I unplug them... which i never do.

matiLanza
04/01/2012, 09:42 AM
Mati, you need to be a little be more detailed in your explanation(remember, I have never used this shield so I need as many details as you can give me if you want me help). What steps have you done prior too? Have you configured everything? Have you taken your voltage readings and input them into the sketch, etc.... Did you watch the instructional videos on the web site I posted for you? I understand what needs to be done based on the videos, but I am still lost at what you are hung up on. Are you trying to configure the shield by trimming the pots and the volts don't change? Sorry, but without more details I will be of no help.

Okay cool sorry about that I'll give you a break down, okay so the
BNC shield is from practicalmaker.com and is setup complete and right. With my code everything work correctly with it stacked on top except the BNC. I bought a bnc probe and watched his video to configure the pots And board. Okay I ran test using my code and his code both don't work and in get the same problem. Okay so with my pin A1 being the probe. I measured the Voltage from the board 4.96 volts and added it to the sketch. I take my meter and place the red on pin A1 without the bnc connected and get 4.22 volts okay all is good. Then I inserted the probe (voltage should go negative) but I get still 4.22 volts. When I plug the meter into the pin I notice the ph goes to 7.0 on the read and the pots with not change that. I remove the meter and the ph floats to 10's. Can it be a bad probe ? If I connect A1 to ground I get the same affect on the ph reading . Turning the pots does nothing at all even with no meter on the pin. The fact the volts on the pin doesn't go negative is a problem . Thanks for the help I need it lol I'm lost at this point don't know what else to do

Patzig
04/01/2012, 10:14 AM
http://item.mobileweb.ebay.com/viewitem?itemId=280697990848

These are the relays I have. My local electronics store has them for 2.99 a piece, so I grabbed bunch.

http://i862.photobucket.com/albums/ab187/patzig/0001.jpg
http://i862.photobucket.com/albums/ab187/patzig/0002.jpg

Sorry the pics are so big, I'm posting from my phone.

Ya I thought about going with the American DJ power strip, but I found mine at home depot for cheap and impulse bought. I crammed all the relays in, strapped with tie wraps, wired everything up, dabbed silicone on all solder points and closed her up. I used rj-45 for my signal wire. One ground wire and 6 Signal for each relay. I would go the route I did and not mess with a relay board. Especially since you'll have plenty of room to mount everything in your strip.

Ya once you start plugging up relays and led drivers, you fill up the digital pins pretty quick. I too wish I had put together my own drivers instead of blowing money on the meanwells.

Massive, any chance you could post your code? I wanna start on my menu and keypad stuff.

SparkysWidgets
04/01/2012, 11:26 AM
Hey mati,
pH probes are pretty standard fair high impedance sensors and you will find most designs are pretty similar. A quick look shows its pretty much the pHDuino (http://code.google.com/p/phduino/) design which is a straightforward and effective design and pretty robust especially for cost. This may help you troubleshoot with another avenue to search based on. I also have a pH interface tutorial (http://www.sparkyswidgets.com/Projects/pHInterface.aspx) which may or may not help you understand why these designs are how they are. It may turn out you have a bad probe as well in the end. Make sure the charge pump is outputting the negative rail, and also make sure the offset voltage divider is correct, then set offset for zero and try to fix the gain at around 10ish. Our interfaces are fixed gain and offset so its a tad different, corrections are made in software.

MassiveReefer
04/01/2012, 09:22 PM
Patzig, I don't mean to sound greedy, but i probably have 60-80+hours into my code and hope to maybe make some money off of these things someday, so I am not to sure i feel real comfortable posting ALL of my code, but i would be willing to answer some questions and maybe give you some advice with some pseudocode. How familiar are you to coding?

Advice to all: I admit that i have not looked at everyone's sketches in this thread, but I have looked at a bunch of them, and they all are fare from fundamental coding. I code for a living and personally I hate picking through other peoples code which is why I wrote my own. Now a day's the standard or "fundamental's" I am referring to have to do with a concept of object oriented programming(OOP). I highly recommend people read up on this concept if they would like to do any complicated coding. Another big concept that is very important in object oriented coding is the concept of decoupling. If you are going to read/learn about them, defiantly read about object oriented coding first. Here is the gist of what they mean for those of you who don't know:

First off, both of these concepts are to make coding easier, make code more reliable(less bugs), easier to debug and make adding new code MUCH MUCH easier! Everyone's code i have looked at so far for this project put close to if not all of their logic in one function(The main loop)! This is very frowned upon in the coding world. First of, its increadible messy, impossible to debug, and very hard to add new code.

The concept of object oriented coding has to do with representing real world objects as as "class" in code. If you use a LCD chances are you are using a class for it such as the LiquidCrystal class that has already been written for you. The LCD itself is the "real world object" and the class itself is the representation of that object in code. I use a class that inherits from the LiquidCrystal class, but thats a whole nother story. Just think of the Adafruit_RGBLCDShield class as the LiquidCrystal class if that is what you are using. The first thing you need to do is this:
#include <Adafruit_RGBLCDShield.h>
This simply says, "hey arduino, I want to use the Adafruit_RGBLCDShield class so any time i refer to Adafruit_RGBLCDShield in my code, use that class/code.

Once you include all of your classes, you need to create an "instance" of that class. An instance can be thought of as a copy of code, and you can have many different instances of the same class. This is an example of creating a new "instance".

Adafruit_RGBLCDShield lcd1 = Adafruit_RGBLCDShield();
Adafruit_RGBLCDShield lcd2 = Adafruit_RGBLCDShield();

As you can see i have created two seperate instances(lcd1 and lcd2) of the same class.
If i had two lcd's I could now easily write to both of them using code like this.
lcd1.print("hello");
lcd2.print("world");

This is once example of why breaking code into classes can have huge benifits. Instead of having code in two places as to how to print to lcd1 and lcd2 there is simply one place to do that, and that is the print function that is found within the Adafruit_RGBLCDShield class itself.

An example of what I did to make life easier is to make a "Lights.cpp" class. This class handles EVERYTHING that has to do with my lights themselves. I initially have to configure them in the "void setup()" function. After that, the only thing that my arduino sketch has to do is call one function that I called "AdjustLights()" This AdjustLights function that is found in my Lights class handles everything for me. This makes dealing with a menu much easier in my arduino sketch.

The way i have my sketch written, which there are many ways of doing it, is that my arduino sketch is what handles the menu itself. I might redue it some day and make my menu its own class. I would most likely use what is called a Doubly linked list data structure. To keep it short for now, you can read about that on your own and ask questions if you would like.

Now, the concept of "decoupling" might make a little more sense(if you understood the concept of OOP). Decoupling isn't really nesissary for coding but its always a good thing to keep in mind while designing your classes. Decoupling in sort is the idea to try to make each class as independent as possible and not rely on other code to work. An example of this can be seen in my Lights class. Other than setting things up in the beggining(Lights on/off time, ramp time, blue/white arduino pin etc), my lights class if fully independent. Nothing that happens in my arduino sketch itself will effect my lights class. Other than the initial setup, it is impossible for my arduino code to mess things up with my lights. The only thing my arduino code needs to do its call a function like this in code:
Lights.AdjustLighting();
and my lights class takes care of everything. This is very beneficial for adding things on such as this menu. How you make and execute your menu class has nothing to do with your Lights class and it will not by any means mess up the lights unless for some reason it is not able to call the AdjustLights function. This is the concept of decoupling and is what all true programmer should work toward, especially when working on large/complicated projects. When i first set up my lights, I wrote a real quick sketch to adjust the both of my channels with two pot's so i could figure out exactly how i want values i want to ramp my lights at. For small simple things like this, breaking code up into classes is not as necessary, but if you really want a fully customizable menu that you can at any time add functionality to, the two concepts are so important.

To further emphisize the importants of this, I will show you what my main loop looks like. This is the exact code of my lights/menu controller:

void loop()
{
input = GetSelectedButton();

//if the lcd is not on and the user pushes a button, turn on the lcd
if (!LcdIsOn && input >= 0){
TurnOnLcd();
//If the lcd is on and the user pushes another button, go to the option menu
}else if (input >= 0)
{
delay(100);
GoToOptionMenu();
//If the user has not done anything in 5 seconds, turn off the lcd to save power
//This turns off both the backlight and the text
}else if(LcdIsOn and timeInSeconds() > lastButtonClick + 5){
TurnOffLcd();
//If the user is not interacting with the arduino, update the main system
//For now, the main system refers to writing the main text to the display and adjusting the lights
//the main text for now is what percent of LED's are on, the time, what phase the lights are in(ramp up/down, max, off, MoonLighting)
//This will eventually display temp(which will have its own class! :) ) maybe ph and other sensors.
}else{
UpdateSystem();
}
}

And here is what my UpdateSystem function looks like:
void UpdateSystem()
{
//check any sensors
//update the lcd main display
UpdateMainDisplay();

//handle light changes
Lights.AdjustLighting();
}


Well, this post has gotten long enough. So I will end it here. This obviously didn't tell you at all how to create a menu, but I think it will give you a good base/background to get you started. If you have more questions feel free to ask. I have always believed in the saying, "why give a man food, when you can teach him to fish". :) Hopefully I can teach people what they need to know to write their own customizable code. :)

katchupoy
04/01/2012, 09:43 PM
Katchupoy - Are you saying that relay's should be connected only through non-pwm pins only because someone could accidently send a pwm signal in the code somewhere? Or are you saying that pwm pins could somehow output voltage even when the digitalWrite(x, LOW) is given? I thought the digitalWrite(x, LOW) or digitalWrite(x, HIGH) would be the final say thus giving that pin either 0v or 5v regardless of whether that pin has pwm capabilities.

Yes, this is true. If someone will accidentally put a code on it, it could fry the coil on those relay. Plus, we want to save these PWM pins for other purposes that really need PWM signal, ie: dim down and up lights.

katchupoy
04/01/2012, 09:47 PM
Patzig, that's really cool you were able fit the relays in that power strip. Were the relays individual relays or all on a relay board? How much did you pay for them? I am looking to do the same thing except maybe with something like this (http://www.musiciansfriend.com/pro-audio/american-dj-pc-100a-8-switch-on-off-power-center). That way i could cut individual power both programmatically and manually.
In my drunken stuper, gazzing at my moon light tank, I came to the conclution that i am really unhappy with how low i can turn my Blues before they turn off with the meanwell drivers. I have 12 3W royal blue cree LED's running at around 400 mA and when my blues go from the lowest to off, it is way to drastic for me. Also, when it is late night like right now(2:30AM) and i turn on my moon lights, i want them to be barely on. To solve this, I am going to replace the 5k pots in the Meanwell driver with digital pots. Its funny because i have already replaced them once because the dumb things were so cheap i broke them on both drivers turning them to hard(and by to hard I mean barely turning them at all. Cheap pieces of...). This way i will be able to adjust my max current through the meanwell. If my daylights are on, i will set it to whatever resistance is needed for ~400mA's of current. Then, if i only have my moonlights on(and maybe even during my ramp up/down to get a smoother transition) I can set the max current to say 50-200 mA's. That way when I am running my lowest PWM value in which my drivers will stay on, the blues will in effect be much lower. If i ever build another lighting system, I will for sure design my own drivers for that very purpose. I was looking into building a voltage regulator to do this, but I ended up going the lazy way out. Does anyone have any opinions on this idea? I don't know anything about digital pots which makes now a perfect time to learn. :) From a real quick look up, it looks like they use I2C which means i will be able to hook up my LCD, 5 buttons(6 including reset), my clock, and this new digital pot all to the same two pins. Once again.... I'm liking it. I really thought i was going to have to go to the arduino mega, but it looks like I wont after all, even with 6-8 relays.

Im not sure if this is even possible, but let us know if you succeed. What im trying to say is that, I believe its the limitation of the drive. Min is 1 volt and then its out... And yes, you are correct, its still very bright and then off...

Patzig
04/02/2012, 09:49 AM
Katchupoy - thanks for verifying. My particular relays are the optical type and can accept up to 32v dc, so I don't think I could fry them with the Arduino even I tried. But I definitely understand your point.

Massive - As of today I've taken 2 c+ classes and 2 java classes, both object oriented. It's funny, I learned alot of terms, code and background, but it wasn't until I started this project that things started to click. Coding seems easier when I have a physical output and object to see my results. I understand your reasons for not posting the code. I asked because I'm lazy lol. I also find it very hard to "use" other peoples code, but of course it's easy to look at someone's working sketch, and pull the necessary chunks to implement in my own code. My current sketch runs a very simplified object oriented style. Everything is listed in it's own classes and then my loop:

void loop()
{
getTemp();
printTemp();
alarm();
printTime();
ampMeter();
relayPowerStrip();
ledLights();
delay(500);
}

I guess I have a hard time wrapping my brain around building the menu because the arduino will have to often "wait" for buttons and responses. And while it's waiting...it's not doing anything else (updating next pwm step in led sunrise/sunset, updating temp, and so on). But I will give it a real attempt before I start asking for help.

I had previously looked into running multiple screens and had determined that it was out of my reach as far as code. But your post kind of verified what I thought would be pretty easy. I had assumed that you could simply run 2 lcd's, each with it's own i2c controller and mac address, and simply declare each screen like you did, lcd1 and lcd2. My hopes were to print all "stats"(current temp, time, ph, current led pwm value) to one screen, and then use the other screen as my menu to update values and such. Surely this would be maxing out the mega328, as my sketch already takes around 500ms to do one full cycle. But it would seem worth it.

katchupoy
04/02/2012, 10:25 AM
Katchupoy - thanks for verifying. My particular relays are the optical type and can accept up to 32v dc, so I don't think I could fry them with the Arduino even I tried. But I definitely understand your point.


Ok, I think what you are reffering to are the optical solid state ones... correct?
But still, for other readers out there, let me make this very clear.

Lets suppose that you have the solid state relays and there is no coil??? I guess since it is a solid state, it can handle massive amount of ON and OFF switches per second.

BUT.... WHAT ABOUT THE DEVICE PLUG TO IT?

Example? Powerhead... lets assume that you have the simple ON and OFF to make it act as a wave maker. But what happens if you accidentally assigned a pwm ramp up to it... The relay can maybe handle it, but I dont think the powerhead can HANDLE the high frequency ON and OFF without frying it. Lol, I fried my Maxijet thinking i can recreate TUNZE low high wave. lol... This is specially true if your device has coil on it such as pumps, electric fans. etc.

Just FYI....

Hope this helps.

Patzig
04/02/2012, 12:04 PM
Lol another good point. This is my worry about shooting pwm into the meanwell 48d drivers. It may work fine, but who's to say the drivers aren't so fast that it's flickering the leds on and off really fast? Or slowly burning up the driver?

MassiveReefer
04/02/2012, 12:30 PM
Patzig, are you a computer science major? It sounds like it. If so, the one class you are missing to complete this "assingment" is a data structors class. Are you formiluar with structers and pointers?

Before I go any further, I would recomend scrapping the idea of two LCD's. If you are setting the on time for the lights, or turning your moonlights on through a menu, or turning off a relay to turn of a pump etc, who cares if you can at the same time see the tank temp at that vary moment? Once all of the coding is done and bugs are out, you might in a given day be in your "menu" maybe twice a day tops for 30 secs? Once you get out of the menu and go back to the main display screen, your getTemp(); printTemp(); will execute then and boom, you will be back to displaying the current temp. No need to read temp when you are trying to turn of the pump for feed time. Same goes with adjusting the lights. Who really cares if your ramp up pwm value jumps more than it normally would. The key with the lights issue is this:

If you are able to reset your arduino when you are half way through ramp up/down and your lights are able to be at the exact same PWM value, then you might at most miss two steps between your 25ish PWM to 255 PWM, you know what i mean? Say during ramp up your whites are at 150 PWM and the max you have them set to is 255. If you restart your arduino, it should be able to be right back at the 150 PWM value, maybe go to the next step up (160 say) depending on how long your ramp up time is. If your ramp time is like 2 mins you will probably see an significant jump in brightness, but if your ramp is 30-60+ mins I promis you wont even notice a difference.

The way i structured my code as you might have been able to see in the code i posted, I give the users 5 or so seconds at every level of the menu. If they do not do anything after that time, it will back up to the next highest level. This will continue until it gets back to the main display where it shows all of my main values(light percent temp etc...I only have light percent time and function(ramp up/down, max, off and MOON). Once it gets back to this main display level, which is the level in my main arduino loop, it will then update all of those values(which is the only time i care what the values are because thats when i can see them). After another 5 or so seconds, i turn of the LCD so i dont waist power. This could obvoiusly be skipped, buy why leave the screen on when your not home?

Like I said before if i were to do it again I could use a doubly linked list data structure. I wish i would have done this before but i jumped the gun and wanted to rush things.

To understand a doubly linked list, you need to understand what a struct is and what and how a pointer works. Have you gotten to pointers yet in your education?

This is the gist of what your struct could look like(probably with more details, but you get the point)

to be technical, you want a circularly doubly linked list
(I am assuming you have a 2X16 LCD that is what i have so thats what I'll use :) )

struct menuItem{
object* previousMenu
object* nextMenu
string mainMenuText
string subMenuText
}

Now you treat this struct as an object, and for every "menu item" you create a new struct for it. Lets say we have three items in this menu. Feed, Lights and Powerhead.

This is how the three structs would look
//feed
struct{
int uniqueId = 1 //this is optional but i think it is what i would do. See below for reasoning
object* previousMenu //this will be a pointer to the powerhead struct
object* nextMenu //This will be a pointer to the light struct
string mainMenuText = Feed mode off
string subMenuText = >off on // if feed mode was on then it would be " off >on"
}
//lights
struct{
int uniqueId = 2
object* previousMenu //this points to the feed struct
object* nextMenu //this points to the powerhead struct
string mainMenuText = "Lights are on"
string subMenuText = " off >on"
}
powerheads
struct{
int uniqueId = 3
object* previousMenu //points to lights struct
object* nextMenu //points to feed struct
string mainMenuText = "powerheads are on"
string subMenuText = " off >on"
}

now your menu might look something like this
void optionMenu(struct currentMenu)


do{
int input = getInput()
lcd.setCursor(0,0)
lcd.print(currentMenu.mainMenuText);
lcd.setCursor(0,1);
lcd.print(currentMenu.subMenuText );

If input == LEFT
optionMenu(currentMenu.previousMenu*);
break; //to get out of the do{}while(true)
if input == RIGHT
optionMenu(currentMenu.nextMenu *);
break;
if input == SELECT
handleSelectedInput(currentMenu);
}while(true);

This obviously isnt everything, but its a good start. Also, for a side note, you would never declare the structs like i did. You would create a new instace just like creating a new instance of a class like this I dont remember the syntax so dont look at that.

menuItem LightMenu = new menuItem();

To actually deal with this "data structor" which is esentually a bunch of nodes that point to each other, you will need to implement some sort of doubly linked list class that will handle adding/removing items to the menu.

The struct i made up here will be apart of this "doubly linked list class". This class always knows the "head" which is the current node or struct that it is at. it also stores how many nodes there are etc. There a hundreds of implementaions of this on the web, so do some searching and you should be able to find what you need without having to implement the doubly linked list class itself.

From my college days, I still have my book called "Data Structures, A pseudocode approach with c++". Everything I am talking about is on page 113 if you are able to check it out. If not, just google it. You could probably even google doubly linked list implementation of a menu if you are lazy and dont want to learn it all. (If your going into computer science, do it yourself! You wont regret it. :) )

Questions? Let me know

MassiveReefer
04/02/2012, 12:43 PM
Im not sure if this is even possible, but let us know if you succeed. What im trying to say is that, I believe its the limitation of the drive. Min is 1 volt and then its out... And yes, you are correct, its still very bright and then off...

If(when) i do this, I dont plan for it to be such a smooth transition that i cant even tell the lights go out. My goal is two fold. 1. when the lights go out, not have it go from super bright to off. 2. Be able to turn on my moonLights at say midnight and not have my fish feel like its morning already and time to come out. I have tested this out, and when i run my blues at a max of 200(I think this was the value) or less amps I am able to get a much dimmer tank. Normally I run them at 400 amps and at 26 PWM(lowest i can go before off) They are just way to bright for my liking. I would like to find the lowest that the internal pot can go, when my lights are dimming down and get to 26PWM switch the max amps from 400 to 100-200ish and then put my PWM back up to say 200 or whatever value looks like it is the same as 400 amp 26 PWM. Then i will be able to lower my blues MUCH lower. If you try lowing your map amps yourself, you will see how much lower your blues can go.

I know for sure that it is totally possible. Check this out:
http://arduino.cc/en/Tutorial/DigitalPotentiometer

This would then hook up to the same pins as my LCD, temp sensors, RTC and all my buttons, so I would not be taking up any more pins to do so. Bingo!

When I do this, I will for sure put some sort of inline fuse(which currently I know nothing about) with my LED's so that if my code messes up somehow and my resistence goes to zero or way high, that i dont over load and blow my LED's.

Does anyone know if they make fusses that will trip at a certain amp? I suppose Ohm's Law could get me to a wattage maybe? IDK, I'm just rambling at this point so I am going to go back to work! :)

katchupoy
04/02/2012, 08:39 PM
@massive,

oh ok... you are referring to the internal pot... i did not catch that...
so you are saying that you will try to control the internal pot via arduino...?
if you succeed, let us know.. this sounds interesting...

What is your driver? P? or D?

If its a P, I believe the lowest PWM value you can have is 39 ? Im not sure about this one, I guess you need to test it... since "P" is 15% lowest dim before it goes out.

If its a D, then you can go as low as 5% which is in my code is equal to PWM of "1", I know it does not make sense, but the D is not linear.

Also, if you can try first the 5K pot inline on the "positive" side" maybe this can give you idea how low is low, then replace it with digital pot.... instead of trying to control it internally.

Hope this helps.

https://dl-web.dropbox.com/get/_Reef/IMAGES/2011-01-30%20-%20ARDUINO/WiringDiagNPN.jpg?w=0fe372af

MassiveReefer
04/03/2012, 10:36 AM
@massive,

oh ok... you are referring to the internal pot... i did not catch that...
so you are saying that you will try to control the internal pot via arduino...?
if you succeed, let us know.. this sounds interesting...

What is your driver? P? or D?

If its a P, I believe the lowest PWM value you can have is 39 ? Im not sure about this one, I guess you need to test it... since "P" is 15% lowest dim before it goes out.

If its a D, then you can go as low as 5% which is in my code is equal to PWM of "1", I know it does not make sense, but the D is not linear.

Also, if you can try first the 5K pot inline on the "positive" side" maybe this can give you idea how low is low, then replace it with digital pot.... instead of trying to control it internally.

Hope this helps.

https://dl-web.dropbox.com/get/_Reef/IMAGES/2011-01-30%20-%20ARDUINO/WiringDiagNPN.jpg?w=0fe372af

I have two P's. I found through trial and error that i can get mine down to about 26 PWM and still have the lights on. I say about because it seems to change due to inaccuracies within either the leds or driver. Either the driver isnt very accurate at reading the PWM value, or the arduino isnt very accurate at writing the PWM value, or more likely both. I set mine to i think 27 or 28 to be safe. When it is set to 26 they will flicker sometimes.

What do you mean by "Also, if you can try first the 5K pot inline on the "positive" side" maybe this can give you idea how low is low, then replace it with digital pot.... instead of trying to control it internally."?

are you saing trying to figure out what the resistance of that pot is for the given max amps desired? I did have a thought the other night, instead of using a digital pot, i could just use two resistors with a switch. These are completly random values, but lets say my resistence when my lights are at 400 mA max is say 400 ohms and when the max mAs is at 100 then the resistance of SVR2 is maybe say 100 ohms. Then, instead of needed a digital pot, all i would need is two resistors (400 and 100 Ohms's) and a switch to switch between the two resistors. These three parts would then fully replace SRV2 on the inside of each driver. This however would requier me to use an arduino pin which is the downside, since the digital one gets hooked up to the same pins as everything else(LCD, buttons etc...). Another reason i think i would rather go with the digital pot is because I could in the future make the fading look a lot more smooth, and i could pick any value for SRV2 instead of just the two hardwired values.

MassiveReefer
04/06/2012, 11:29 AM
I say about because it seems to change due to inaccuracies within either the leds or driver.

I meant to say "I say about because it seems to change due to inaccuracies within either the Arduino or the driver.", but for some reason I can no longer edit this post.

bmahlie
04/10/2012, 03:44 PM
TRN, Did you ever figure out how to stop the wavemaker relays from clearing the LCD? I have the 8 relay board similar to your 4 relay one and have the switching power isolated from the arduino. The LCD will still clear.

MassiveReefer
04/11/2012, 06:53 AM
bmahlie, could you possibly be running out of SRAM(volital memory) while your sketch is running? Here is something I found that could be releated:

"If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely. To check if this is happening, you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). If it then runs successfully, you're probably running out of SRAM."
From this (http://arduino.cc/en/Tutorial/Memory) site.

If you are not sure, a good way to test this would be to write a sample/test script that only writes some dummy data to the lcd, and then switches the relays. If you have a very bare bones sketch running, and you notice the same problem, then this can be rulled out. If, however, you are unable to reproduce the issue while running this "bare bones" sktech, then the issue is either running out of memory or a bug in the sketch.

What exactly happens with the lcd again? Have you tried debugging the issue yet? Are you able to break it down, and figure out if there is a specific line of code, or area of code that it happens at?

Another thing that comes to mind about what else it could be is that the relays are pulling to much power. When everything is running and the issue happens, how hot does your regulator on your arduino get? I know that the lcd's pull a somewhat large amount of amps. What is your input power to the arduino? (aka what volts/amps rating do you have for your powersupply?) It could maybe be that your walwart is not able to handle the amount of amps you are trying to pull through your system? I'm no pro, but you might also be able to try messuring the amount of amps the arduino is pulling and compair that to your walwart(powersupply) rattings. These are the first things I would loot at.

MassiveReefer
04/11/2012, 06:57 AM
patzig, any progress with the menu concept?

matilanza, any success with the probe shield?

MassiveReefer
04/11/2012, 07:10 AM
Does anyone know if there would be a downfall to swapping out the 5k SRV2 pot with a 10k pot? Would this cause issues? I am trying to find a digital pot so I can control this through my arduino but a 5k pot with the criteria I am looking for is really hard to find. I would like to find a digipot with the following criteria:
-5k resistance range perfered
-i2c data transfer(this is the hard thing to find in 5k's, i can find 10k i2c, but no 5k)
-2 channels on one chip if possible but not a big deal if i only find single channel pots.
-I need to figure out the amps that are running through SRV2 so I can find an equal rated pot.
-Lastly, I would really like it to be a through hole design rather than any sort of surface mount. I have never delt with surface mounted hardware before, and i dont think i want to start mixing it into this project now. This is also a requirement that seems to limit my possibilities quite a bit.

The closest thing I can find to these requiremnts are a 10k pot from digikey. If anyone has any advice/input/thoughts about this, I would love to hear them. I'll let everyone know how this progresses. I think this is going to be my next focus for now. I just added a transistor to switch my lighting fans off in code. However, I needed to lessen my volts supplied to the fans to be able to keep the transistor cool for now. Soon I will replace the transistor with a MOSFET so I can bring my volts back up to 10 instead of 3.3.

katchupoy
04/11/2012, 11:01 AM
TRN, Did you ever figure out how to stop the wavemaker relays from clearing the LCD? I have the 8 relay board similar to your 4 relay one and have the switching power isolated from the arduino. The LCD will still clear.

Did you use a transistor to switch these relays on and off? or are you connecting directly to the arduino pins...?

katchupoy
04/11/2012, 03:57 PM
For those people who are still using the original sketch. I mentioned before that the sketch has a wavemaker function built-in.

All you need to add are relays. There are several types, but I will concentrate on two common ones. The 5vdc coil ones that you can connect directly to arduino, or the 12vdc coil ones that are more common and more heavy duty.

Diagram 1 is for the 5v coil setup...
https://lh5.googleusercontent.com/-aqZgY5XEidg/T4X_EggpGeI/AAAAAAAABKI/5Y75VO2b3bI/s1024/relay%25205v%2520wiring.jpg


Diagram 2 is for the 12v coil setup...
https://lh4.googleusercontent.com/-4jmTz4sY16o/T4X8kl4IIzI/AAAAAAAABJs/2eHWlnXmB3s/s1024/relay%252012v%2520wiring.jpg

Hope this helps.

.

wardda
04/11/2012, 04:41 PM
Ok I have been running this controller for several weeks with 2 channels. 1 Channel for 2 strings of blue and 1 channel for 1 string of white. Worked great. The only problem I had is that it wasn't enough light for my tank. So I added another string of mixed white and blues. So now I'm running the 2 strings on each channel.

The problem I'm having is that my dimming has gone to crap. It is like the drivers are no longer getting the signal from the arduino. I swapped out one of my 2N2222's and then that channel started working. I ran some tests and swapped out the other one and then did some more tests and independently they seemed to work well.

I then hooked up the full system and then things started to go bad again. I can now plug in the 10v for the pwm signal and the power cord for the drivers WITHOUT the power to the arduino plugged in and the blue lights will come on.

So for starters what would be causing my 2N2222A's to be failing? I'm pretty sure I have the C,B,E all identified correctly, but in the event that I don't what would happen? How do you know if a 2N2222A fails? Are there different types/levels of 2N2222A's? I'm wondering if I'm buying ones that are rated too low?

Any advice? Could it be something else?

katchupoy
04/11/2012, 05:22 PM
@Warrda

Hmmm are you sure you are paralleling the drivers the same color from the driver to the transistor? are you using a pot to dim manually?

Can you double check if we have similar wiring diagram?

https://lh5.googleusercontent.com/-6WtDj_W7ikQ/T4YUZ4cROsI/AAAAAAAABKk/VrAtAVjpBtE/s1052/dual+driver+one+transistor.jpg

wardda
04/11/2012, 06:45 PM
Katchupoy,

Your diagram is what I used to design my system. The only difference that I see is that I am using two power adapters. I have a 10v regulated power adapter (rapid led) and a 9v regulated power adapter. The 10v is used how you show it in your diagram but I don't have it going to power the arduino, I have the 9v power adapter going to the power jack of the arduino. Do you think this would cause the issue?

Dan

@Warrda

Hmmm are you sure you are paralleling the drivers the same color from the driver to the transistor? are you using a pot to dim manually?

Can you double check if we have similar wiring diagram?

https://lh5.googleusercontent.com/-6WtDj_W7ikQ/T4YUZ4cROsI/AAAAAAAABKk/VrAtAVjpBtE/s1052/dual+driver+one+transistor.jpg

MaLi
04/11/2012, 07:14 PM
http://item.mobileweb.ebay.com/viewitem?itemId=280697990848

These are the relays I have. My local electronics store has them for 2.99 a piece, so I grabbed bunch.

http://i862.photobucket.com/albums/ab187/patzig/0001.jpg
http://i862.photobucket.com/albums/ab187/patzig/0002.jpg

Sorry the pics are so big, I'm posting from my phone.

Ya I thought about going with the American DJ power strip, but I found mine at home depot for cheap and impulse bought. I crammed all the relays in, strapped with tie wraps, wired everything up, dabbed silicone on all solder points and closed her up. I used rj-45 for my signal wire. One ground wire and 6 Signal for each relay. I would go the route I did and not mess with a relay board. Especially since you'll have plenty of room to mount everything in your strip.

Ya once you start plugging up relays and led drivers, you fill up the digital pins pretty quick. I too wish I had put together my own drivers instead of blowing money on the meanwells.

Massive, any chance you could post your code? I wanna start on my menu and keypad stuff.

... this is nice. You may want to replace the pcb with the protection (low importance at this stage) with a small pcb with a MCP23017 so instead of sending a bunch of wires from digital pins you will send only +5, GND, and the I2C interface (SKL, SDA). This assume you will be using the centipede library.


just two cents,
Marian

katchupoy
04/11/2012, 08:58 PM
Katchupoy,

Your diagram is what I used to design my system. The only difference that I see is that I am using two power adapters. I have a 10v regulated power adapter (rapid led) and a 9v regulated power adapter. The 10v is used how you show it in your diagram but I don't have it going to power the arduino, I have the 9v power adapter going to the power jack of the arduino. Do you think this would cause the issue?

Dan

I think you need to share the negative/common side of both power supply. You can also try (highly suggest) to just use the 10V for both the arduino and rapidled... Just try it for now... and see... I think there is a conflict.... For whats its worth, if you are not 100% sure on whats going on out there, I feel that the 10V is being piggy backed with the 9V and when this happens, it adds up.... ending up with 19V somewhere along the line...

I rather put the arduino and rapidled in one power supply, then maybe the 9v can power up the relays? Im not sure what relays you are using...
But do that first and remove the 9v for now and just use the 10v for all your power needs.... start with that.

Patzig
04/11/2012, 10:03 PM
Massive - No, I haven't had a chance to mess with the sketch. I've been busy with school...way less fun than the arduino. And I'm in information systems. I was in computer science, but couldn't handle the work/time needed for engineering. I am familiar with structures and pointers, but still trying to wrap my head around the logic behind it. Thank you for posting the tutorials, I will get to work on it soon.

Katchupoy - Thanks for posting these diagrams. I didn't realize that was your website with the diagrams for wiring up drivers to the Arduino. They really helped me out.

Mali - This is funny, when I started this Arduino project, I used your led sunrise/sunset code from reefprojects.com in my sketch. I had to change the RTC lines and a few other things, but it really helped me out, thanks! Also, that's pretty cool with the MCP23017. I didn't look into it that much yet, but would that chip ONLY need power and the obvious signal in/out connections? No other components to get it working? If so, that would definitely be cool, taking up virtually no pins, other than the shared skl and sda. And I assume this chip just assigns different mac addresses to the different output pins?

MassiveReefer
04/12/2012, 09:46 AM
Does anyone know if there is a max amount of things you can connect through i2c? I know you can only connect a sertain amount of the same thing. A lot of those digital pots i was talking about earlier can only handle up to 8ish on the same line because of how they address them.

I was also going to mention that the SRV2 is a 1k pot not 5K like I said before. I cannot find a 1k i2c through hole digipot yet. Still looking though. I think I might have to settle with a 2K or 10K pot or something, and then trust my code to keep it under 1K. I emailed meanwell and they said that if i put a pot on there bigger than 1K it could ruin the driver.

Their are however many 1-2k pots that use a three wire design(2 of the 3 use pwm pins though :/). If, when I set up my relays, I used i2c for them, i wouldnt mind using a three pin config for this digipot then. If not though, 3 pins for one pot seems like a lot. Excpecially if i do this for both drivers. :)

bmahlie
04/12/2012, 08:54 PM
bmahlie, could you possibly be running out of SRAM(volital memory) while your sketch is running? Here is something I found that could be releated:

"If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely. To check if this is happening, you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). If it then runs successfully, you're probably running out of SRAM."
From this (http://arduino.cc/en/Tutorial/Memory) site.

If you are not sure, a good way to test this would be to write a sample/test script that only writes some dummy data to the lcd, and then switches the relays. If you have a very bare bones sketch running, and you notice the same problem, then this can be rulled out. If, however, you are unable to reproduce the issue while running this "bare bones" sktech, then the issue is either running out of memory or a bug in the sketch.

What exactly happens with the lcd again? Have you tried debugging the issue yet? Are you able to break it down, and figure out if there is a specific line of code, or area of code that it happens at?

Another thing that comes to mind about what else it could be is that the relays are pulling to much power. When everything is running and the issue happens, how hot does your regulator on your arduino get? I know that the lcd's pull a somewhat large amount of amps. What is your input power to the arduino? (aka what volts/amps rating do you have for your powersupply?) It could maybe be that your walwart is not able to handle the amount of amps you are trying to pull through your system? I'm no pro, but you might also be able to try messuring the amount of amps the arduino is pulling and compair that to your walwart(powersupply) rattings. These are the first things I would loot at.


MassiveReefer and katchupoy, Thanks for your replies,.

The problem i am having is...

I have 2 relays controlling powerheadsfor a wavemaker. One of the powerheads switches every 30 sec and the other every 50 sec. I can run my program with out the powerheads hooked up (the relays switch on and off but there is no power going through the 120v AC part of the relay) to the relays with out any problems. The program will run for days (i have not tested it longer then this because i like to play with the sketch). But soon after i "plug in" the powerheads, the LCD will go blank. It seems to be caused by the relay switching with the powerheads plugged in. THN, talked about it a little bit in post 784 on page 32.

Also, i should mention that when the powerheads are plugged in, the LCD will not always go out right away, it may take a few hours.

Also, the LCD will go blank but the sketch can still run. But it will usually freeze up with in a few hours after the LCD goes out.

I have this ( http://arduino-direct.com/sunshop/index.php?l=product_detail&p=156 ) relay board. I am currently using three of these relays. Two for the powerheads and one to turn off my LED drivers and cooling fans. I do have the relay board Opto-Isolated with a separate 5v power supply.

Given this, MassiveReefer, I do not believe i am running out of SRAM because the program will run for days without the relays plugged in. Also, because i have the relay board Opto-Isolated with a separate power supply, i should not be pulling a lot of current from the andrino.

katchupoy, I have a 5v source running to the relay as well as 3 digital pins connected directly to the relay board.

Any help would be appreciated.

Thanks!

katchupoy
04/12/2012, 11:37 PM
MassiveReefer and katchupoy, Thanks for your replies,.

The problem i am having is...!

How many amps do you have for your relay 5v power supply?
Also how many volts and amps do you have for your arduino power supply?

did you read about the note on how to do optical isolation?

NOTES: If you want complete optical isolation, connect "Vcc" to Arduino +5 volts but do NOT connect Arduino Ground. Remove the Vcc to JD-Vcc jumper. Connect a separate +5 supply to "JD-Vcc" and board Gnd. This will supply power to the transistor drivers and relay coils.

If relay isolation is enough for your application, connect Arduino +5 and Gnd, and leave Vcc to JD-Vcc jumper in place.

Also read this please... (http://arduino-info.wikispaces.com/ArduinoPower#4-8)

It says each relay draws 80 ma... i believe arduino can only do 40 ma? so maybe you need to go to the optical isolation route?

dadsoldtruck
04/14/2012, 10:10 AM
Subscribed. This topic was very confusing to me, but thanks to you i think i can do it! Ty ty ty!

muda
04/14/2012, 10:20 AM
It can very much be interference coming from relay contact or coil that causes LCD freeze. I have same problem which is caused by ATO kicking in. Not often but still ... Must note that my ATO is completely separate unit . I say this in case optical isolation is not helping you. Rearranging components and adding feritte rings to power cords helped somewhat.

katchupoy
04/14/2012, 10:26 AM
@DADS

thank you also for your kind words... The first 6 pages are the critical ones. And the updated index is at page 53. When in doubt, just ask. I will try my best to answer. Welcome to RF....

also some of my pics are not showing up.... Damn picasa. But if you search caddnima and google it, you should find my website.....

badstraw
04/15/2012, 12:04 AM
Hey guys can I use this real time clock

http://img17.imageshack.us/img17/2978/smlmvof773974424875.jpg

Instead of using the DS1307 Real Time Clock?

Would it work?

Another quick question...In the meantime I can just skip getting the LCD screen and it would work with the code by itself, correct?

katchupoy
04/15/2012, 12:57 AM
@Badstraw,,

the picture won't tell us anything, where is the link of the store you are getting this from?
I believe , even without the lcd screen, it snould work. Its just hard to tell if the program is running or not. But it should work

badstraw
04/15/2012, 01:06 AM
Here's the data sheet : http://infinitec-ml.site50.net/dsz/201033.html

1. General description
2. Features
The PCF8563 is a CMOS real-time clock/calendar optimized for low power consumption. A programmable clock output, interrupt output and voltage-low detector are also provided. All addresses and data are transferred serially via a two-line bidirectional I2C-bus. Maximum bus speed is 400 kbit/s. The built-in word address register is incremented automatically after each written or read data byte.
s Provides year, month, day, weekday, hours, minutes and seconds based on 32.768 kHz quartz crystal
s Century flag
s Clock operating voltage: 1.8 V to 5.5 V
s Low backup current; typical 0.25 μA at VDD = 3.0 V and Tamb = 25 °C
s 400 kHz two-wire I2C-bus interface (at VDD = 1.8 V to 5.5 V)
s Programmable clock output for peripheral devices (32.768 kHz, 1024 Hz, 32 Hz and
1 Hz)
s Alarm and timer functions
s Integrated oscillator capacitor
s Internal power-on reset
s I2C-bus slave address: read A3h and write A2h
s Open-drain interrupt pin
s ElectroStatic Discharge (ESD) protection exceeds 2000 V Human Body Model (HBM)
per JESD22-A114, 200 V Machine Model (MM) per JESD22-A115 and 2000 V Charged Device Model (CDM) per JESD22-C101
s Latch-up testing is done to JEDEC standard JESD78 which exceeds 100 mA

The online store won't tell anything, it only shows the picture and the price..

What do you think?

katchupoy
04/15/2012, 01:19 AM
can't say, maybe we need to wait from the experts. Worst come to worst, that my code will not work, and just need to change something on the code to make it I2C compatible. I believe it should work, but not 100% sure. And I am no code expert.

badstraw
04/15/2012, 02:05 AM
For those people who are still using the original sketch. I mentioned before that the sketch has a wavemaker function built-in.

All you need to add are relays. There are several types, but I will concentrate on two common ones. The 5vdc coil ones that you can connect directly to arduino, or the 12vdc coil ones that are more common and more heavy duty.

Diagram 1 is for the 5v coil setup...
https://lh5.googleusercontent.com/-aqZgY5XEidg/T4X_EggpGeI/AAAAAAAABKI/5Y75VO2b3bI/s1024/relay%25205v%2520wiring.jpg


Diagram 2 is for the 12v coil setup...
https://lh4.googleusercontent.com/-4jmTz4sY16o/T4X8kl4IIzI/AAAAAAAABJs/2eHWlnXmB3s/s1024/relay%252012v%2520wiring.jpg

Hope this helps.

.

Thank you for your response katchupoy, I hope I can use the PCF8563 real time clock for my project... I'll wait for an advice from another expert. :)

Would you update the diagrams please?

muda
04/15/2012, 02:26 AM
Please help solving small problem.

I need few timer for my controller for relay control. Problem is I dont know how to write code for it . :)
Anytime when set time range intersect with fade part all messes up.

muda
04/15/2012, 04:49 AM
This is how I try doing that :

if (hour >= 11)
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}

I know - I am not good at coding at all. :D

Atc5016
04/15/2012, 01:02 PM
Hello Guys.

So I am very new to this and I have been spending some time looking though this thread among other research and I was wondering if the is a simple Arduino sketch out that that utilizes the DS1307 RTC to fade a 0-5v signal at a specified time. I have seen the others out their but they appear to be very overwhelming with all the additional information. Any help would be greatly appreciated and feel free to contact me if you are willing to help me out. I am hoping one day to learn enough to add all the other equipment but I am having a hard time learning how to implement the RTC to create a time based event at this moment. I apologize in advance if this information is already out there.

katchupoy
04/15/2012, 03:38 PM
@badstraw
Sorry for the images.... here they are...



LED + arduino + transistor.
https://lh6.googleusercontent.com/-dImZj0eRbSs/TzIba6KNVhI/AAAAAAAABK8/XN3RuCUptKI/s800/WiringDiagNPN.jpg



Arduino + Breadboard + Transistor
This schematic is using two POTS for two channels. One for blue and one for white. One channel can handle several drivers, example 3 drivers or 36 LEDs in one channel.
https://lh3.googleusercontent.com/-PcFmutGsq6Q/TzIbb4QZXyI/AAAAAAAABK8/5N19frMAT94/s800/Breadboard%2Btransistor.jpg



Arduino + Transistor + 2 Drivers
As mentioned above, you can use one channel with several drivers.
https://lh4.googleusercontent.com/-6WtDj_W7ikQ/T4YUZ4cROsI/AAAAAAAABO0/jM6RqHT2bXQ/s800/dual+driver+one+transistor-001.jpg



Arduino + Transistor (No Potentiometer)
If you decided you dont need the POTS, and just do the show and tell to your friends via programming within the sketch.
https://lh6.googleusercontent.com/-7MNafMzG1AA/TzIbdbz1ClI/AAAAAAAABK8/1UeQ_kghOY0/s800/arduino%2Btransistor_simple.jpg



Arduino + Transistor + 12volts + 2 Potentiometer
You only do this when you are using 12 volts as power supply. One pot is to make it to 10 volts and never touch again. And the other is for the dimming up or down of one channel.
https://lh6.googleusercontent.com/-95sL9vIRSw4/TzIbdzaLUeI/AAAAAAAABK8/98-vrDMqcII/s800/arduino%2Btransistor%2Bpot_simple.jpg



Arduino + Transistor + 12 volt Relay
12 volts relay used. Cannot use Arduino pins directly to power the relay coil so we will need a transistor instead and use the same 10 volts power supply that sends signal to our drivers.
https://lh4.googleusercontent.com/-aP431Bpqvwc/T4s6Xji_pOI/AAAAAAAABOo/fSUH9gVC92Y/s800/relay+12v+wiring.jpg



Arduino + Transistor + 5 volt Relay
5 volts relay used. This type of relay can be connected directly to non-pwm pins of your Arduino without the use of transistors.
https://lh5.googleusercontent.com/-L6_ygdy9prs/T4s6W7MdPcI/AAAAAAAABOg/2vePndcpc_k/s800/relay+5v+wiring.jpg

katchupoy
04/15/2012, 03:46 PM
This is how I try doing that :

if (hour >= 11)
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}

I know - I am not good at coding at all. :D


Muda, I wish I can help you. I not also good with coding. One thing i can tell, is you need to do define it outside of the loop... very similar to the relay function...

Take a look at my original sketch again... (https://sites.google.com/site/caddnima/myreeftank/led_controller/arduinosketch)

Then take a look at the relay. See, they were defined first outside of the loop. Then you will just recall the function inside the loop... see the relay1, relay2???

Let me know how it works... I want to also do dosing function in mine...lol.
Btw, what sketch are you using???

katchupoy
04/15/2012, 03:49 PM
Hello Guys.

So I am very new to this and I have been spending some time looking though this thread among other research and I was wondering if the is a simple Arduino sketch out that that utilizes the DS1307 RTC to fade a 0-5v signal at a specified time. I have seen the others out their but they appear to be very overwhelming with all the additional information. Any help would be greatly appreciated and feel free to contact me if you are willing to help me out. I am hoping one day to learn enough to add all the other equipment but I am having a hard time learning how to implement the RTC to create a time based event at this moment. I apologize in advance if this information is already out there.


ATC5016, WELCOME, WELCOME, WELCOME!!!!

Im glad you can join us, I will try to help you as much as I can, but Im no expert.

Why 5 volts? I believe Arduino pins are native 5 volts, so no transistors needed?

If you are having a hard time learning, then lets take super baby steps... I will walk you through...

Time based? me too, but explain further what you need to do and maybe we can decipher it....

Atc5016
04/15/2012, 04:02 PM
Thanks!

I want to control the BuckPuck Drivers for my new Led setup on my 35gal Reef. I have a good understanding of the electronics side of how to get the 0-10v signal, but when it comes to the coding I am quite lost. I just purchased the Arduino uno, the only thing I am waiting for still is my RTC. In the mean time I have been playing around the software RTC (swRTC) and got the readout via the example but no idea how to actually set up a time based even with a fade. I have your sketch but there is a lot of extra info in there that I am not looking for at this time. (is it possible to just delete or ignore the coding I dont use?) Also I do not have the LCD shield and dont plan on using one at this point in the setup. I dont know if you have a version for the 1.0 software yet but I have not found it.

So in the end at this moment all I want is to use the RTC to have my blue lights fade in at a time and then my whites, then fade out at the end of the night. Would it be possible for you to explain or send me sketch with just that info if you have it? Is that rude of me to ask? Again I am trying to learn and not sure what is proper of me to ask but any info is greatly appreciated, the last time I coded anything was 9+ years ago and was not this complicated.

THANK YOU, THANK YOU, THANK YOU!

bioreefdude
04/15/2012, 04:42 PM
ok so i spent all weekend reading entire thread . i ordered all parts , i also got the lcd/keyboard shield 16x2 (now i want bigger)anywho i dont have any hardware yet but i have been playing with sketchs and the Arduino software v1.0 and i am getting error messages up the wazoo is this because i dont have arduino hooked up or are the sketches out of day ?

katchupoy
04/15/2012, 05:35 PM
I want to control the BuckPuck Drivers for my new Led setup on my 35gal Reef. I have a good understanding of the electronics side of how to get the 0-10v signal, but when it comes to the coding I am quite lost.
I believe no conversion is needed with buckpuck. Since buckpuck is 5volts and arduino is the same... just simple plug and play with the arduino pins. Maybe this can help. (http://www.nano-reef.com/forums/index.php?showtopic=214770)


I have your sketch but there is a lot of extra info in there that I am not looking for at this time. (is it possible to just delete or ignore the coding I dont use?)
Dont delete, just ignore. Just pay special attention on the pins where you put them. Pin 3 for the blue and Pin 11 for the white.


Also I do not have the LCD shield and dont plan on using one at this point in the setup. I dont know if you have a version for the 1.0 software yet but I have not found it.
You can download it here.... (http://arduino.cc/en/Main/Software)


So in the end at this moment all I want is to use the RTC to have my blue lights fade in at a time and then my whites, then fade out at the end of the night. Would it be possible for you to explain or send me sketch with just that info if you have it? Is that rude of me to ask? Again I am trying to learn and not sure what is proper of me to ask but any info is greatly appreciated, the last time I coded anything was 9+ years ago and was not this complicated.
Try to decipher the original sketch... i have reconstructed it with notes so that it would be easier to understand. Download it here. (https://sites.google.com/site/caddnima/my-files/katchupoy.pde?attredirects=0)

katchupoy
04/15/2012, 05:41 PM
ok so i spent all weekend reading entire thread . i ordered all parts , i also got the lcd/keyboard shield 16x2 (now i want bigger)anywho i dont have any hardware yet but i have been playing with sketchs and the Arduino software v1.0 and i am getting error messages up the wazoo is this because i dont have arduino hooked up or are the sketches out of day ?

Dude! WELCOME!

Yes you are correct, it is because there is no arduino hooked up. Also on the selection, I believe you need to choose "duemilanove" on the drop down. Really depends on what arduino you bought. They will tell you what to use.

Atc5016
04/15/2012, 05:45 PM
Thanks again, I will look over all of it! and I wanted to correct myself I am using both the Buck Puck and Buck Block, the Block requires a 0-10v. Looks like I have some reading to do, thanks for all the help so far! ( Correction) I was wondering if you had an updated version of your sketch I get a lot of errors when I try to open it in the new software and I cant seem to correct for it.

Atc5016
04/15/2012, 05:56 PM
If I change all the wire.write and wire.read in the sketch I still end up with these errors...

Is this because I do not have the RTC connected yet? It seems to verify correctly in the 0022 software I have.


katchupoy.cpp: In function 'void setDateDs1307(byte, byte, byte, byte, byte, byte, byte)':
katchupoy.pde:-1: error: call of overloaded 'write(int)' is ambiguous
/Applications/Arduino (original).app/Contents/Resources/Java/libraries/Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
/Applications/Arduino (original).app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note: size_t Print::write(const char*)
katchupoy.cpp: In function 'void getDateDs1307(byte*, byte*, byte*, byte*, byte*, byte*, byte*)':
katchupoy.pde:-1: error: call of overloaded 'write(int)' is ambiguous
/Applications/Arduino (original).app/Contents/Resources/Java/libraries/Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
/Applications/Arduino (original).app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note: size_t Print::write(const char*)

bioreefdude
04/15/2012, 09:16 PM
u know i get those same error messages

Atc5016
04/15/2012, 09:49 PM
Ok so my apologies if I am becoming annoying but... I am trying to figure this coding out and while katchupoy's sketch kinda makes sense to me I still have a hard time understanding how to actually create an event based on the time that was set in the RTC. I am going to try wait for my RTC to come in the mail but in the mean time I found the swRTC ( http://www.leonardomiliani.com/?p=411&lang=en ) and have been trying to replace the hardware version in katchupoy's sketch. I have been very unlucky, is it even possible? Anyone else ever use this library and have a piece of the sketch I can view. Something even as simple as turn pin 9 on at full at a certain time might help me out understanding how to work with it.

If not I will try to wait until my RTC comes in and load ketchupoy's sketch and play around with it a little.

Any suggestions on were to learn how to code these things written in a "for Dummies" style?

bioreefdude
04/15/2012, 10:14 PM
well i was checking things out and it turns out there are a few new libraries for a few different things rtc being one. i also believe that when they update a library that can dramatically change the wording in a code so now the only RTC library that will work for ds1307 for 1.0 is DS1307new.h .so if we can get these wonder programmers to update the sketch we will be ok

bioreefdude
04/15/2012, 10:36 PM
dbl post

bioreefdude
04/15/2012, 10:37 PM
dbl post sorry

bioreefdude
04/15/2012, 10:40 PM
here is example of new library// #############################################################################
// #
// # Scriptname : DS1307_Test.pde
// # Author : Peter Schmelzer, Oliver Kraus
// # Date : 2011-04-08
// # Version : 1.21
// # License : cc-by-sa-3.0
// #
// # Description:
// # Test file for the DS1307new library. Assumes that you have a DS1307
// # connected to the I2C-Bus of your Arduino and that it has a battery backup.
// #
// #############################################################################
// *********************************************
// INCLUDE
// *********************************************
#include <Wire.h> // For some strange reasons, Wire.h must be included here
#include <DS1307new.h>

// *********************************************
// DEFINE
// *********************************************

// *********************************************
// VARIABLES
// *********************************************
uint16_t startAddr = 0x0000; // Start address to store in the NV-RAM
uint16_t lastAddr; // new address for storing in NV-RAM
uint16_t TimeIsSet = 0xaa55; // Helper that time must not set again

// *********************************************
// SETUP
// *********************************************
void setup()
{
pinMode(2, INPUT); // Test of the SQW pin, D2 = INPUT
digitalWrite(2, HIGH); // Test of the SQW pin, D2 = Pullup on

Serial.begin(9600);

/*
PLEASE NOTICE: WE HAVE MADE AN ADDRESS SHIFT FOR THE NV-RAM!!!
NV-RAM ADDRESS 0x08 HAS TO ADDRESSED WITH ADDRESS 0x00=0
TO AVOID OVERWRITING THE CLOCK REGISTERS IN CASE OF
ERRORS IN YOUR CODE. SO THE LAST ADDRESS IS 0x38=56!
*/
RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));// Store startAddr in NV-RAM address 0x08

/*
Uncomment the next 2 lines if you want to SET the clock
Comment them out if the clock is set.
DON'T ASK ME WHY: YOU MUST UPLOAD THE CODE TWICE TO LET HIM WORK
AFTER SETTING THE CLOCK ONCE.
*/
// TimeIsSet = 0xffff;
// RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));

/*
Control the clock.
Clock will only be set if NV-RAM Address does not contain 0xaa.
DS1307 should have a battery backup.
*/
RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
if (TimeIsSet != 0xaa55)
{
RTC.stopClock();

RTC.fillByYMD(2011,4,8);
RTC.fillByHMS(22,7,0);

RTC.setTime();
TimeIsSet = 0xaa55;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
RTC.startClock();
}
else
{
RTC.getTime();
}

/*
Control Register for SQW pin which can be used as an interrupt.
*/
RTC.ctrl = 0x11; // 0x00=disable SQW pin, 0x10=1Hz,
// 0x11=4096Hz, 0x12=8192Hz, 0x13=32768Hz
RTC.setCTRL();

Serial.println("DS1307 Testsketch");
Serial.println("Format is \"hh:mm:ss dd-mm-yyyy DDD\"");

uint8_t MESZ;

MESZ = RTC.isMEZSummerTime();
Serial.print("MEZ=0, MESZ=1 : ");
Serial.println(MESZ, DEC);
Serial.println();
}

// *********************************************
// MAIN (LOOP)
// *********************************************
void loop()
{
RTC.getTime();
if (RTC.hour < 10) // correct hour if necessary
{
Serial.print("0");
Serial.print(RTC.hour, DEC);
}
else
{
Serial.print(RTC.hour, DEC);
}
Serial.print(":");
if (RTC.minute < 10) // correct minute if necessary
{
Serial.print("0");
Serial.print(RTC.minute, DEC);
}
else
{
Serial.print(RTC.minute, DEC);
}
Serial.print(":");
if (RTC.second < 10) // correct second if necessary
{
Serial.print("0");
Serial.print(RTC.second, DEC);
}
else
{
Serial.print(RTC.second, DEC);
}
Serial.print(" ");
if (RTC.day < 10) // correct date if necessary
{
Serial.print("0");
Serial.print(RTC.day, DEC);
}
else
{
Serial.print(RTC.day, DEC);
}
Serial.print("-");
if (RTC.month < 10) // correct month if necessary
{
Serial.print("0");
Serial.print(RTC.month, DEC);
}
else
{
Serial.print(RTC.month, DEC);
}
Serial.print("-");
Serial.print(RTC.year, DEC); // Year need not to be changed
Serial.print(" ");
switch (RTC.dow) // Friendly printout the weekday
{
case 1:
Serial.print("MON");
break;
case 2:
Serial.print("TUE");
break;
case 3:
Serial.print("WED");
break;
case 4:
Serial.print("THU");
break;
case 5:
Serial.print("FRI");
break;
case 6:
Serial.print("SAT");
break;
case 7:
Serial.print("SUN");
break;
}
Serial.print(" seconds since 1.1.2000:");
Serial.print(RTC.time2000, DEC);
uint8_t MESZ = RTC.isMEZSummerTime();
Serial.print(" MEZ=0, MESZ=1 : ");
Serial.print(MESZ, DEC);

Serial.print(" - Address in NV-RAM is: ");
RTC.getRAM(0, (uint8_t *)&lastAddr, sizeof(uint16_t));
Serial.print(lastAddr, HEX);
lastAddr = lastAddr + 1; // we want to use it as addresscounter for example
RTC.setRAM(0, (uint8_t *)&lastAddr, sizeof(uint16_t));
RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
if (TimeIsSet == 0xaa55) // check if the clock was set or not
{
Serial.println(" - Clock was set!");
}
else
{
Serial.println(" - Clock was NOT set!");
}
delay(1000); // wait a second
}

bioreefdude
04/15/2012, 11:06 PM
i love th internet ok so check this if u have changed the sends and receives the next step is here heres example:
void getDateDs1307()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS)
Wire.write((byte)0x00); // This is where you make the change correction is made insert ((byte) before 0x00 do this to each wire.write
Wire.endTransmission();

bioreefdude
04/15/2012, 11:44 PM
im goning for this on a way smaller scale with ato and arduino

TuDYCCaVIKo

muda
04/16/2012, 12:03 AM
Hi Kachupoy,

Thanks for trying to help. I have defined everything already. My timer actually is working somehow this way . But only during night time. When ramping time comes it starts acting incorectly. I thing I need to place that part of code in apropriate location (I dont know how to tell that in programmers language :))

I use modified sketch. Blue and white lights are not ramping separatelly now. Blue light starts and when it reaches 15%, white kicks in and starts to trail. Finaly both end at 100%. I like it much more as there is no prolonged period of too deep blueness, which looked too unnaturall for my liking. Some still persists though.
I am also controling on-off for led powersupply, heater, fan, algae scrubber lights( the one bothers me now). And I have LCD dimming function for night time so bright light is not interrupting my sons sweet dreams now.
Guess that is all for now.
I'd like add more timers for dosing too ,but failure with one timer not alows me to dream for more.
Hope somebody will help.

katchupoy
04/16/2012, 09:38 AM
Muda, email me your code... let me see....
caddnima gmail

MassiveReefer
04/16/2012, 11:36 AM
Atc, I can try and help you understand the errors. First, you could be able to compile a sketch without the arduino hooked up without any problems, but you will see errors if you try to upload the sketch without it connected. NOTE FOR ALL: I have noticed may bugs in the IDE(aruino software). Do not try to compile the sketch while it is already compiling. When I do this, I get really strange errors, and the only way to fix it is to fully close out of all open arduino sketches and reopen them and compile.

Now for the errors. I will take this one line at a time. (each line is a the lines off errors you posted)
Line 1: This is telling you where the error is happening. It is happening in function setDateDs1307(byte, byte, byte, byte, byte, byte, byte)
Line 2: This is what the problem is. What it is saying is that you have defined the same function twice within all of your librarys. More on this in a second.
Line 3 & 4: This is telling you where the two ambiguous(same) functions are being defined.

this is what is happening. I dont have time to pull up the sketch, so forgive me if I am a little off but here we go...
Somewhere within function setDateDs1307(byte, byte, byte, byte, byte, byte, byte) you must be calling the function write(). Since there is two deffinitions of the function write(), the compiler does not know what one to use so it spits an error. It looks like the two functions are being defined in your wire.h class and the arduinos core library print.h. Now it is clear that you did not write any of these classes so you most likely didn't "define" this functions on your own. Thus, the issue must be related to what you "include". By including two libraries that have the same function name you will get an error like this. If you are using katchupoy's sketch, you either included a class that should not have been included, or your wire.h/print.h classes are different than katchupoy's. Check for any includes at the top of the screen for these two classes, wire.h/print.h, and see if they are in the sketches you are copying.

MassiveReefer
04/16/2012, 11:39 AM
Muda, I would be willing to help(Coding is my strong point here), but I am afraid I dont understand your question, or even what your code that you posted is trying to do. If Katchupoy isn't able to trouble shoot the issue for you, let me know and I will take a look at it.

MassiveReefer
04/16/2012, 11:52 AM
Katchupoy, I glanced over your "original" sketch that you linked to above and I thought I would share something that I noticed. In your two relay functions, you use millis() to figure out how long your ph's have been on/off. I'm not sure if you have or even would notice this, but technicaly there is a bug here. Millis() returns the number of milliseconds since the arduino has been turned on/reset. Once this number gets so big, it will start back at zero. Thus, not making it reliable for keeping track of time. I think this starts back at zero every week or so ish. I didn't study the code long enough to figure out exactly what would happen, but it seems that their is a possibility that after it rolls over to zero, your powerheads may not turn on/off like you would want them to. Exspecially since you add that full second delay in your oneSecond() function. I'm not really sure why you need to pause for a second in that function, but thats a different topic. I would recommend using the time off of your RTC for this calculation instead of using millis, but if you are able to leave your controller on for 2 weeks + without seeing any issue, it might not be a big deal and I might just be being picky with code.

Hope you dont mind my observations.

muda
04/16/2012, 02:44 PM
I just post my code here . May be someone will find something interesting in it. My problem name is ATS. :)

I want it go on and of on defined time. Like simple timer, that we use for tank lights when we dont have this controler. Just simple on and of. But when I set of time which is in ramp up, or max or down zone , relay starts klicking on-of .

ATS is my algae scruber (kind of refugium- for those who dont know. ) It starts , when main lights go of. But I need posibility to set exact time for of. And I need posibility to change it flexibly. Now I set it exactly when DT lights start max period. This way I awoid clicking relay. But if I add 5mins - I got 5 mins of clickig relay. On -of-on-of...


* ------------------------------
* 0 HEATER A0 FAN
* 1 ATS A1 24V
* 2 A2
* 3 MOON LED PWM A3
* 4 LCD A4 RTC
* 5 LCD PWM A5 RTC
* 6 LCD PWM
* 7 LCD
* 8 TEMP
* 9 BACKLTH PWM
* 10 LED PWM
* 11 LED PWM
* 12 LCD
* 13 LCD
* -------------------------------

**********************************************************************************/
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 // Set rtc
#include <LiquidCrystal.h> // initialize the library with the numbers of pins
#define ONE_WIRE_BUS 2 // Define the pin of the DS18B20

/*||||||||||||||||||| L E D D I M M I N G P A R T ||||||||||||||||||||||||||*/

int bluemin = 0 ; // minimmum dimming value of blue LEDs, range of 0-255
int bluemax = 255 ; // maximum dimming value of blue LEDs, range of 0-255
int whitemin = 0 ; // minimum dimming value of white LEDs, range of 0-255
int whitemax = 255 ; // maximum dimming value of white LEDs, range of 0-255
int photoperiod = 420 ; // amount of time array is on at full power in minutes
int ontime = 7 ; // when start photoperiod fade in
int ramptime = 240 ; // time for LEDs to dim on and off in minutes

/*||||||||||||||||||||||||||||||||| P I N ||||||||||||||||||||||||||||||||||||||*/

int blue = 11; // blue LEDs connected to digital pin 11 (pwm)
int white = 10; // white LEDs connected to digital pin 10 (pwm)

int fan = A0;
int ats = 1;
int heater = 0;
int light = A1;
int moon = 3;
int backlight = 9;

int iBlueIntensity; //declare the integer of blue intensity
float fBlueIntensity; //declare the floating point version of blue intensity

int bluepercent[] = { 0, 2, 3, 4, 5, 7, 11, 15, 26, 52, 78, 100, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255 };
int whitepercent[]= { 0, 0, 0, 0, 2, 3, 4, 8, 18, 40, 54, 75, 99, 110, 130, 155, 175, 200, 210, 230, 255, 255 };

int abc(sizeof(bluepercent)/sizeof(bluepercent[0]));

LiquidCrystal lcd(13,12,7,6,5,4); // initialize the library with the numbers of the interface pins

byte newChar[8] = { // Set up the custom icon saule leidzias ir kyla ( 0 ir 1 kyla) (2 ir 3 leidzias) (4 ir 5 menulis )
B01001,
B01001,
B00101,
B00101,
B10101,
B10111,
B01111,
B11111
};

byte newChar1[8] = {
B10010,
B10010,
B10100,
B10100,
B10101,
B11101,
B11110,
B11111
};
byte newChar2[8] = {
B11111,
B01111,
B10111,
B10101,
B00101,
B00101,
B01001,
B01001
};
byte newChar3[8] = {
B11111,
B11110,
B11101,
B10101,
B10100,
B10100,
B10010,
B10010
};
byte newChar4[8] = {
B00111,
B01110,
B11100,
B11000,
B11000,
B11100,
B01110,
B00111
};
byte newChar5[8] = {
B01010,
B10000,
B00010,
B01001,
B00100,
B10000,
B00100,
B10001
};
byte newChar6[8] = {
B01010,
B00100,
B00001,
B11011,
B00011,
B00001,
B01000,
B10010
};
byte newChar7[8] = {
B10010,
B00100,
B10000,
B11011,
B11000,
B10000,
B00010,
B01001
};

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.

/*||||||||||||||||||||||||||||||||||||||| R T C C L O C K D S 1 3 0 7 ||||||||||||||||||||||||||||||||||||*/

byte decToBcd(byte val) // Convert normal decimal numbers to binary coded decimal
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers
{
return ( (val/16*10) + (val%16) );
}
void setDateDs1307(byte second,
byte minute,
byte hour,
byte dayOfWeek,
byte dayOfMonth,
byte month,
byte year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f);
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}

/*|||||||||||||||||||||||||||||||||||| D E F I N E : B A C K L I G H T ||||||||||||||||||||||||||||||*/
void backlighton()
{
analogWrite(backlight, 200);
}
void backlightoff()
{
analogWrite(backlight, 25); // If too bright or dim adjust the value accordingly.
}
/*|||||||||||||||||||||||||||||||||| D E F I N E : L U N A R P H A S E ||||||||||||||||||||||||||||||*/

int moonPhase(int moonYear, int moonMonth, int moonDay)
{
int dayFromYear, dayFromMonth;
double julianDay;
int phase;

if (moonMonth < 3) //keep the month before march
{
moonYear--; //take away a year
moonMonth += 12; //add an extra 12 months (the year taken away from before)
}
++moonMonth;
dayFromYear = 365.25 * moonYear; //get days from current year
dayFromMonth = 30.6 * moonMonth; //get number of days from the current month
julianDay = dayFromYear + dayFromMonth + moonDay - 694039.09; //add them all
julianDay /= 29.53; //divide by the length of lunar cycle
phase = julianDay; //take integer part
julianDay -= phase; //get rid of the int part
phase = julianDay*8 + 0.5; //get it between 0-8 and round it by adding .5
phase = phase & 7; //get a number between 1-7
return phase; //1 == new moon, 4 == full moon
}
/*|||||||||||||||||||||||||||||||||||||||| D E F I N E : O N E S E C O N D ||||||||||||||||||||||||||||||*/

void onesecond() //function that runs once per second while program is running
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.setCursor(0, 1);
if(hour>0)
{
if(hour<=12)
{
lcd.print(hour, DEC);
}
else
{
lcd.print(hour, DEC);
}
}
else
{
lcd.print("12");
}
lcd.print(":");
if (minute < 10) {lcd.print("0");}
lcd.print(minute, DEC);
//lcd.print(":");
//if (second < 10) {lcd.print("0"); }
//lcd.print(second, DEC);
delay(1000);
}

/*|||||||||||||||||||||||||| D E F I N E : 24 V O N - O F |||||||||||||||||||||||||||||||||*/

void LightOn()
{
digitalWrite(light, HIGH);
lcd.setCursor(3, 3);
lcd.print("+");
}

void LightOff()
{
digitalWrite(light, LOW);
lcd.setCursor(3, 3);
lcd.print("-");
}
/*|||||||||||||||||||||||||| D E F I N E : A T S O N - O F |||||||||||||||||||||||||||||||||*/

void AtsOn()
{
digitalWrite(ats, LOW);
lcd.setCursor(19, 3);
lcd.print("+");
}

void AtsOff()
{
digitalWrite(ats, HIGH);
lcd.setCursor(19, 3);
lcd.print("-");
}

/*||||||||||||||||||||||||||||||||||||| S E T U P P I N ||||||||||||||||||||||||||||||||||||||||||||*/

void setup() {
pinMode(heater, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(light, OUTPUT);
pinMode(ats, OUTPUT);
pinMode(moon, OUTPUT);
pinMode(backlight, OUTPUT);

sensors.begin(); // Start up the DS18B20 Temp library

/*||||||||||||||||||||||||||||||| S E T U P - C L O C K ||||||||||||||||||||||||||||||||||||||||*/

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();

second = 00;
minute = 54;
hour = 13;
dayOfWeek = 6; // Sunday is 0
dayOfMonth = 14;
month = 04;
year = 12;

//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); // ******* set the clock *******

// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.

analogWrite(blue, bluemin);
analogWrite(white, whitemin);
lcd.createChar(0, newChar);
lcd.createChar(1, newChar1);
lcd.createChar(2, newChar2);
lcd.createChar(3, newChar3);
lcd.createChar(4, newChar4);
lcd.createChar(5, newChar5);
lcd.createChar(6, newChar6);
lcd.createChar(7, newChar7);
lcd.begin(20, 4);
//lcd.setCursor(0, 0);
//lcd.write(0);
//lcd.write(1);
lcd.setCursor(3, 0);
lcd.print("Jokubo koralai ");
//lcd.setCursor(18, 0);
//lcd.write(3);
//lcd.write(2);
lcd.setCursor(11, 1);
lcd.print("B:");
lcd.print(33*bluemin/85);
lcd.setCursor(16, 1);
lcd.print("W:");
lcd.print(33*whitemin/85);
lcd.setCursor(11, 2);
lcd.print("L: ");
lcd.setCursor(0, 2);
lcd.print("W: ");
lcd.setCursor(0, 3);
lcd.print("24V");
lcd.setCursor(5, 3);
lcd.print("Fan");
lcd.setCursor(11, 3);
lcd.print("Htr");
lcd.setCursor(16, 3);
lcd.print("Ats");
}



/*|||||||||||||||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@||||| L O O P |||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@||||||||||||||||||||||*/

void loop()
{
onesecond();

/*||||||||||||||||||||||||||||||||||||||||||||||| L U N A R |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


float fSecond, fHour, fMinute; //turn the times read from the RTC into float for math ops
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; //declare variables to hold the times
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); //read the RTC times
int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
fSecond = (float) second; //sets fSecond as the float version of the integer second from the RTC
fMinute = (float) minute; //same as above, but for the minute
fHour = (float) hour; //ditto, but for the hour
int lunarCycle = moonPhase(year, month, dayOfMonth); //get a value for the lunar cycle

//--------MOON LED SETUP----------//

if ( ((hour == 7) && (minute < 00)) || (hour < 7))//Off at 730am.
{
fBlueIntensity = 255; //...then we want the blue LED at the max brightness (255)
}

else if (hour > 18) //&& (hour < 19)) // On at 5pm
{
fBlueIntensity = 255 * (((fHour - 16) + (fMinute / 59)) / 7); //...set intensity out of 255 based on time since 17:00
}
else
{
fBlueIntensity = 0;
}

//--------- Account for the moon cycle with the blue LEDs ---------//

if (lunarCycle == 0) //new moon
{
fBlueIntensity /= 2;
}
if ((lunarCycle == 1) || (lunarCycle == 7)) //cresent
{
fBlueIntensity /= 1.75 ;
}
if ((lunarCycle == 2) || (lunarCycle == 6)) //half moon
{
fBlueIntensity /= 1.5;
}
if ((lunarCycle == 3) || (lunarCycle == 5)) //gibbous
{
fBlueIntensity /= 1.25;
}

//full moon is full intensity


//----------FLOAT TO INT-------------//
iBlueIntensity = (int) fBlueIntensity;

//---prepare the intensities to be written to pin----//

if (iBlueIntensity < 0) //if the blue intensity is less then 0, set it to 0
{
iBlueIntensity = 0;
}
analogWrite(moon, iBlueIntensity);
delay(1000);

/*|||||||||||||||||||||||||||||||||||||||| T E M P E R A T U R E DS18B20 |||||||||||||||||||||||||||||||||||*/

sensors.requestTemperatures(); // Send the command to get temperatures
delay(750);
lcd.setCursor(13, 2);

float temp1=0, temp2=0;

temp1=sensors.getTempCByIndex(1);
lcd.print(sensors.getTempCByIndex(1));
lcd.print((char)223);
lcd.print("C");

lcd.setCursor(2, 2);

temp2=sensors.getTempCByIndex(0);
lcd.print(sensors.getTempCByIndex(0));
lcd.print((char)223);
lcd.print("C");

if ( (temp2) > 26.5)
{
digitalWrite(fan, HIGH);
lcd.setCursor(8, 3);
lcd.print("+");
}
else if ( (temp1) > 45)
{
digitalWrite(fan, HIGH);
lcd.setCursor(8,3);
lcd.print("+");
}
else if ((temp2) < 26.4)
{
digitalWrite(fan, LOW);
lcd.setCursor(8,3);
lcd.print("-");
}

if ( (temp2) < 24.3 )
{
digitalWrite(heater, HIGH);
lcd.setCursor(14,3);
lcd.print("+");
}
else if ( (temp2) > 24.6 )
{
digitalWrite(heater, LOW);
lcd.setCursor(14,3);
lcd.print("-");
}

/*|||||||||||||||||||||||||||||||||||||||||||||||||||| ATS |||||||||||||||||||||||||||||||||||||||||||||||||*/
if (hour >= 11) // butu 14 val
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}

/*|||||||||||||||||||||||||||||||| R A M P T I M E C A L C U L A T I O N ||||||||||||||||||||||||||||||||*/


int rampup;
if (daybyminute >= (ontime*60))
rampup = (((ontime*60) + ramptime) - daybyminute);
else
rampup = ramptime;

int rampdown;
if (((ontime * 60) + photoperiod + ramptime) <= daybyminute)
rampdown = (((ontime*60) + photoperiod + 2*ramptime) - daybyminute);
else
rampdown = ramptime;

/*|||||||||||||||||||||||||||||||||||||||||| F A D E I N ||||||||||||||||||||||||||||||||||||||||||||||*/

if (daybyminute >= (ontime*60))
{ if (daybyminute < ((ontime*60) + ramptime))
{
LightOn();
backlighton();

lcd.setCursor(0, 0);
lcd.write(0);
lcd.write(1);
lcd.setCursor(18, 0);
lcd.write(0);
lcd.write(1);

int i;
for (int i = 0; i < abc; i++)
{
analogWrite(blue, bluepercent[i]);
analogWrite(white, whitepercent[i]);

lcd.setCursor(13, 1);
lcd.print((bluepercent[i]*99)/255);
if (i < 10) lcd.print(" ");

lcd.setCursor(18, 1);
lcd.print((whitepercent[i]*99)/255);
if (i < 10) lcd.print(" ");

int countdown = ((rampup*60)/abc);
while (countdown>0)
{
onesecond();
countdown--;

lcd.setCursor(6, 1);
if (countdown < 100) lcd.print ("0");
if (countdown < 10) lcd.print ("0");
lcd.print(countdown);
}
}
}
}

/*||||||||||||||||||||||||||||||||||||||||||||||| M A X |||||||||||||||||||||||||||||||||||||||||||||*/

if ( daybyminute >= ((ontime * 60) + ramptime))
{
if ( daybyminute < ((ontime * 60) + ramptime + photoperiod ))
{
LightOn();
backlighton();
AtsOff();
analogWrite(blue, 255);
analogWrite(white, 255);

lcd.setCursor(0, 0);
lcd.write(6);
lcd.write(7);
lcd.setCursor(18, 0);
lcd.write(6);
lcd.write(7);
lcd.setCursor(0, 3);
lcd.print("24V");
lcd.setCursor(13, 1);
lcd.print(99);
lcd.setCursor(18, 1);
lcd.print(99);

lcd.setCursor(6, 1);
lcd.print(" ");
}
}

/*||||||||||||||||||||||||||||||||||||||||||||| F A D E O U T |||||||||||||||||||||||||||||||||||||||||*/

if ( daybyminute >= ((ontime * 60) + photoperiod + ramptime))

{
if ( daybyminute < (ontime * 60) + photoperiod + (ramptime *2) )
{
LightOn();
backlighton();

lcd.setCursor(0, 0);
lcd.write(2);
lcd.write(3);
lcd.setCursor(18, 0);
lcd.write(2);
lcd.write(3);

for (int i = abc-1; i >= 0; i--)
{
analogWrite(blue, bluepercent[i]);
analogWrite(white, whitepercent[i]);

lcd.setCursor(13, 1);
lcd.print((bluepercent[i]*99)/255);
if (i < 10) lcd.print(" ");
lcd.setCursor(18, 1);
lcd.print((whitepercent[i]*99)/255);
if (i < 10) lcd.print(" ");

int countdown = ((rampdown*60)/abc); // calculates seconds to next step
while (countdown>0)
{
onesecond();
countdown--;

lcd.setCursor(6, 1);
if (countdown < 100) lcd.print ("0");
if (countdown < 10) lcd.print ("0");
lcd.print(countdown);
}
}
}
}


//*|||||||||||||||||||||||||||||||||||||||||||||||| Night Time ||||||||||||||||||||||||||||||||||||||||||||||*/

if (daybyminute >= (((ontime * 60) + photoperiod + (2 * ramptime))))
{
LightOff();
backlightoff();
AtsOn();

lcd.setCursor(0, 3);
lcd.print("24V");
lcd.setCursor(0, 0);
lcd.write(4);
lcd.write(5);
lcd.setCursor(18, 0);
lcd.write(4);
lcd.write(5);
lcd.setCursor(6, 1);
lcd.print(" ");
}
}
//*|||||||||||||||||||||||||||||||||||||||||||||||| T H E E N D ||||||||||||||||||||||||||||||||||||||||||*/

muda
04/16/2012, 02:48 PM
Massive reefer,
Part of code that you refer to is swiching my ats at defined time :)

11 oclock at this example.

jedidog1
04/16/2012, 08:37 PM
are you looking for a timer to just switch on and off at certain time ? if so i can post my sketch and maybe you can just copy my timer into yours

katchupoy
04/16/2012, 08:55 PM
Katchupoy, I glanced over your "original" sketch that you linked to above and I thought I would share something that I noticed. In your two relay functions, you use millis() to figure out how long your ph's have been on/off. I'm not sure if you have or even would notice this, but technicaly there is a bug here. Millis() returns the number of milliseconds since the arduino has been turned on/reset. Once this number gets so big, it will start back at zero. Thus, not making it reliable for keeping track of time. I think this starts back at zero every week or so ish. I didn't study the code long enough to figure out exactly what would happen, but it seems that their is a possibility that after it rolls over to zero, your powerheads may not turn on/off like you would want them to. Exspecially since you add that full second delay in your oneSecond() function. I'm not really sure why you need to pause for a second in that function, but thats a different topic. I would recommend using the time off of your RTC for this calculation instead of using millis, but if you are able to leave your controller on for 2 weeks + without seeing any issue, it might not be a big deal and I might just be being picky with code.

Hope you dont mind my observations.

Good point here... Thanks Massive.
So far no issues since i have everything on a mechanical timer. And it goes off for 15 minutes every 9:30 am. Just before the program begins at 10 am.

Haha, to be honest, I just got the whole sketch from a fellow reefer also (credit on the first part) then just added the relay function. When I was trying to add it, I was loosing sleep at that code just to put two together... and the code you are looking at is the best I can do, hahahaha... pathetic... But at least, I understand it the way it works now.

I can easily copy someones code, but the issue there is, i just copy it without understanding it. And i cant help others if i dont understand it.

Recently, our local Frys Electronics, started selling arduino clones, and they even have the barebone ones for 14 dollars. I think im going to buy one and build another controller so that I have something to play with while the other one is working.

Sometimes I want to help people here but I cant because i dont have anything to play with. So soon, I think I will buy another set of the parts needed to create another one.

..

katchupoy
04/16/2012, 08:59 PM
@Muda,

Question to Code Experts!
Can you really use pin 0 and 1??? I thought those are reserved for whatever arduino is using it for???

Also, your code is way above my understanding... Lol, sorry, I thought it is similar somehow from my original code. Wow...

katchupoy
04/16/2012, 09:08 PM
@Muda

See this is what im saying...

Can you put this code...

if (hour >= 11) // butu 14 val
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}

inside this code...
void AtsOn()
{
digitalWrite(ats, LOW);
lcd.setCursor(19, 3);
lcd.print("+");
}

void AtsOff()
{
digitalWrite(ats, HIGH);
lcd.setCursor(19, 3);
lcd.print("-");
}

so that the ATSON is inside this...
{
onesecond();
countdown--;

lcd.setCursor(6, 1);
if (countdown < 100) lcd.print ("0");
if (countdown < 10) lcd.print ("0");
lcd.print(countdown);
}

and i notice that it is already inside MAX?
if ( daybyminute >= ((ontime * 60) + ramptime))
{
if ( daybyminute < ((ontime * 60) + ramptime + photoperiod ))
{
LightOn();
backlighton();
AtsOff();
analogWrite(blue, 255);
analogWrite(white, 255);

so i believe it should be the same on all part of the loop...

Before the loop start
During ramp up
during max
during ramp down
and after the loop.

Hope this helps...

double check my orig sketch.... you will see the relay, before, during, noon, after, and when its done...

Hope this helps???


@Massive, is that even possible? am i making sense?

katchupoy
04/16/2012, 09:14 PM
are you looking for a timer to just switch on and off at certain time ? if so i can post my sketch and maybe you can just copy my timer into yours

Can we not use a simple mechanical timer? to make life simpler?
Hold on, what is ATS again? is that the scrubber?


I think i got it Muda... what if you do this? what will happen?
1) remove the AtsOff @ Max
2) and remove the AtsOn @ Nigh time

Let me know what happens... I believe, is that when it does this ramp up and down, it actually goes through the loop. But every time it goes through the loop then it goes here first...
if (hour >= 11) // butu 14 val
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}

Which is fine, but what creates the click of on and off relay is that you also defined it here....
/*||||||||||||||||||||||||||||||||||||||||||||||| M A X |||||||||||||||||||||||||||||||||||||||||||||*/

if ( daybyminute >= ((ontime * 60) + ramptime))
{
if ( daybyminute < ((ontime * 60) + ramptime + photoperiod ))
{
LightOn();
backlighton();
AtsOff();

and here....
//*|||||||||||||||||||||||||||||||||||||||||||||||| Night Time ||||||||||||||||||||||||||||||||||||||||||||||*/

if (daybyminute >= (((ontime * 60) + photoperiod + (2 * ramptime))))
{
LightOff();
backlightoff();
AtsOn();


thus creating the on and off clicking sound of the relay. Try removing these two and see what happens. So basically, you set your timer setting on here...
/*|||||||||||||||||||||||||||||||||||||||||||||||||||| ATS |||||||||||||||||||||||||||||||||||||||||||||||||*/
if (hour >= 11) // butu 14 val
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}

muda
04/16/2012, 11:43 PM
Katchupoy,

Thank you very much. Pins 1 and 2 are working no problems.
Part of code that appeared under MAX, I put it there after my ATS (scrubber ) was not switching off at any ramp period. When I put it there realy started clicking at the time when it should be on until time to of (all inside MAX loop only). Then I set time to 11 and all bad stopped. 11 is time when MAX starts. When time differs from 11, that difference is saluted with clicking relay. Hope now It is more clear.

I try all your suggestions and report back.

May be there is better way to program timers in to code. That is general question . And if elegant solution would be found , that would be very useful and simple enhancement for controller.

jedidog1
04/17/2012, 12:32 AM
muda try this see if it helps you out any



* ------------------------------
* 0 HEATER A0 FAN
* 1 ATS A1 24V
* 2 A2
* 3 MOON LED PWM A3
* 4 LCD A4 RTC
* 5 LCD PWM A5 RTC
* 6 LCD PWM
* 7 LCD
* 8 TEMP
* 9 BACKLTH PWM
* 10 LED PWM
* 11 LED PWM
* 12 LCD
* 13 LCD
* -------------------------------

**********************************************************************************/
#include
#include
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 // Set rtc
#include // initialize the library with the numbers of pins
#define ONE_WIRE_BUS 2 // Define the pin of the DS18B20

/*||||||||||||||||||| L E D D I M M I N G P A R T ||||||||||||||||||||||||||*/

int bluemin = 0 ; // minimmum dimming value of blue LEDs, range of 0-255
int bluemax = 255 ; // maximum dimming value of blue LEDs, range of 0-255
int whitemin = 0 ; // minimum dimming value of white LEDs, range of 0-255
int whitemax = 255 ; // maximum dimming value of white LEDs, range of 0-255
int photoperiod = 420 ; // amount of time array is on at full power in minutes
int ontime = 7 ; // when start photoperiod fade in
int ramptime = 240 ; // time for LEDs to dim on and off in minutes

/*||||||||||||||||||||||||||||||||| P I N ||||||||||||||||||||||||||||||||||||||*/

int blue = 11; // blue LEDs connected to digital pin 11 (pwm)
int white = 10; // white LEDs connected to digital pin 10 (pwm)

int fan = A0;
int ats = 1;
int heater = 0;
int light = A1;
int moon = 3;
int backlight = 9;

int iBlueIntensity; //declare the integer of blue intensity
float fBlueIntensity; //declare the floating point version of blue intensity

int bluepercent[] = { 0, 2, 3, 4, 5, 7, 11, 15, 26, 52, 78, 100, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255 };
int whitepercent[]= { 0, 0, 0, 0, 2, 3, 4, 8, 18, 40, 54, 75, 99, 110, 130, 155, 175, 200, 210, 230, 255, 255 };

int abc(sizeof(bluepercent)/sizeof(bluepercent[0]));

LiquidCrystal lcd(13,12,7,6,5,4); // initialize the library with the numbers of the interface pins

byte newChar[8] = { // Set up the custom icon saule leidzias ir kyla ( 0 ir 1 kyla) (2 ir 3 leidzias) (4 ir 5 menulis )
B01001,
B01001,
B00101,
B00101,
B10101,
B10111,
B01111,
B11111
};

byte newChar1[8] = {
B10010,
B10010,
B10100,
B10100,
B10101,
B11101,
B11110,
B11111
};
byte newChar2[8] = {
B11111,
B01111,
B10111,
B10101,
B00101,
B00101,
B01001,
B01001
};
byte newChar3[8] = {
B11111,
B11110,
B11101,
B10101,
B10100,
B10100,
B10010,
B10010
};
byte newChar4[8] = {
B00111,
B01110,
B11100,
B11000,
B11000,
B11100,
B01110,
B00111
};
byte newChar5[8] = {
B01010,
B10000,
B00010,
B01001,
B00100,
B10000,
B00100,
B10001
};
byte newChar6[8] = {
B01010,
B00100,
B00001,
B11011,
B00011,
B00001,
B01000,
B10010
};
byte newChar7[8] = {
B10010,
B00100,
B10000,
B11011,
B11000,
B10000,
B00010,
B01001
};

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.

/*||||||||||||||||||||||||||||||||||||||| R T C C L O C K D S 1 3 0 7 ||||||||||||||||||||||||||||||||||||*/

byte decToBcd(byte val) // Convert normal decimal numbers to binary coded decimal
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers
{
return ( (val/16*10) + (val%16) );
}
void setDateDs1307(byte second,
byte minute,
byte hour,
byte dayOfWeek,
byte dayOfMonth,
byte month,
byte year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f);
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}

/*|||||||||||||||||||||||||||||||||||| D E F I N E : B A C K L I G H T ||||||||||||||||||||||||||||||*/
void backlighton()
{
analogWrite(backlight, 200);
}
void backlightoff()
{
analogWrite(backlight, 25); // If too bright or dim adjust the value accordingly.
}
/*|||||||||||||||||||||||||||||||||| D E F I N E : L U N A R P H A S E ||||||||||||||||||||||||||||||*/

int moonPhase(int moonYear, int moonMonth, int moonDay)
{
int dayFromYear, dayFromMonth;
double julianDay;
int phase;

if (moonMonth < 3) //keep the month before march
{
moonYear--; //take away a year
moonMonth += 12; //add an extra 12 months (the year taken away from before)
}
++moonMonth;
dayFromYear = 365.25 * moonYear; //get days from current year
dayFromMonth = 30.6 * moonMonth; //get number of days from the current month
julianDay = dayFromYear + dayFromMonth + moonDay - 694039.09; //add them all
julianDay /= 29.53; //divide by the length of lunar cycle
phase = julianDay; //take integer part
julianDay -= phase; //get rid of the int part
phase = julianDay*8 + 0.5; //get it between 0-8 and round it by adding .5
phase = phase & 7; //get a number between 1-7
return phase; //1 == new moon, 4 == full moon
}
/*|||||||||||||||||||||||||||||||||||||||| D E F I N E : O N E S E C O N D ||||||||||||||||||||||||||||||*/

void onesecond() //function that runs once per second while program is running
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.setCursor(0, 1);
if(hour>0)
{
if(hour<=12)
{
lcd.print(hour, DEC);
}
else
{
lcd.print(hour, DEC);
}
}
else
{
lcd.print("12");
}
lcd.print(":");
if (minute < 10) {lcd.print("0");}
lcd.print(minute, DEC);
//lcd.print(":");
//if (second < 10) {lcd.print("0"); }
//lcd.print(second, DEC);
delay(1000);
}

/*|||||||||||||||||||||||||| D E F I N E : 24 V O N - O F |||||||||||||||||||||||||||||||||*/

void LightOn()
{
digitalWrite(light, HIGH);
lcd.setCursor(3, 3);
lcd.print("+");
}

void LightOff()
{
digitalWrite(light, LOW);
lcd.setCursor(3, 3);
lcd.print("-");
}
/*|||||||||||||||||||||||||| D E F I N E : A T S O N - O F |||||||||||||||||||||||||||||||||*/

// these arrays store timer data
// on hour, on minute, on second, off hour, off minute,off second, day of week [1-7 Sun>Sat, 8 = daily, 9 = weekends, 10 = weekdays], on/off (0 off 1 on)
int atstimer[9]= {0,0,0,0,0,0,8,0,0};

void checkatsTimer()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

if (atstimer[6]==8){
if (hour==atstimer[0] && minute==atstimer[1] && second==atstimer[2])
{digitalWrite(ats, HIGH);
lcd.setCursor(3,13);
lcd.print("ats");}
else{
lcd.setCursor(3,13);
lcd.print(" ");}

if (hour==atstimer[3] && minute==atstimer[4] && second==atstimer[5])
{digitalWrite(ats, LOW);
atstimer[8]=0;}
}
}





/*||||||||||||||||||||||||||||||||||||| S E T U P P I N ||||||||||||||||||||||||||||||||||||||||||||*/

void setup() {
pinMode(heater, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(light, OUTPUT);
pinMode(ats, OUTPUT);
pinMode(moon, OUTPUT);
pinMode(backlight, OUTPUT);

sensors.begin(); // Start up the DS18B20 Temp library

/*||||||||||||||||||||||||||||||| S E T U P - C L O C K ||||||||||||||||||||||||||||||||||||||||*/

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();

second = 00;
minute = 54;
hour = 13;
dayOfWeek = 6; // Sunday is 0
dayOfMonth = 14;
month = 04;
year = 12;

//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); // ******* set the clock *******

// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.

analogWrite(blue, bluemin);
analogWrite(white, whitemin);
lcd.createChar(0, newChar);
lcd.createChar(1, newChar1);
lcd.createChar(2, newChar2);
lcd.createChar(3, newChar3);
lcd.createChar(4, newChar4);
lcd.createChar(5, newChar5);
lcd.createChar(6, newChar6);
lcd.createChar(7, newChar7);
lcd.begin(20, 4);
//lcd.setCursor(0, 0);
//lcd.write(0);
//lcd.write(1);
lcd.setCursor(3, 0);
lcd.print("Jokubo koralai ");
//lcd.setCursor(18, 0);
//lcd.write(3);
//lcd.write(2);
lcd.setCursor(11, 1);
lcd.print("B:");
lcd.print(33*bluemin/85);
lcd.setCursor(16, 1);
lcd.print("W:");
lcd.print(33*whitemin/85);
lcd.setCursor(11, 2);
lcd.print("L: ");
lcd.setCursor(0, 2);
lcd.print("W: ");
lcd.setCursor(0, 3);
lcd.print("24V");
lcd.setCursor(5, 3);
lcd.print("Fan");
lcd.setCursor(11, 3);
lcd.print("Htr");
lcd.setCursor(16, 3);
lcd.print("Ats");
}



/*|||||||||||||||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@||||| L O O P |||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@||||||||||||||||||||||*/

void loop()
{
onesecond();
checkatsTimer();
/*||||||||||||||||||||||||||||||||||||||||||||||| L U N A R |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


float fSecond, fHour, fMinute; //turn the times read from the RTC into float for math ops
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; //declare variables to hold the times
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); //read the RTC times
int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
fSecond = (float) second; //sets fSecond as the float version of the integer second from the RTC
fMinute = (float) minute; //same as above, but for the minute
fHour = (float) hour; //ditto, but for the hour
int lunarCycle = moonPhase(year, month, dayOfMonth); //get a value for the lunar cycle

//--------MOON LED SETUP----------//

if ( ((hour == 7) && (minute < 00)) || (hour < 7))//Off at 730am.
{
fBlueIntensity = 255; //...then we want the blue LED at the max brightness (255)
}

else if (hour > 18) //&& (hour < 19)) // On at 5pm
{
fBlueIntensity = 255 * (((fHour - 16) + (fMinute / 59)) / 7); //...set intensity out of 255 based on time since 17:00
}
else
{
fBlueIntensity = 0;
}

//--------- Account for the moon cycle with the blue LEDs ---------//

if (lunarCycle == 0) //new moon
{
fBlueIntensity /= 2;
}
if ((lunarCycle == 1) || (lunarCycle == 7)) //cresent
{
fBlueIntensity /= 1.75 ;
}
if ((lunarCycle == 2) || (lunarCycle == 6)) //half moon
{
fBlueIntensity /= 1.5;
}
if ((lunarCycle == 3) || (lunarCycle == 5)) //gibbous
{
fBlueIntensity /= 1.25;
}

//full moon is full intensity


//----------FLOAT TO INT-------------//
iBlueIntensity = (int) fBlueIntensity;

//---prepare the intensities to be written to pin----//

if (iBlueIntensity < 0) //if the blue intensity is less then 0, set it to 0
{
iBlueIntensity = 0;
}
analogWrite(moon, iBlueIntensity);
delay(1000);

/*|||||||||||||||||||||||||||||||||||||||| T E M P E R A T U R E DS18B20 |||||||||||||||||||||||||||||||||||*/

sensors.requestTemperatures(); // Send the command to get temperatures
delay(750);
lcd.setCursor(13, 2);

float temp1=0, temp2=0;

temp1=sensors.getTempCByIndex(1);
lcd.print(sensors.getTempCByIndex(1));
lcd.print((char)223);
lcd.print("C");

lcd.setCursor(2, 2);

temp2=sensors.getTempCByIndex(0);
lcd.print(sensors.getTempCByIndex(0));
lcd.print((char)223);
lcd.print("C");

if ( (temp2) > 26.5)
{
digitalWrite(fan, HIGH);
lcd.setCursor(8, 3);
lcd.print("+");
}
else if ( (temp1) > 45)
{
digitalWrite(fan, HIGH);
lcd.setCursor(8,3);
lcd.print("+");
}
else if ((temp2) < 26.4)
{
digitalWrite(fan, LOW);
lcd.setCursor(8,3);
lcd.print("-");
}

if ( (temp2) < 24.3 )
{
digitalWrite(heater, HIGH);
lcd.setCursor(14,3);
lcd.print("+");
}
else if ( (temp2) > 24.6 )
{
digitalWrite(heater, LOW);
lcd.setCursor(14,3);
lcd.print("-");
}

/*|||||||||||||||||||||||||||||||||||||||||||||||||||| ATS |||||||||||||||||||||||||||||||||||||||||||||||||*/
/*if (hour >= 11) // butu 14 val
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}
*/
/*|||||||||||||||||||||||||||||||| R A M P T I M E C A L C U L A T I O N ||||||||||||||||||||||||||||||||*/


int rampup;
if (daybyminute >= (ontime*60))
rampup = (((ontime*60) + ramptime) - daybyminute);
else
rampup = ramptime;

int rampdown;
if (((ontime * 60) + photoperiod + ramptime) <= daybyminute)
rampdown = (((ontime*60) + photoperiod + 2*ramptime) - daybyminute);
else
rampdown = ramptime;

/*|||||||||||||||||||||||||||||||||||||||||| F A D E I N ||||||||||||||||||||||||||||||||||||||||||||||*/

if (daybyminute >= (ontime*60))
{ if (daybyminute < ((ontime*60) + ramptime))
{
LightOn();
backlighton();

lcd.setCursor(0, 0);
lcd.write(0);
lcd.write(1);
lcd.setCursor(18, 0);
lcd.write(0);
lcd.write(1);

int i;
for (int i = 0; i < abc; i++)
{
analogWrite(blue, bluepercent[i]);
analogWrite(white, whitepercent[i]);

lcd.setCursor(13, 1);
lcd.print((bluepercent[i]*99)/255);
if (i < 10) lcd.print(" ");

lcd.setCursor(18, 1);
lcd.print((whitepercent[i]*99)/255);
if (i < 10) lcd.print(" ");

int countdown = ((rampup*60)/abc);
while (countdown>0)
{
onesecond();
countdown--;

lcd.setCursor(6, 1);
if (countdown < 100) lcd.print ("0");
if (countdown < 10) lcd.print ("0");
lcd.print(countdown);
}
}
}
}

/*||||||||||||||||||||||||||||||||||||||||||||||| M A X |||||||||||||||||||||||||||||||||||||||||||||*/

if ( daybyminute >= ((ontime * 60) + ramptime))
{
if ( daybyminute < ((ontime * 60) + ramptime + photoperiod ))
{
LightOn();
backlighton();
//AtsOff();
analogWrite(blue, 255);
analogWrite(white, 255);

lcd.setCursor(0, 0);
lcd.write(6);
lcd.write(7);
lcd.setCursor(18, 0);
lcd.write(6);
lcd.write(7);
lcd.setCursor(0, 3);
lcd.print("24V");
lcd.setCursor(13, 1);
lcd.print(99);
lcd.setCursor(18, 1);
lcd.print(99);

lcd.setCursor(6, 1);
lcd.print(" ");
}
}

/*||||||||||||||||||||||||||||||||||||||||||||| F A D E O U T |||||||||||||||||||||||||||||||||||||||||*/

if ( daybyminute >= ((ontime * 60) + photoperiod + ramptime))

{
if ( daybyminute < (ontime * 60) + photoperiod + (ramptime *2) )
{
LightOn();
backlighton();

lcd.setCursor(0, 0);
lcd.write(2);
lcd.write(3);
lcd.setCursor(18, 0);
lcd.write(2);
lcd.write(3);

for (int i = abc-1; i >= 0; i--)
{
analogWrite(blue, bluepercent[i]);
analogWrite(white, whitepercent[i]);

lcd.setCursor(13, 1);
lcd.print((bluepercent[i]*99)/255);
if (i < 10) lcd.print(" ");
lcd.setCursor(18, 1);
lcd.print((whitepercent[i]*99)/255);
if (i < 10) lcd.print(" ");

int countdown = ((rampdown*60)/abc); // calculates seconds to next step
while (countdown>0)
{
onesecond();
countdown--;

lcd.setCursor(6, 1);
if (countdown < 100) lcd.print ("0");
if (countdown < 10) lcd.print ("0");
lcd.print(countdown);
}
}
}
}


//*|||||||||||||||||||||||||||||||||||||||||||||||| Night Time ||||||||||||||||||||||||||||||||||||||||||||||*/

if (daybyminute >= (((ontime * 60) + photoperiod + (2 * ramptime))))
{
LightOff();
backlightoff();


lcd.setCursor(0, 3);
lcd.print("24V");
lcd.setCursor(0, 0);
lcd.write(4);
lcd.write(5);
lcd.setCursor(18, 0);
lcd.write(4);
lcd.write(5);
lcd.setCursor(6, 1);
lcd.print(" ");
}
}
//*|||||||||||||||||||||||||||||||||||||||||||||||| T H E E N D ||||||||||||||||||||||||||||||||||||||||||*/

jedidog1
04/17/2012, 12:40 AM
under ats on off just put in the array hour ,min,sec for ats on and then hour ,min,sec ats off in military time like this say i want the ats to come on at 1a.m and off at 6 a.m
1,0,0,6,0,0,8,0,0 the eight is for 8 daily you can also set it for weekends ony or weekdays only i tried to test it for you but i dont know my but i get allot of errors when i compile your sketch but just try it see if it works if not let me know im just know learning to code these things to so im a newb lol

muda
04/17/2012, 01:57 AM
Thanks jedidog.
Do I understand it right if I thing that we don't need to put timer function inside loop ?Just define in the setup and then it will be carried out all the time ? I thought this way arduino will set pin to state which is appropriate to startup time and then leave it unchanged until next arduino reset. Hmmm.

P.S. I got bunch of errors too. So cant check it works way I want at the moment.
P.S.S. Needed to delete all my ATS things , before get rid of errors.

MassiveReefer
04/17/2012, 06:57 AM
muda, can you please tell me in english when exactly you want the ATS on/off? Its sort of unclear how you have it coded. To me it seems like it is happening because you are trying to turn it on/off in more than one location. If it were me, I would have on function called handleATS(). This one function would do all of the calulations to figure out when it should be on/off. That way, within your loop, at any point within the loop, you can call handleATS() and it will do it for you. I'm at work so i didn't try to figure out all of your timing logic, but certainly seems to be because you are turning it on/off in multiple places which isn't good coding practice. It would really help if you laid out when you want it off/on, but this is something i noticed. You have
if (hour >= 11) // butu 14 val
{
if ( hour < 23) AtsOff();
}
else
{
AtsOn();
}

But my guess is you want something like this:
if ((hour >= 11) and ( hour <= 23)){
AtsOff();
}else{
AtsOn();
}
Although knowing when you want it on/off would help.

muda
04/17/2012, 08:05 AM
I want it on once, when DT lights go of or so. But "off" time must be changeable. I must have chance to play with it. And it can happen anywhere in the loop.

So no I dont need it at multiple locations at all. I just messed things up after sketch messed my brain first.
Seems like my main problem is not knowing where in the sketch I have to locate this part of code and second one - how loop works.

Apologies for my english as it is not my first and even second language.

MassiveReefer
04/17/2012, 09:53 AM
When you say you want to "play with the timing", which do you mean:
1. you want to adjust the the on/off time of the lights, but the on/off of the ATS will always come on/off with the lights?
2. Or do you mean you want the lights on/off to always be the same, and you just want to adjust the on/off of the ATS?

MassiveReefer
04/17/2012, 11:49 AM
Also muda, what do you mean you dont understand "how the loop works"? Do you mean you dont understand what the code within the loop is doing, or that you dont understand just the basic concept of the loop in general?

MassiveReefer
04/17/2012, 12:04 PM
And it goes off for 15 minutes every 9:30 am. Just before the program begins at 10 am.
....
Recently, our local Frys Electronics, started selling arduino clones, and they even have the barebone ones for 14 dollars. I think im going to buy one and build another controller so that I have something to play with while the other one is working.
..

You mean you have a mechanical timer shut it off for 15 mins every day? If so, why do you do that? That would take care fo the Millis() issue however :)

I really want to start building my own arduinos as well. I would like at least one to test like you had said, but I would also like a bunch more to make cool little gadgets around the house. I have been wanting to buy all of the supplies in bulk, say buy 25-50 of everything and then split the cost with people, but I don't know anyone else how is into electronics. :( This would also be a lot better for building a large project all on one pcb instead of having 10 different boards(RTC, Arduino, LCD, different packs, power supplies, etc)

Make sure you do your research on those barebone arduinos however(not that its a big blow to the wallet but....). There are a couple of different types of models out there, so I dont know what one exactly you are looking at, but a lot of the barebones dont have the chip to connect to it through usb. Then you need to buy a serial adaptor, and if you are only going to buy one of these barebones it really defeats the purpose of buying the barebones arduino. The processor on these arduinos can only accept serial data so there is another chip on the uno's and others that convert usb data to serial.

MassiveReefer
04/17/2012, 03:07 PM
The problem i am having is...


-Did you ever solve your LCD/Relay problem? If not:
-Did you ever check your amps at all at the relavent locations?
-Do you have flyback diodes on each of your relays?

If you dont, this could also possibly be the issue? I'm not sure if you need these with op-iso replays or not. Any input from any electronics gurus?

For anyone who doesnt know what a flyback diode is here is a good explination, Its on the second page:
http://www.physics.unlv.edu/~bill/PHYS483/relay.pdf
These should be used an all relays/motors(including pc fans)

katchupoy
04/17/2012, 04:19 PM
Massive, I believe the 8 relays that Bmahlie have has a built in flyback diode already.

katchupoy
04/17/2012, 04:28 PM
@Bmahlie

How many amps do you have for your relay 5v power supply?
Also how many volts and amps do you have for your arduino power supply?

did you read about the note on how to do optical isolation?

NOTES: If you want complete optical isolation, connect "Vcc" to Arduino +5 volts but do NOT connect Arduino Ground. Remove the Vcc to JD-Vcc jumper. Connect a separate +5 supply to "JD-Vcc" and board Gnd. This will supply power to the transistor drivers and relay coils.

If relay isolation is enough for your application, connect Arduino +5 and Gnd, and leave Vcc to JD-Vcc jumper in place.

Also read this please... (http://arduino-info.wikispaces.com/ArduinoPower#4-8)

It says each relay draws 80 ma... i believe arduino can only do 40 ma? so maybe you need to go to the optical isolation route?

muda
04/18/2012, 02:21 AM
Massive,

I need (and want) all lights and relays to be controllabe independently. Like I would have mechanical timers inside arduino.
What I do not understand about loop is if arduino stops doing one job when it is stuck doing another. Say if it is dimming lights will it continue follow temp probe ? Or for that to happen we need temp probe part include in light dimming function ?
I understand we have sketch of 4 parts : up, max, down, nigh. I thing this is complete loop. Other idea that comes to my mind is that arduino reads over all sketch constantly and decides what to do and what to skip.

katchupoy
04/18/2012, 08:46 AM
@muda
try to learn and google, "blink without delay" that might help?

MassiveReefer
04/18/2012, 10:24 AM
The loop is very basic. Its like reading a book strait through. You start and the top, read line one, and then move to the next line. Very simple. The arduino only has one processor, so it can only process one thing at a time. This was true of all computers untill only the last 5-10 years where they introduced "multi core" processors... anyway...

First, this loop happens(unless you put unnessisary "delay(int)" all over your code) many many times a second. Way more than you can even imagine.
Second, when you do something like set your lights to a given value, that value will stay their when you are checking your probe. It will forever stay there untill you change the value at that pin, so this is not a problem.

If however your code ever gets "stuck" doing one thing such as checking your probe, this is a MAJOR problem!!! This would be concidered a bug. If you had a code statement like this:
If (1=1){
digitalWrite(1,HIGH)
}
This would get "stuck" and is called an infinate loop. This once again is very bad, becasue one the code gets to the if statement, it will never leave becasue 1 always equals 1.

And NO, you should NEVER combine unrelated logic like putting temp probe logic with your light probe.... EVER! Well writen code should look something like this:

unsigned long AtsOnTime = 9AM
unsigned long AtsOffTime = 9PM

loop(){
adjustLights();
printTemp();
handleATS()
}

adjustLights(){
//all of your logic to adjust lights should go here
//If there is logic for when the ATS goes on this would be bad in your case since you want them independent
}

printTemp(){
temp = getTemp();
LCD.print(temp);
}

handleATS(){
If(CurrentTime >=AtsOnTime and currentTime < AtsOffTime ){
AtsOn();
}else{
AtsOff();
}
Then you would just change your global variables (AtsOnTime andAtsOffTime ) to adjust the time "independantly"
}

When your code gets to line one of the loop, it will set the lights to the correct value. When it gets to line 2, your lights value will stay they way it is, and it will then print the temp to the lcd. At line three, once agian, your lights will stat at the same value, your lcd will keep the printed temp, and then it will set the ATS on/off accordingly. After that, it will do it all over again. Without any "delay()"'s in the code, it would probably do this 100 times a second or something.

Does that make sense? If not let me know. I would recomend following katchupoys suggestion and play around with all of the easy demo sketchs first. Wiring up a simple led and figuring out how to get it to blink will really help you out. learning the difference between digital, analog, pwm, input/output(reading/writing) is really the way to go. I played with my arduino for about 1-2 months before I even attempted working with my project and I would concider myself advanced at coding. Its a lot easier to play around with those simple sketches to figure things out instead of jumping into a large project where you are following someone elses overly complicated code.

muda
04/18/2012, 11:23 AM
Thanks guys , this is such a joy hanging on this forum where I can feel others helping hand.
That was exactly what I needed. Now I feel much better looking over sketch.
I have played with easy demos. But was not sure how many things combine in to single game. Now my eyes are open .
Thanks one more time.

Now new question . What is best way to run some process for several seconds (dosing comes to my mind) and not to brake whole code? Is that what catchupoy suggests - use milllis ?

TheFishMan65
04/18/2012, 12:25 PM
If (1=1){
digitalWrite(1,HIGH)
}
For the record (and avoid confusion later) that is not an infinite loop. It will do the write every time it hits the set of commands and then continue to the next line.

Infinite loops need a 'while' or 'for' such as
while (1 == 1)
{
digitalWrite(1,HIGH)
}
or
for (i = 0; i < 5; ) // notice i is not incremented
{
digitalWrite(1,HIGH)
}

muda
04/18/2012, 02:11 PM
Honestly I didnt doubted first example . But now its clear. Ha ha ha.

MassiveReefer
04/18/2012, 02:54 PM
oops, whats what I ment! Sorry

MassiveReefer
04/18/2012, 02:58 PM
Now new question . What is best way to run some process for several seconds (dosing comes to my mind) and not to brake whole code? Is that what catchupoy suggests - use milllis ?

delay(1000) will delay for 1 second, delay(5000) will delay for 5 seconds... etc

so you would do something like:

void doseTank(){
turnOnPump();
delay(2000);
turnOffPump();
}

If you are new to coding, I would be very careful with this though. One small bug and you will wind up with one big mess and a lot of dead animals.

jedidog1
04/18/2012, 05:04 PM
I recommend this site http://www.arduino.cc/ it has help me allot

muda
04/19/2012, 02:00 AM
so you would do something like:

void doseTank(){
turnOnPump();
delay(2000);
turnOffPump();
}


That part is very clear. As I understand this way controller will hang on this part for delay time and not continue reading along code for 100 times per sec ?
I also need look for the right time to start pump with a seconds precision. What is right way to do that ? Does this works :

if (hour =2) {turnONpump}

Does it looks for minutes and seconds automatically ? Or compares only hours and will continue for whole hour until 3 o'clock ? I thing I need something like :

if (timeOf day =2:00:00) // what is right way for that ?

TheFishMan65
04/19/2012, 08:47 AM
I think you will need
if ((hour == 2) && (min == 0) && (sec == 0))
{
// do something
}

katchupoy
04/19/2012, 09:00 AM
to all arduino experts, thanks for backing me up here, and for helping muda.

quick questions for the experts, is there such a thing as virtual arduino so I don't have to buy an actual one Nd just play my code in my desktop? Complete with devices attached or close to it? And free ones of course?

MassiveReefer
04/19/2012, 10:06 AM
quick questions for the experts, is there such a thing as virtual arduino so I don't have to buy an actual one Nd just play my code in my desktop? Complete with devices attached or close to it? And free ones of course?

http://www.virtualbreadboard.com/

The app is not free now however.

Once again, I'm at work so i dont have a lot of time to look into this, but i would really be interested in setting this up as well. Since arduino is really its own language(its a mix of c/c++/java), this website claims its hard to write something to match it exactly. It seems like you wont be able to simply copy and past code from arduino to vitual arduino, although I am yet to figure out the differences. We could start a new page for this.

It looks relitivly easy though. Seems like you just have to wrap your arduino code around a class(I'm guessing a java class maybe?).

Man I wish my days were 30 hours long!

MassiveReefer
04/19/2012, 10:18 AM
What I would truly love, and this topic just got my thinking about it, is a debugger for arduino. I would LOVE if I could step through my code one line at a time to debug everything instead of having to print random things to my lcd to figure out what is going on. You dont realize how nice Visual Studio 2010 is untill you dont have it thats for sure!

MassiveReefer
04/19/2012, 10:33 AM
Just found this, this is AWESOME!!!
http://www.youtube.com/watch?v=UgRGq9O6YXg&NR=1&feature=endscreen

The guy in the video says you might be able to use it as a simulator. I will need to check this out more when i have more time. I really really want to create my own pcb's, and this seems like a super easy way to do it.

bmahlie
04/19/2012, 06:37 PM
Sorry for the delay in my responses, I am in the process of buying a house, and the sellers are being a real pain.

How many amps do you have for your relay 5v power supply?
Also how many volts and amps do you have for your arduino power supply?

did you read about the note on how to do optical isolation?

NOTES: If you want complete optical isolation, connect "Vcc" to Arduino +5 volts but do NOT connect Arduino Ground. Remove the Vcc to JD-Vcc jumper. Connect a separate +5 supply to "JD-Vcc" and board Gnd. This will supply power to the transistor drivers and relay coils.

If relay isolation is enough for your application, connect Arduino +5 and Gnd, and leave Vcc to JD-Vcc jumper in place.

Also read this please... (http://arduino-info.wikispaces.com/ArduinoPower#4-8)

It says each relay draws 80 ma... i believe arduino can only do 40 ma? so maybe you need to go to the optical isolation route?

"Also how many volts and amps do you have for your arduino power supply?"

I am using a cell phone charger to power the relays, 5v DC 1000 mA


"did you read about the note on how to do optical isolation?...It says each relay draws 80 ma... i believe arduino can only do 40 ma? so maybe you need to go to the optical isolation route?"

Yes, I have it connected under the "optical isolation" method.... i have a separate wall wart powering the relays with no connection to the Arduino ground. The "jumper" is removed as well.


"Also read this please..."

it took me a little bit to figure this out, but i did include it in my setup function.

Here is a copy of my code. (https://www.dropbox.com/s/01ec6ca0ztax6c7/Fishy_Controller_3_1.ino)[/I]

It similar to the original code but i have restructured a lot of it. I Took care the the millis() becoming to large for an INT issue as well. Also, sorry that the commenting is not always correct, i am pretty lazy about updating it. i can go through it this weekend and update it.



For anyone who doesnt know what a flyback diode is here is a good -Did you ever solve your LCD/Relay problem? If not:
-Did you ever check your amps at all at the relavent locations?
-Do you have flyback diodes on each of your relays?

If you dont, this could also possibly be the issue? I'm not sure if you need these with op-iso replays or not. Any input from any electronics gurus?
explination, Its on the second page:
http://www.physics.unlv.edu/~bill/PHYS483/relay.pdf
These should be used an all relays/motors(including pc fans)

"-Did you ever solve your LCD/Relay problem? "

Sadly no.

" -Did you ever check your amps at all at the relavent locations?"

Yes, everything seems to be alright. i believe it only happens when the relays switch.


"-Do you have flyback diodes on each of your relays?"

Yes, as katchupoy mentioned, the 8 relay board i have comes with them.


"If you dont, this could also possibly be the issue? I'm not sure if you need these with op-iso replays or not. Any input from any electronics gurus?"

I do have a few electronic engineers friends. i am going to try to draw up a schematic to show them when i get a chance.

jedidog1
04/19/2012, 07:46 PM
Just found this, this is AWESOME!!!
http://www.youtube.com/watch?v=UgRGq9O6YXg&NR=1&feature=endscreen

The guy in the video says you might be able to use it as a simulator. I will need to check this out more when i have more time. I really really want to create my own pcb's, and this seems like a super easy way to do it.

try eagle at http://www.cadsoftusa.com/ a bit of a learning curve as im still learning to use it but i have used it couple times to make things like my led drivers

MassiveReefer
04/20/2012, 10:17 AM
try eagle at http://www.cadsoftusa.com/ a bit of a learning curve as im still learning to use it but i have used it couple times to make things like my led drivers

Is it sort of like that video where you create a schematic and it lays it out a PCB for you? That seems like a really cool feature.

Also, did you print your board yourself or did you send away for it? If i ever buld another fixture, i will certainly want to build my own. I hate the limitations of the meanwell drivers. (I do however feel saver using their drivers with $200ish of LED's :blown:)

MassiveReefer
04/20/2012, 11:32 AM
Katchupoy, earlier you talked about wanted another cheap arduino. Check this out:
http://www.solarbotics.com/product/kardw/
You would still need to to buy the USB-to-TTL FTDI-type cable for another $15. The thing is, you only need on cable for all of these boards. Thus you make a one time buy of $15 for the cable, and then every arduino is only $10. I think the only thing it is missing is the regulator. Also, it uses a resonator in stead of a crystal so i dont think the timing is as accurate? Just a thought, knew you were looking...

jedidog1
04/20/2012, 07:46 PM
Is it sort of like that video where you create a schematic and it lays it out a PCB for you? That seems like a really cool feature.

Also, did you print your board yourself or did you send away for it? If i ever buld another fixture, i will certainly want to build my own. I hate the limitations of the meanwell drivers. (I do however feel saver using their drivers with $200ish of LED's :blown:)

i made my own pcb their not very pro but they work i just didn't want to wait 2 weeks to get them back from the pcb shops , basically all i did was print the circuit out on some sticker paper put in on the board then cut out around the traces with a razes knife then etched it , there are better ways of doing it but i just used what i had on hand.

crazyreef09
04/20/2012, 09:49 PM
katchupoy, thanks for the idea about the loop

My temps were froze at 185 after i pluged it back in from adding more cords.

this is what i did.




void loop()
{
onesecond();
relay2();
relay1();
sensors.getTempFByIndex(0); // I added this in the LOOP

so far it works, but if it don't, i think it is on the right track

So Dan_Cochran, did that fix the temperature freezing problem? Thanks.

muda
04/21/2012, 01:47 AM
Masive,

Regarding home brew PCB I have some experience. If you dont know yet, there is special black oily marker that you simply draw your layout on copper side. Then you put board in special chemical (FeCl as I remember) and after 20 mins or so you have ready made pcb. Its super easy for single sided PCB.

fish220
04/21/2012, 09:45 AM
I ordered an Arduino Uno, RTC, 48 CREE LED kit from rapidled, because of this thread. Can't wait to start playing with the arduino! Having no prior experience with this platform, I will surely reference this thread quite a bit. Thanks all for posting such depth of info on here.

Now I need to order 2 heatsinks. Will be covering my 24x24 60 gal, I went with 1:1 CW:RB and 60 degree optics. Ideally, I would like the light about 12-14" above the tank, without having much overshoot into the room. Anyone have any feedback on this?

Atc5016
04/21/2012, 04:34 PM
Ok guys, thanks for your help to this point I do have another issue I am hoping you can help me out with. I have my Arduino Uno, a 16x2 LCD and a DS1307 breakout kit from Adafruit. I have everything wired correctly and I get a readout on my LCD but It sticks at 12:00:00 am and wont count or sync to the time I adjust under the Setup-Display part of Katchupoy's code. I do have the SDA to pin 4 and SCL to pin 5 on the analog in on my arduino. I also double checked all my solder points on my breakout kit and found i am getting 3.1v to the proper pin of the RTC. I am wondering if the watch crystal is bad?

Not sure if it matters but I am using arduino software v23 on a apple snow leopard machine.

Bezz
04/22/2012, 08:02 AM
Hi guys,

I need some help on getting rid of the delay in the code for PWM ramping up.
I pulled this code off arduino.org


{
for (int i=0; i <= 255; i++){
analogWrite(pwmPin, i);
delay(100);
}


It gets the job done, but everytime when this part of the sketch is running the whole controller comes to a standstill till this code is excuted.

Anyway to have the controller continue running while running this code?

Thank

Patzig
04/22/2012, 11:00 AM
Atc - If you are getting a 12 am reading, the rtc is running and the uno is reading a value from it. If you have tried to set the clock via a sketch, then I don't think it worked. Maybe try to upload that code again to get the rtc kick started. I know that on arduino 1.0, its just a one line command that sets the clock to whatever time it was uploaded at (pulls the time from the computer).
Sent from my Samsung Galaxy s2

katchupoy
04/22/2012, 04:03 PM
Just found this, this is AWESOME!!!
http://www.youtube.com/watch?v=UgRGq9O6YXg&NR=1&feature=endscreen

The guy in the video says you might be able to use it as a simulator. I will need to check this out more when i have more time. I really really want to create my own pcb's, and this seems like a super easy way to do it.


Haha, this is amazing! Very graphic and user friendly... you can even export it to eagle file... or do your own pcb..... print it and make pcd yourself...

Amazing.... thank you....

MassiveReefer
04/22/2012, 09:15 PM
i made my own pcb their not very pro but they work i just didn't want to wait 2 weeks to get them back from the pcb shops , basically all i did was print the circuit out on some sticker paper put in on the board then cut out around the traces with a razes knife then etched it , there are better ways of doing it but i just used what i had on hand.

So yo only relied on scarping it off? Was it hard? Could you post a picture?

MassiveReefer
04/22/2012, 09:19 PM
Then you put board in special chemical (FeCl as I remember) and after 20 mins or so you have ready made pcb. Its super easy for single sided PCB.

I did see some videos on this on youtube. I was a little sketched out with all of the chemicals. I have a very curious dog and live in a rather small appartment. After one PCB board do you dispose of the chemicals right away? Can you Save it and use it again? Also, how do you dispose of it when the time comes?

MassiveReefer
04/22/2012, 09:26 PM
I ordered an Arduino Uno, RTC, 48 CREE LED kit from rapidled, because of this thread. Can't wait to start playing with the arduino! Having no prior experience with this platform, I will surely reference this thread quite a bit. Thanks all for posting such depth of info on here.

Now I need to order 2 heatsinks. Will be covering my 24x24 60 gal, I went with 1:1 CW:RB and 60 degree optics. Ideally, I would like the light about 12-14" above the tank, without having much overshoot into the room. Anyone have any feedback on this?

Hey Fish,

Sounds like your on track for a cool project. :thumbsup::thumbsup: Thats a somewhat small space for that many of leds. There shouldn't be any problem, but I wouldn't skimp on the heat sinks. I dont use optics because my leds are right on top of my tank. As for the mean well drivers(if thats what you got) be warned that the pot on the inside is super cheap and it only turns like 3/4 of a turn. Dont over turn it or it will break and your lights will go on super bright(to bright). Do you have any coding or electrical experience?

Welcome to the project and have fun!

MassiveReefer
04/22/2012, 09:38 PM
Hi guys,

I need some help on getting rid of the delay in the code for PWM ramping up.
I pulled this code off arduino.org


{
for (int i=0; i <= 255; i++){
analogWrite(pwmPin, i);
delay(100);
}


What does the rest of your code look like? Are you using someone elses sketch or writing your own?

Your issue is that you are handling all of your lights ramp up logic you one for statement. A "for" statement is a loop that will continue to loop until the condition (int i=0; i <= 255; i++) is no longer met. Thus you are saying turn up the light, wait turn up the light, wait, turn up..... untill i = 256, then it will stop.

Do you have a RTC?

your logic should be something like this:

If (start of ramp time <= current time <= end of ramp time){
write logic here to set your light. Dont use a loop. just do some math to figure out what PWM value the lights should be at given the current time and then set them.
}else if ( daylight on time <= current time <= daylight off time){
Set lights to max. Again use no looping statement.
}else if ( start ramp down <= current time <= end ramp down{
Logic for ramp down.
}else{
turn off lights
}


Make sense?

MassiveReefer
04/22/2012, 09:43 PM
Haha, this is amazing! Very graphic and user friendly... you can even export it to eagle file... or do your own pcb..... print it and make pcd yourself...

Amazing.... thank you....

It seems like it use to be free. Now I think its like $30. Do you plan to buy it? If you do, you will have to share your thoughts as to if it is worth it. I'm skeptical that it will be really buggy and more of a pain in the *** than its really worth. It would be cool however to build a general circuit design file to share. I think we all generally have the same setup? Once again, I'm still waiting to find something to debug code! If anyone finds a debugger, let me know!

omartinez
04/23/2012, 01:10 PM
can someone help me out with a basic sketch

I need to test my arduino prototype and leds...I just need basic ramp up and down, no rtc, lcd or anything else. I just have a bare atmega working (just uploaded a basic blink test) on the breadboard and the leds connected to a cat driver.

I've a lot of experience with programming but this is my first with arduino coding, i'm a fast learner but need some example to get started

fish220
04/23/2012, 06:53 PM
Hey Fish,

Sounds like your on track for a cool project. :thumbsup::thumbsup: Thats a somewhat small space for that many of leds. There shouldn't be any problem, but I wouldn't skimp on the heat sinks. I dont use optics because my leds are right on top of my tank. As for the mean well drivers(if thats what you got) be warned that the pot on the inside is super cheap and it only turns like 3/4 of a turn. Dont over turn it or it will break and your lights will go on super bright(to bright). Do you have any coding or electrical experience?

Welcome to the project and have fun!

Thanks for the welcome. I have experience with vb .net, and various database scripting languages namely. I have 0 experience with arduino but with the resources here I am sure it will be doable :thumbsup:
As far as the LEDs, well RapidLED sure is quick! They showed up today. I was able to find 3/4" C channel @ Home Depot this past weekend. I cut it to 12" lengths, and picked up a 90 degree 48" aluminum piece to hold it together. Once I saw all the strips next to each other, it was clear that making it 24"X12" to cover my 24x24 cube was not a great move. So instead, I am thinking of starting the strips 3" from each side, effectively spacing it to fill 18"x12" or so.
Now I am starting to think 36 LEDs (6 on each six12" strips of c channel) is the way to go. Since I have 24 CW and 24 RB in hand, anyone have any last minute input on what ratio i should go for? Tank will be a mixed reef, sps, softies, clows, etc.

I did pick up the Meanwell 48P's. Thanks for the warning!

MassiveReefer
04/23/2012, 11:14 PM
I've a lot of experience with programming but this is my first with arduino coding, i'm a fast learner but need some example to get started

If you have a lot of coding experience this should be all you need:
http://arduino.cc/en/Reference/HomePage
http://arduino.cc/en/Reference/Libraries

I learned Arduinos API over an hour lunch break at work one day. Is a basicly a mix of c/c++ code. I use c++ and the two pages I posted for any info I need. Once you get that going, I got all of the rest of my components from adafruit.com. The have a ton of tutorials for each of their products.

focus on the digitalWrite() functions dealing with PWM and you should be good to go.

MassiveReefer
04/23/2012, 11:27 PM
\ anyone have any last minute input on what ratio i should go for? Tank will be a mixed reef, sps, softies, clows, etc.

I did pick up the Meanwell 48P's. Thanks for the warning!

Do you think you are going to like the idea of a "Night mode" where after hours, you can turn on your lights a very dim blue color? If so this is one thing I would recommend. You didnt specify what LED's you got, so I'll make it genaric. Each meanwell driver has a max and min number of lights you can put on it. I would max one driver out. For the leds I used I could use a max of 14 LED's and a min of 8 LED's. You are most likely going to need 4 drivers correct? In your cenario i would put 14 on one channel and 10 on another. Then the string of 14 I would turn up the most, and turn the string of 10 a little lower. Then when you want your night lights on, turn off the string of 14 and use the string of 10 for it.

Just my 2 cents.

Also, keep me updated on the temp of those c channels. I am guessing they are going to get pretty hot. Do you have a good fan plan in mind?

muda
04/24/2012, 02:07 AM
I did see some videos on this on youtube. I was a little sketched out with all of the chemicals. I have a very curious dog and live in a rather small appartment. After one PCB board do you dispose of the chemicals right away? Can you Save it and use it again? Also, how do you dispose of it when the time comes?

After use you close tightly and keep it untill you need it again.
After this chemical is not effective to each boards it is not harmless anymore too. There is water and some precipitated salt in it. So you just get rid of it.

omartinez
04/24/2012, 06:29 AM
thanks...i already reading that links....

where can i download the code for this proyect?

MassiveReefer
04/24/2012, 08:07 AM
I just figured out how to control the D type controllers through PWM which seems to be the safe way(having the driver not actually recieve a PWM signal), although I dont have any D's so I did not look far into it. If anyone is interested let me know and I can try to explain.

bmahlie
04/24/2012, 05:22 PM
I just figured out how to control the D type controllers through PWM which seems to be the safe way(having the driver not actually recieve a PWM signal), although I dont have any D's so I did not look far into it. If anyone is interested let me know and I can try to explain.

I am using the d type drivers. What did you figure out?

MassiveReefer
04/25/2012, 10:33 AM
Long story short, you replace the pnp transistor with a digital to analog converter IC. Its most likely going to require a little bit of rewireing however. Instead of using the transistor as an on off switch, you use the digital to analog converter to convert the pwm value to an analog signal. I think the key is going to be finding the correct converter. It will have to have a range from 0-10v and accept a 5v pwm input. Thats all I know for now.

wardda
04/30/2012, 11:52 AM
Hello,

Has anyone run into this issue? I'm running my controller with two channels one for white and one for blue. I also have a temp sensor and clock setup with the config. I have everything wired up on a breadboard sharing one 5v line from the controller and one ground from the controller. I'm also using a 10v wall wart to supply power to the transistors for the pwm signal and the controller. I'm running 4 meanwell 60-48P's, 2 for the whites and 2 for the blues.

If I run just the white it ramps up, runs at flat rate, and ramps down just fine. If I run just the blue same result. I have a sketch that will allow both white and blue to ramp at the same time at different rates. If I run both, then the blue ramps up just fine (I have that starting an hour sooner than the white.) Then when the white starts up it will lock up the controller. I have put in debug code and it locks at random points.

Also if I pull the 10v power supply from the transistors but keep it connected to the controller it runs the program just fine. So it is just when both transistors are powered at the same time. They share the same ground and same power...

So I'm assuming it has something to do with sharing the single 5v and ground... any thoughts.... ?

Panagiotis07
04/30/2012, 12:05 PM
Hello,

Has anyone run into this issue? I'm running my controller with two channels one for white and one for blue. I also have a temp sensor and clock setup with the config. I have everything wired up on a breadboard sharing one 5v line from the controller and one ground from the controller. I'm also using a 10v wall wart to supply power to the transistors for the pwm signal and the controller.

If I run just the white it ramps up, runs at flat rate, and ramps down just fine. If I run just the blue same result. I have a sketch that will allow both white and blue to ramp at the same time at different rates. If I run both, then the blue ramps up just fine (I have that starting an hour sooner than the white.) Then when the white starts up it will lock up the controller. I have put in debug code and it locks at random points.

Also if I pull the 10v power supply from the transistors but keep it connected to the controller it runs the program just fine. So it is just when both transistors are powered at the same time. They share the same ground and same power...

So I'm assuming it has something to do with sharing the single 5v and ground... any thoughts.... ?


I 'm trying to do the same thing with no luck..:worried:

wardda
04/30/2012, 01:37 PM
Also, I have mounted my LCD 20x4 about 12 cable feet away from the controller. Is this ok for it to be this far away and then also what gauge cable do I need to use for this?

And is it possible to go too thick of wire? I have left over speaker wire that is like 14 gauge ....

Dan

muda
05/01/2012, 07:14 AM
warda ,

can you make drawing of how you try to connect all. I am not sure I understand.
Or do you use one of kachupoy's schematic ?

Regarding LCD. You dont need big wires. Thinnest you have will work. But my guess is you need shielded cable to protect from different interference at that distance. I have some interference at less than 10 inch distance, exeptionally when relays and pumps start and stop.

wardda
05/01/2012, 01:34 PM
What would the impact of interference be? I'm currently using cat 6 network cable for power transmission from drivers to leds soldering two wires together so I have 4 wires instead of 8, kachupoy did that as well. I also did the same thing to connect my LCD to my controller.... I'm wondering if this could be my issue?

muda
05/01/2012, 03:05 PM
LCD will go crazy. Screen converts to hieroglyphs . I have posted about this problem earlier on thread. This is not 100% likely. Possibly not all LCD schields are sensitive to the same level. Leds are not sensitive to any interference, so you are free to choose any cable you like.

MassiveReefer
05/02/2012, 10:35 AM
So I'm assuming it has something to do with sharing the single 5v and ground... any thoughts.... ?

As muda said, a simple drawing of your wiring would go a long way.

Im guessing your have two transistors? One for blues and one for whites. 10V coming in to the transistor and two wires running out, one to each driver?

If so, have you tried hooking up just one driver to each transistor as see if that works? That might help you rule some things out.

MassiveReefer
05/03/2012, 03:22 PM
To add what I wrote yesterday. If you do only wire up one driver to each transistor and it works, then it would lead me to believe that it is a wiring problem, however, if that does not work... well it could be a code or wiring issue still. Are you using Katchupoy's sketch? Sorry there are to many people on here now to keep track of who is using what sketch.

michael_in_nc
05/07/2012, 08:55 PM
Long story short, you replace the pnp transistor with a digital to analog converter IC. Its most likely going to require a little bit of rewireing however. Instead of using the transistor as an on off switch, you use the digital to analog converter to convert the pwm value to an analog signal. I think the key is going to be finding the correct converter. It will have to have a range from 0-10v and accept a 5v pwm input. Thats all I know for now.

No, DAC will not take PWM. PWM is essentially a DAC output already. The PWM signal can be 'filtered' to produce a DC output, in this case, 0-5v if the Arduino has 5v PWM outputs. Problem is that signal levels are not correct (you don't have enough gain). You need to use a simple amplifier to translate the signal levels up to be correct, and filter them to prevent the square wave PWM input into the dimmer control. The arduino is about 400Hz on the PWM, so you need a bandwidth of no more than about 40Hz to get reasonable 'ripple' on the output, probably even lower. The only disadvantage to running lower bandwidth is the response time to dimmer control is slower, but this is still very fast relative to our measure of time.

You can use this circuit to provide the gain. The amplifier is any simple op-amp pretty much. An LM358 or similar. You will need a 12v supply, but those are easy to obtain and you'd need that no matter what to supply power to the dimmer port. In this case, we need the resistor ratio (gain) to be 2:1 to gain up from 5v to 10v. The input RC circuit acts as the filter to attenuate the ripple in the PWM output to get a (mostly) DC output at the amplifier output.

https://lh6.googleusercontent.com/-Qaqgc24AzJE/T6iKaitDf7I/AAAAAAAAAhA/vEjxwuAqZ2k/s912/pwm_to_dimmer.jpg

wardda
05/08/2012, 07:15 AM
Muda,

You nailed it!! I swapped out the 12' of cat6 cable to the LCD and replaced it with shielded 18/4 security cable and it works like a champ. I was surprised as I would have expected the LCD to just display junk with the interference not to lock up the entire controller... but it works great now.

Thank you,
Dan

warda ,

can you make drawing of how you try to connect all. I am not sure I understand.
Or do you use one of kachupoy's schematic ?

Regarding LCD. You dont need big wires. Thinnest you have will work. But my guess is you need shielded cable to protect from different interference at that distance. I have some interference at less than 10 inch distance, exeptionally when relays and pumps start and stop.

muda
05/14/2012, 08:11 AM
Glad to hear it helped Dan !

:)

ladybugs
05/14/2012, 11:49 PM
I like this thread, easy to undertand.

Just want to know is somebody already can input the time for ramp in & out without reskecth.

Thanks

MassiveReefer
05/15/2012, 07:56 AM
Just want to know is somebody already can input the time for ramp in & out without reskecth.
Thanks

Do you mean change the ramp time on an lcd or something? Yes, this is possible. I dont have this in code, but i have it so i can change the max of both white and blue using my lcd. This way, when i get new corals, i can set my lights lower to acclimate them to the lights. Everyone acclimates things to temp, salinity etc but never to light and corals are very sensitive to changes in light if they are put into light that is a lot brighter than where they were coming from.

Set the time is definatly possible. I would recomend reading my comments before about creating a menu through lcd. Pretty much have a menu item called changed on time or something like that. Then when enter is selected, read up and down buttons to change the hours, then when enter is selected again move to the mins.

Make sense?

I didnt put the time into my menu because i never change the on/off time(neither does the sun :) ). Its totally possible, and easy if you understand how to create a menu. If you need help, I wrote some about this in the previous couple of pages.

ladybugs
05/15/2012, 09:22 AM
Thanks MassiveReefer. I will see your script.

Actually i don't really understand how to create a menu. So i need help to create it.

Actually i want make a controller that i can key in or save the time or everything at controller unit so i don't need to change or load the script every time i change the number.

Hope u understand what i'm write sorry for poor english

bioreefdude
05/17/2012, 07:45 PM
sorry guys i have everything hooked up and i upload the original sketch and my blues r going on and off like every 60 secs HELP

katchupoy
05/17/2012, 11:13 PM
bioreef, triple check the pin assignments. For some reason you have it o. Pins for wave timer??

Panagiotis07
05/22/2012, 01:40 PM
has anyone managed to start fading in the whites while blues are already fading ?

thnx

MassiveReefer
05/24/2012, 11:00 AM
I have a question for any electronics experts...

As mentioned before, i would like to control SRV2 through the arduino so i can have better control of dimming. I have a couple basic thoughts and was wondering if any of these roughts seems fesible, or even if you guys have any better suggestions.

Thought 1:
Replace the pot with two sets of two resistors to create a voltage devider. Since the pot is 1k, both resistors would just need to add up to 1k correct? Then i could just have two sets of two resistors, and switch between the two with a multiplexer? Would this work? Is there any concerns with this? I'm pretty sure the multiplexer has a bit of resistance, so i am assuming that i would have to take that into consideration when figuring out my resistance values.

Thought 2:
Replace SRV2 with a digi pot. The biggest issue with this is finding the correct IC. First and formost, i need a through hole design, and this really limits down my options. I cannot find a 1k digi pot, but i can find a 10k digi pot. Can i swap the 1k for a 10k and then just ensure that the max resistence between v+ and the wiper is 1k? Thus having a 9k resistence from the wiper to v-. Is that equivalent?

Thought 3:
Is it possible that the pot is not being used as a voltage devider and instead being used as just a single resistor between v+ and the wiper? If so, i could do something along the lines of my first thought, but wouldnt need to use two pair of resistors, i would just need two resistors. Is there a way for me to figure out if it is being used as a voltage devider or just a resistor?

Any other thoughts on how i can change SRV2 from the Arduino??? If i could get a wide range of possible values to select from for SRV2 that would be great, but if I can even simple switch between two values I would be satisfied.

Any help is greatly appreciated! If i make a go at anything, I will surely let everyone know how it goes, but as of now, I dont think i know enough to start it.

TheFishMan65
05/24/2012, 11:25 AM
T1 - maybe but the time it takes to switch may cause issues. Spikes which cause lock ups or may have momentary full on of off.

T2 - yes, but you need to make sure that you get a true digital pot. I looked at these a while back and looking at the internal configuration very few were actually acted as a pot. IIRC the other behaved as a voltage divider - without knowing the meanwell circuit I don't know if these would work. Which one are you thinking of using?

T3 - look at the schematic (probably not available :)). Are there traces to all three leads (multilayer board and you won't be able to tell), if so where do they go?

Out of curiosity, is this a P or D and why not use that control?

michael_in_nc
05/24/2012, 08:56 PM
I have a question for any electronics experts...

As mentioned before, i would like to control SRV2 through the arduino so i can have better control of dimming. I have a couple basic thoughts and was wondering if any of these roughts seems fesible, or even if you guys have any better suggestions.

Thought 1:
Replace the pot with two sets of two resistors to create a voltage devider. Since the pot is 1k, both resistors would just need to add up to 1k correct? Then i could just have two sets of two resistors, and switch between the two with a multiplexer? Would this work? Is there any concerns with this? I'm pretty sure the multiplexer has a bit of resistance, so i am assuming that i would have to take that into consideration when figuring out my resistance values.

Thought 2:
Replace SRV2 with a digi pot. The biggest issue with this is finding the correct IC. First and formost, i need a through hole design, and this really limits down my options. I cannot find a 1k digi pot, but i can find a 10k digi pot. Can i swap the 1k for a 10k and then just ensure that the max resistence between v+ and the wiper is 1k? Thus having a 9k resistence from the wiper to v-. Is that equivalent?

Thought 3:
Is it possible that the pot is not being used as a voltage devider and instead being used as just a single resistor between v+ and the wiper? If so, i could do something along the lines of my first thought, but wouldnt need to use two pair of resistors, i would just need two resistors. Is there a way for me to figure out if it is being used as a voltage devider or just a resistor?

Any other thoughts on how i can change SRV2 from the Arduino??? If i could get a wide range of possible values to select from for SRV2 that would be great, but if I can even simple switch between two values I would be satisfied.

Any help is greatly appreciated! If i make a go at anything, I will surely let everyone know how it goes, but as of now, I dont think i know enough to start it.

I agree with TheFishMan...

I'm assuming you're talking about a MeanWell driver? If so, the SRV2 only shows -25% to +3% range. Why do you need to adjust that? If you have the 'D' or 'P' model, then you can just use that port to perform the dimming with much better range. The arduino can easily interface to those ports. Not sure on the levels for the 'P' model, but the 'D' model can be interfaced with the circuit I posted above. Do you have a different model with dimming?

muda
05/25/2012, 02:26 AM
has anyone managed to start fading in the whites while blues are already fading ?

thnx

I have

See my version of sketch page or two ago.

MassiveReefer
05/25/2012, 07:21 AM
Currently, i have everything wired up(p version of meanwell), fully running my own sketch and am very happy with my lights. The only thing i hate about them is the range in which i can dim them. If i run my leds at about 400-500 mA(with PWM=255) the tank is blue enough for me for the day time, but when it comes to night time, when i turn my blues to the lowest they can go without turning off, they look WAY to blue. Unnatrually blue. Its so bright that my fish stay out, my corals dont close up, and frankly it looks horable in my opinion for moonlights. The P version of the meanwell drivers can only get down to like 20% brightness i think before it shuts off? That number is probably wrong, but I know it cant get even close to 1% without turning off.

If however, i run my blues at about 200 mA(with PWM maxed at 255) the blues are not enough for me during the daytime. They do however look GREAT for moon lights. If you run your lights at a lower max mA, you are able to dim the lights down a lot more.

That is the main reason i want to be able to change SRV2. I understand i could just add another string of blues just for moonlights, but i dont really want to go that rought since i already have everything build, wired and finished up.

Another reason that i would really like to be able to change SRV2 through the arduino is so that when my lights go from the lowest PWM value that they can(for me i think its 27) before they shut off, the next step down in PWM to 26 obviously turns them off. Since they go from being so bright to fully off, its not a smooth transition by any means and all of my fish instantly scatter. I know it doesnt do any harm to the fish, but I just hate how it looks. Night time is when I watch the tank because its when I'm not working. :)

If i could replace it with a digi pot, that would be the best becasue i could really have full controll of the lights brightness at all times. But if i cannot get a digi pot to work, and i could get the two pair of two resistors and a switch working that would still be good enough for me.

Michael - what did you mean by "the SRV2 only shows -25% to +3% range"?

The digi pot i was thinking about is something like this:
http://www.mouser.com/ProductDetail/Maxim-Integrated-Products/DS18030-010+/?qs=0Y9aZN%252bMVCU2vlKjgWdNExANgUwRbGs3N2037cij%2fPU%3d

It says its serial 2-wire. I'm not sure if that is the same and I2c. When i set the filter on mouser for I2C digi pots there is no through hole chips, and i need to through hole design because of limited soldering skills. They seem to use the same data and clock lines, but I'm not sure if they are the same thing. Any thoughts?

TheFishMan65
05/25/2012, 09:46 AM
I think the easiest solution is to get a night job :).

The rating from the ELN-60-48 D datasheet says SVR2 can be adjusted to -25 to +3% or 1.3 *.75 to 1.3 *1.03 or .975 amps to 1.34 amps. I have no idea if we are damaging the ELN if it is run outside of those ranges - note that you are trying to do this. Anyone?

Assuming it can be run out side of that range. You need to determine where the ends of the current pot are going. The one you listed does not come in 1k. If it is just a voltage divider the 10k would work (wiper till goes between x and y voltages). But if it is important that the ends are a 1K drop, then you would be out of luck. Such as they have a 60 volt supply and want a 0 - 10 volt signal. They have a 5k in series before the pot so the output is 0-10. If you place a 10k there the output would be 0-40 and maybe something would fry.

You sure you have ELN Ps? I am surprised they don't have full range.

michael_in_nc
05/25/2012, 01:47 PM
I agree with TheFishMan, the d/s says there is limited range for adjustment if you use SRV2. only -25% to +3%. So, I don't think this will fix your problem. What if you do it manually to test it out? Set your blue lights to the brightness value you want for day, then dim them to max (just before they shut off) and then adjust SRV2 to the min and see if it fixes the dimming issue. If it does, then you could try and figure out how to control it, but if not then it's kind of a waste of time? I wouldn't try to push it beyond the d/s rated range. You could damage your driver.

MassiveReefer
05/25/2012, 02:26 PM
I think the easiest solution is to get a night job :).

The rating from the ELN-60-48 D datasheet says SVR2 can be adjusted to -25 to +3% or 1.3 *.75 to 1.3 *1.03 or .975 amps to 1.34 amps. I have no idea if we are damaging the ELN if it is run outside of those ranges - note that you are trying to do this. Anyone?

Assuming it can be run out side of that range. You need to determine where the ends of the current pot are going. The one you listed does not come in 1k. If it is just a voltage divider the 10k would work (wiper till goes between x and y voltages). But if it is important that the ends are a 1K drop, then you would be out of luck. Such as they have a 60 volt supply and want a 0 - 10 volt signal. They have a 5k in series before the pot so the output is 0-10. If you place a 10k there the output would be 0-40 and maybe something would fry.

You sure you have ELN Ps? I am surprised they don't have full range.

I am possitive i have the p's. I researched the project for like 6 months before i built it. :crazy1: I still dont get what the percentage is that you two are talking about. -25 to 3 percent of what? Are you implying that anyone that is not running ".975 amps to 1.34 amps" through their leds is ruining their drivers??? That would be news to me.

I contacted meanwell about this and they got back to me about adding a 10k pot. They said that as long as i dont adjust the 10k pot above 1k i will be fine. Guess i just have to make sure i hook the posts up correctly.

MassiveReefer
05/25/2012, 02:38 PM
What if you do it manually to test it out? Set your blue lights to the brightness value you want for day, then dim them to max (just before they shut off) and then adjust SRV2 to the min and see if it fixes the dimming issue. If it does, then you could try and figure out how to control it, but if not then it's kind of a waste of time? I wouldn't try to push it beyond the d/s rated range. You could damage your driver.

I think I have done what you are concidering "manual"? Are you saying I should do the following?

1. Set Pwm value to max.
2. Turn SRV2 up until I am satisfied with the amount of blue during the daytime.
3. Set Pwm value to the lowest value before they turn off.
4. Turn SRV2 down until I am happy with the amount of blue during the night time.

Then, if i can achieve both #2 and #4 then you are saying a digi pot would work? If so, i have deffinatly done it. When my PWM is maxed and my mA's are around 500 i am happy for the daytime. When my pwm is maxed and my mA's are at 200, then I change my pwm to be the smallest it can be, I am then happy with the night time blues(Sounds depressing! ha). Thus the reason i would like to change the pot through the arduino.

michael_in_nc
05/25/2012, 03:40 PM
I think I have done what you are concidering "manual"? Are you saying I should do the following?

1. Set Pwm value to max.
2. Turn SRV2 up until I am satisfied with the amount of blue during the daytime.
3. Set Pwm value to the lowest value before they turn off.
4. Turn SRV2 down until I am happy with the amount of blue during the night time.

Then, if i can achieve both #2 and #4 then you are saying a digi pot would work? If so, i have deffinatly done it. When my PWM is maxed and my mA's are around 500 i am happy for the daytime. When my pwm is maxed and my mA's are at 200, then I change my pwm to be the smallest it can be, I am then happy with the night time blues(Sounds depressing! ha). Thus the reason i would like to change the pot through the arduino.

Ok, then you should have enough range. The -25% to +3% is the adjustment range of the output current via SRV2. I suspect the reason that Meanwell says do not go above 1k on the resistor is that the control loop in the driver can only handle certain voltage outputs. That is, the driver is constant current, but there is some max and min voltage output that it can create to achieve the constant current. If you use SRV2 beyond it's intended range, it may break the control loop.

mikez104
06/07/2012, 02:04 PM
subscribed

mikez104
06/07/2012, 08:51 PM
Ok, I have been out of the hobby for years and just a few months ago started playing around with the Arduino Uno. I started to bring my tanks back up to speed and started looking and the LEDs and I found this thread. I read through the first 20~25 pages and amvery interested in this project.

So I downloaded the original code from the google caddnima site and also loaded up the libraries from there. I tried to compile and got a few errors. Could someone throw me a bone? Not sure what the issue is. Here is the error.

In file included from sketch_jun07a.cpp:16:
C:\Users\Mike\Desktop\arduino-1.0\libraries\LiquidCrystal/LiquidCrystal.h:82: error: conflicting return type specified for 'virtual void LiquidCrystal::write(uint8_t)'
C:\Users\Mike\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

wgraham
06/08/2012, 05:23 AM
you need to use version 22

mikez104
06/08/2012, 06:14 AM
Yeah, I tried to compile some of the other sketches and was running into errors with them also so i downloaded 0023 and it compiled ok. What happened in version 1.0? Not backwards compatible?

wgraham
06/08/2012, 06:43 AM
a lot of the coding has change so the old codes are not compatible, you have to go and change some of the wording

mikez104
06/08/2012, 06:50 AM
If I stick with a pre 1.0 version i should be ok? What abouut new library files? Do they have the potential of screwing up the older code?

rrasco
06/08/2012, 10:48 AM
I have not been able to read through all the posts yet, been skimming through for a few days now, but can someone point me to a sketch that has the whites/blues ramp up smoother than the 10% increments? I know a few people said they have done it, but I need some code to reference while I write my sketch. Also, I was curious if anyone has code where the intensity of the LEDs is limited, it looks like most sketches ramp up to 100%, or are people limiting the intensity with a pot?

muda
06/08/2012, 03:04 PM
If you look at my version - there is posibility to change dimming the way you like. You can make any count of step and any size. You can dim blues and whites parallel or one after another . It is couple pages above.

RonnyTheReefer
06/09/2012, 05:16 AM
Hi guys!!

At first: AWESOME WORK @ ALL!!!!!
Special thanks to katchupoy,Reefninja,Liquidart and Muda.
I ve read this thread from beginning till now.
But still got some trouble in my sketch.
Iīm using a modified version of Mudas Sketch.
And the problem is: Temperature is freezing during dim-in and dim-out.
Muda solved this problem but donīt tell how.
Please help!!
Thanks

Greetings Ronny

muda
06/09/2012, 06:17 AM
Hmm I dont remember temperature freezing. Or possibly I not even noticed that.
So how can I remember how I fixed ....zzzz.....
:D
I wish I am younger...

RonnyTheReefer
06/09/2012, 12:08 PM
@ Muda: ooops.....sorry,thought you was that

i remember to have read that..... the age...:headwalls:

Perhaps anybody else can help me....



Greetings Ronny

mikez104
06/09/2012, 12:32 PM
Getting ready to order my ELN-60-48P drivers and looking for a connection schematic. The only ones I have seen here seem to be for the ELN-60-48D like back in post 294. Do you connect the P driver in the same way?

RonnyTheReefer
06/09/2012, 01:35 PM
You can connect the P Driver directly to the Arduino.
Without Transistors.

mikez104
06/09/2012, 01:39 PM
Well that's easy. I guess that why theres no diagram.:)

Thanks

MassiveReefer
06/10/2012, 09:19 AM
You can connect the P Driver directly to the Arduino.
Without Transistors.

This is 100% not true!!!! You need to use the PWM of the arduino and that outputs 5V and the p's need 10V. You NEED a transistor. Read the whole thread! You will find that you need to hook them up the same. There are a couple ways to do it, but the input on the P needs to be 10V.

If you only hook it up to the arduino, the lights will not turn on.

mikez104
06/10/2012, 10:12 AM
Ok, I think I get it. The D version will get brighter as the voltage gets closer to 10v and the P version is looking for a 10V signal and as the duty cycle gets closer to 100%, the LEDs get brighter.

MassiveReefer
06/10/2012, 11:42 AM
Ok, I think I get it. The D version will get brighter as the voltage gets closer to 10v and the P version is looking for a 10V signal and as the duty cycle gets closer to 100%, the LEDs get brighter.

bingo

RonnyTheReefer
06/10/2012, 01:16 PM
Sorry guys,i missunderstood the Data Sheet .
http://www.meanwell.com/search/eln-60/default.htm
Thought for the P-Driver 5 V will be enough.
Just wanted to order some of these,but in case is senseless when i will also
need Transistors. So i go with the D-Drivers.

Greets Ronny