DIY Reef Controller

Here's the outlet screen.

549467_153671111468525_1071190931_n.jpg
 
Drew,

Relay activity as in the state of each relay or how I am telling each relay to be on or off with the shift register?

Rott,

I was hoping someone might like the Tardis.
 
Drew,

Relay activity as in the state of each relay or how I am telling each relay to be on or off with the shift register?

Rott,

I was hoping someone might like the Tardis.

Mainly the first part. But if youre using the 595s I'd be interested in knowing that too :)
 
Drew,

I am just using a byte array with 16 spots. When the code checks for any of the conditions that would cause an outlet to change it checks the type of outlet first, (timer, temp, ato, etc.) than checks whether the outlet should be on or off.

The method loops through all 16 of the outlets this way resulting in a byte array of 16 that contains the current states of the relays.

It then calls another method that splits the 16 variables in the array into two individual bytes containing eight relay states each (using bitwise operators) and then shifts them out to the shift registers.

Code:
  void Update_Outlets(){
  
    byte Shift_Outlet1;                                                          //Integer to send to shift register
    byte Shift_Outlet2;                                                          //Second Integer to send to shift register
  
    for(int i = 0; i < 8; i++){                                                  //Convert first 8 outlet boolean values to a decimal
      Shift_Outlet1 += (Outlet_Settings[i].Status << i);
    }
  
    for(int k = 0; k < 8; k++){                                                  //Convert second 8 outlet boolean values to a decimal
      Shift_Outlet2 += (Outlet_Settings[k+8].Status << k);  
    }
  
  
    digitalWrite(Outlet_Data, LOW);                                              //Prepare the shift register for an update
    digitalWrite(Outlet_Clock, LOW);
  
    digitalWrite(Outlet_Latch, LOW);                                             //Write Data to the Shift Registers Storage Registers
    shiftOut(Outlet_Data, Outlet_Clock, MSBFIRST, Shift_Outlet1);                //Write Data
    shiftOut(Outlet_Data, Outlet_Clock, MSBFIRST, Shift_Outlet2);                //Write Data
    digitalWrite(Outlet_Latch, HIGH);                                            //Move data from the Storage Registers to the output
  
  }

Forgot to mention that I am also using a struct to keep all the outlet information together at the moment which is what Outlet_Settings.Status is. I still have to go through the code and optimize everything so this may change, haha.
 
Last edited:
Nice approach. Im trying to save pins by using this method. I've got my mega 2560 maxed out already :( if you could share the other parts of the code for relay control/shift registers that would be great as I'm trying to understand your logic for splitting the 16 byte array into two bytes. Which I assume is because the shift registers only output 8 pins but why not store in two seperate arrays? I'm not sure of the commands you're using to split the array etc either :) I use a very similar method for my 16relays at the moment but like I said...I've just gotten my shift registers in and I desperately need to free up some pins and the 595s are a perfect way to do this (especially for relay control). :) MUCH appreciated!
 
Last edited:
If you really need to save pins you can use an I2c port expander instead, just watch how long your cables from the mega to your outlet box is. I've read that 9-12ft is the limit of a standard use of the i2c bus.
 
Hi Nick
I am going to order the relay boards today. I was looking at the 2 different ones in the pictures you posted but I can't remember what they where going to trigger. I wanted to know because the SS ones are rated for only 2 amp and that isn't very much so I was hopeing you could tell me what they where for. the other ones are rated for 10A so that would be pumps ,power heads, etc

Dale
 
Yeah I'm going longer than that. That's my issue. So it's SPI or bust. Not trying to code jack. Just trying to save hours of me "trying to figure it out" lol. Either way is cool. I don't plan on distributing your code or anything but looking for your experience in my personal project :) PM me if needed.
 
Rott,

The SS relays are for smaller stuff like sump lights, fans, small powerhead whereas the 10A mechanical ones can run your heavy. You can get whatever you like I just went with one of each.

Drew,

I honestly don't care if you distribute my code as I am distributing it, haha.
I might be able to help more if you send me an email with what your trying to do exactly. nkd502 6 @ gmail
 
I didn't notice it before but that code block has some nice details about what the code is doing on each line. Will make it easy to set up diffrent stuff later down the line or to edit out things we might not use.
 
I've got a completed code for any w5100 Ethernet module. Anyone interested in individualized control of 16 relays? If so... I'll post it here.
 
Back
Top