Serial Relay Board

I'm building a circuit and i don't have enough pins for the amount of relays I need to use. Right now, i really only need 4 relays but it may expand to many many more (prob no more than 8 or 16).

I can spare 2 pins for serial. I know exactly how I could design another arduino to do this job but i was wondering if there was already a pre-made circuit to do this.

bwahh, this may be too far confusing for a pre-made chip to do this. Maybe I'll just make it myself, but just wondering if anything exists.

Thanks again.

You could just use a shift register or 2, to add more digital outs and then put a suitable transistor on each pin to drive the realys.

With a few of Arduinos digital pins you could easily have 16 or more relays.

Can you write directly to a shift register?

Such as

0100

and

1110

instead of just shifting?

This is my first post- the forum won't allow a link within the first post. Look to my next one, I've seen something that may help.

Here it is, have a look at this board:

http://www.efx-tek.com/php/store/index.php?main_page=product_info&cPath=2&products_id=6

Pretty sure it's serial controlled. Hope it helps.

No you can not write directly to the register, they are serial in parallel out. So you would have to shift the date outone bit at a time.

Is that a problem for your application?

EDIT: the board linked in the previous post is serial, but its almost 30$ without the relays, rather expensive IMHO.

You can shift in from 1 to 8 bits at a time.

To control 8 relays you just need to keep a byte in memory containing the current state of each of the 8 relays. To turn one of the relays on or off just change that one bit and shift out the whole byte. You use the latch line on the shift register to allow you to shift in all 8 bits before applying the change to the output pins.

There are really good examples in the playground. This seems like a perfect project to control with a shift register.

The only issue I see is that you probably need to use the shift register to drive transistors which, in turn, drive the relays to supply enough current to close the relays.

The only issue I see is that you probably need to use the shift register to drive transistors which, in turn, drive the relays to supply enough current to close the relays.

This is true, but it would be an issue under all circumstances because the Arduino pins can not source enough current anyway.

I guess my project would be similar to home automation, but that's not what it's for. The Arduino gets user input on what devices to turn on and these devices are turn on by their respective relays. I don't want devices switching on when they're not supposed to be on. So I don't know if a shift register would work properly.

I know i'll need to use transistors, the relays are going to be 5v coils and they'll be switching 12v lines.

The RC-4 is exactly what i'm looking for but I can make my own with an extra Arduino chip for less than that.

I think i'll poke around some home automation projects and see how they did it.

Sorry, I guess I didn't make it clear. The shift register will not turn things on inadvertently.

If you have 8 relays attached to a shift register and want to turn them all off send value B00000000 to the shift register. Now to enable the first relay send B10000000. The output pins on the shift register do not change until after the last bit is shifted in (the shift register library takes care of the details) so only one relay is powered on. If you now send B10100000 the first relay remains on and the third relay is powered on.

As I said as long as you keep track of which relays are on and off you can turn the relays on and off individually by setting or resetting individual bits in this byte and shifting the result out.

Shift registers are dirt cheap. If you have a local source pick one up and use some LED's to play with it. You'll see how easy it would make your project.

The INTERNAL shift register status does not change the state of the output latches until the latch pin is set.

    digitalWrite(latchPin, 0);
    shiftOut(dataPin, clockPin, B00100000);
   ...
    digitalWrite(latchPin, 1);

While LATCH pin is 0, your relays won't change state.

So... you SHIFT seriall... stop shifting... enable the latches... and POOF> 1 external state change happens all at once across all thr outputs.

Wow, thanks. I guess shift registers are the way to do it.

EDIT

Removed messsage. I accidently answered to anoher message here.

Due to the nature of encoders... you might even consider using Interrupt versus polling code. That way you can "catch" a state change on the encoder input pins since if you miss one or two due to polling you would have sluggish or sloppy encoder input.