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.
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.
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.