Arduino controller help please

Hello all!
I recently set up a new 55 gallon tank. With a DIY cedar stand, sump, base rock live sand, LED lighting(blue and white no dimmer). It is currently cycling. I just set up auto top off for it! :) Have some diatoms. So letting them stabilize things and waiting for them to go away. Figure since it was base rock, I am nearing the end of the cycle. (Tests will tell) Recently, I have decided to add in an open source DIY mini controller. A little history of myself; I used to run a traffic department for a municipality. Where the controllers for the intersections, worked very similar to an aquarium controller; timers, sensors, etc...
It was always nice because many manufacturers will provide free software. To assign pin operations, phases, etc. My dilemma is, I switched my operating system to linux! lol Most places only have windows based software. My experience was in the wireing and software, not the actual scripting. I now see how privileged I was, having drag and drop menus and enter a pin and a designation or what I wanted it to do. With the Linux, I do not think I will get that luxery with my aquarium. :) So I have been studying the Arduino system. I came up with the following basic script for lights and two steady on relays. I read Arduinos only can handle so many counts. If I set the millis down to say around 10 seconds. The script runs fine. For some reason as written, relay 2 will not turn back off. I am assuming it might be too long of a duration delay? Does anyone know a better way for this basic time schedule of relay 3&4 always on. Then relay1 on, an hour later, relay2 on, 8 hours later, relay 2 off, then an hour later, relay one off. Then I have it delayed for 14 hours to then repeat the loop indefinitely. The delays are in milli seconds. That is why the large numbers. I have an RTC and also read about blinking led for a schedual. Figured while I am researching it, I would ask here for some advice. Here is my script!!!!! Please check.
The original is an Arduino example, Then I completely changed it. Just starting on this type of stuff.... SOOOO I am a noobe! lol More than adequate experience for the wiring though.
Thank you in advance..
p.s. I included a couple pics of the hardware I have. Kind of hard to toss the wires in, before I am aware of possible conflicts and rules of scripts. ( I miss my old traffic software!lol)

/* Basic lighting and two extra outlets: Arduino Control
Handles "Relay is active-low" to assure
no relay activation from reset until
application is ready.

/*-----( Import needed libraries )-----*/
/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 3 // d3 on Arduino to relay#2 etc, etc,...
#define Relay_3 4
#define Relay_4 5

void setup() /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
digitalWrite(Relay_4, RELAY_OFF);


//---( THEN set pins as outputs )----
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_4, OUTPUT);

delay(4000); //Check that all relays are inactive at Reset
digitalWrite(Relay_3, RELAY_ON);// turns relay3 on
digitalWrite(Relay_4, RELAY_ON // turns relay4 on
delay(3000); //so a 3 second delay before lights on
}//--(end setup )---


void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//---( Turn blue and white led relays ON in sequence)---

digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
delay(3600000);
digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
delay(28800000);


//---( Turn white then blue leds OFF in sequence)---
digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
delay(3600000);
digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
delay(57600000);


}//--(end main loop )---
 

Attachments

  • 0306142014a.jpg
    0306142014a.jpg
    38.9 KB · Views: 9
I also noticed around the 8 hours later after coming back from my nieces birthday party, That there was some flicker in the indicating LEDs on the relay and mini controller. My connections are temporary at the moment and noticed one of my grounds where not attached the best.(but connected) Is it possible that was messing up the count? Then just retry the schedule? If there is no limit for delays? It was a sequenced blink though. Kind of like it may have reached a maximum count and had no reset. Then just kept blinking.
 
It would probably be easier to use different statements with an RTC or running a digital pin to an analog for a timer. Then be able to use different times for gathering data or triggering events. I am still new to Arduino though and starting with basics. So I understand, what I am building. That is why the loop I have. Would probably be easier to switch back to windows, but what is the fun in hobby with that? Switching back from Linux to windows is a whole other topic! lol exe. files ugh.
 
Doesn't help I copied and pasted the script wrong. lol I cut the delays back to 6 seconds and it works fine. so I'm going to try the one wire or rtc methods. so delays won't block other actions anyways. Any recommendations for good research links?
 
Might be because pin 3 is a pwm pin as well. I am going to switch pin2 to pin 7. Just to see if the pin # was the issue. Or maybe switch the pwm (pulses) on pin2 to 100% to see if that makes a difference in the millis and turning relay2 off. Supposedly the millis do not reset until 50 days. So up to 24 hours should not be an issue. I am only counting millis in delay. I will test it tomorrow and let people know, Incase anyone else does DIY controllers.
 
I think you want an RTC. I have an Arduino controlling the lights on my daughter's tank, with an RTC and display on the I2C interface. The RTC works well, but adds complexity. You might be exceeding the limit of the delay function, it isn't really designed around 8 hour time frames.
Also, your day is 26 hours long (1 hour delay, 8 hour delay, 1 hour delay, 16 hour delay)
 
Thank you for the response. I have an RTC, but have not wired it in yet. I might just have to go that route. I am trying to do a little bit at a time. So I understand the scripting behind it. I recently found the reference section, under help, in the Arduino software. So that I believe will be the best option to learn definitions to research and learn. I was able to get relay 1&3 up with no problem. Then relay 2 comes on with no problem. Now I got it to turn relay2 off at the desired delay. The only problem is relay 1&3 turned off for a second with it. Then came back on!!!!! lol Like you mentioned though, I might be exceeding the delays. If I have the delays set to less than a minute, the script runs great. Here is an updated, with what I tried. I limited it down to 3 relays. Basically relay3 is an outlet always on now. Then relay1&2 are the lights. I updated it to pin 7 instead of pin3 for my white lights(relay 2) Just incase a pulse current on pin 3 was there. Should not be, but.... lol Forgive the math on the delays. I have been hung up on problems when pin two turns off. I might toss on the RTC tomorrow.

#define RELAY_ON 0
#define RELAY_OFF 1

#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 7
#define Relay_3 4
void setup()
{
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);

delay(4000);
digitalWrite(Relay_3, RELAY_ON);
delay(5000);
}//--(end setup )---


void loop()
{

digitalWrite(Relay_1, RELAY_ON);
delay(1800000);
digitalWrite(Relay_2, RELAY_ON);
delay(14400000);
digitalWrite(Relay_2, RELAY_OFF);
delay(3600000);
digitalWrite(Relay_1, RELAY_OFF);
delay(43200000);
}
 
Last edited:
Basically the delays keep changing because I always end up constrained on time. Just tossing in numbers. So I can let it go, while doing other stuff. Then just check on it periodically. I plan on DIYing the entire project. Including making my own salinity probe and ph probe. I ended up putting a purchsed temperature control. Then put ATO on the sump. So I have stability in parameters. The nano controllers seem to be pretty temper mental. I might order a mega. That way the ethernet shield I have can just plug in. I just have a basic 16x2 display with buttons. that plugs into the ethernet shield. The nano controller, I need to make jumpers, instead of plug and script. I thaught the nano had a clock in.Then a script could make it display hour and min for timing. I thought that was why it could milli up to 50 days before reset. The 50 days might be for a count though.
 
Using the delay function is not worth the effort you are putting in, as the controller can do nothing else while that function is executing. You would be better served by writing a main loop that reads a time (either the RTC or the millis() function) and turns the lights on or off based on that, because you will have to do so eventually if you want to make this more useful than the cheapest timer.
Can't tell you why the various pins would turn off, your best bet is to research the Arduino site.
 
I hear ya. I did end up going to the arduino website. Someone mentioned tossing in a UL. Which I was able to research and got the thing to work!!!! Lol I fully understand the delays will need to go eventually. I was just surprised it wasn't handling the basic function of being a milli timer. Now that I have that working. My next part, will be wiring up the serial port. So I can monitor and record what happens when. then the rtc. The serial first, so I can see what is happening. Ill post the sketch that ended up working, when I get back to my computer. Until I figure out further sketches, I have it on a battery backup. So it will keep a schedule if power turns off.
 
Here is the sketch that worked. The milliseconds are still off because I was fighting power outages all day. So adjusted them to a lesser time. Now I fear the power outages might have messed up my board. I keep on getting a error message about the programmer. I might just order a different board, like the Arduino Mega. That is the one my Ethernet shield just plugs into any ways. I have been tempted to donate to that jarduino controller sketch. Just to make things easier, but I want to learn the stuff too. Plus I checked that software download out and it is a exe. file. I run Linux Ubuntu. The nano is just so small to try to do anything with. If I get it to accept uploads again. I might just use it to make a timer for my father in laws fantasy sports draft parties. Then get the Mega. I guess the first part of my sketch really wasn’t needed. Since I was turning a pull up resister off, when it does by default for the functions I had any ways.



#define RELAY_ON 0
#define RELAY_OFF 1

#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 7
#define Relay_3 4
void setup()
{
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);

delay(4000);
digitalWrite(Relay_3, RELAY_ON);
delay(5000);
}//--(end setup )---


void loop()
{

digitalWrite(Relay_1, RELAY_ON);
delay(3600000UL);
digitalWrite(Relay_2, RELAY_ON);
delay(3600000UL);
digitalWrite(Relay_2, RELAY_OFF);
delay(3600000UL);
digitalWrite(Relay_1, RELAY_OFF);
delay(57600000UL);
}
 
Does anyone think this would be a better base for a controller?
http://www.ebay.com/itm/280919073637
$T2eC16Z,%21%29UE9s3wDbWtBRe3Gdw,Nw%7E%7E60_14.JPG
(LCD display)
280931846454_2.jpg

http://www.ebay.com/itm/280931846454

I have an Ethernet shield that goes with the mega already.
That way I am not messing with the small nanos and trying to slave them for a couple extra pins. Would the sensor shield be o.k.? It says it can do motor control and I think the clips would be nice for some DIY ph probes and salinity probes, orp. ex....
I think , I would have plenty of extra pins for my 8 relay power strip.
 
http://www.ebay.com/itm/Ethernet-Sh...214?pt=LH_DefaultDomain_0&hash=item56618432fe
$%28KGrHqIOKpkFJs9z0uDbBSb3tge,M%21%7E%7E60_14.JPG


That is the ethernet shield I already have.
Then a 5v 8 relay strip for outlets.
Plus an extra 16x2 lcd with buttons, that has an i2c adapter.
Plus a ton of 1p-1p Dupont connectors.
2 x arduino nano 3.0 (need to figure out the fuses on them) Did an oopsy, that led to my next sentence. (wireing in dim lighting.)
AAAAAnd, I guess I need to make the stuff work. lol My wife just emailed me happy birthday and she went on my ebay. It is not my bday, but close enough.
Then a battery backup my mom gave me from her computer.
Already have a RTC.
Then my nieghbor gave me a pile of resistors, to sort out with the tester and use! I guess I have no choice, but to make it work :/
Wanted a bit of reassurance from people first, but I know the mega will work. Just not sure of the sensor shield? Any sensors I need to make. Should be basic parts at a local hobby store. Then youtube and internet research crazy, I guess.
 

Attachments

  • 0314140851.jpg
    0314140851.jpg
    44.7 KB · Views: 9
  • 0314140853a.jpg
    0314140853a.jpg
    50.2 KB · Views: 9
  • 0312141831a.jpg
    0312141831a.jpg
    57.9 KB · Views: 7
Plus, I found a website that is called cprogrammers.com ... It is by far the best resource I have found for learning the principle behind c++. Explained through tutorials. At least for myself, who is starting with basically zero coding skills.
 
Back
Top