Pattern relay

Hi everybody, I'm new to this forum.
I'm planning a new project: I want to connect 12 relays (3 groups of 4) to Arduino and manage them both manually and automatically via BAUD_RATE (writing on the serial monitor). I'd like to write code strings in order any group creates a different rhythmic pattern. Please help me to write this code string. N.B. I'd like to connect any button of the keyboard to every single rhythmic pattern in order to turn on/off them when I want. Moreover, how can I electrically connect all the relays?
Thanks very much in advance
Seba :~

Hi everybody, I'm new to this forum.
I'm planning a new project: I want to connect 12 relays (3 groups of 4) to Arduino and manage them both manually and automatically via BAUD_RATE (writing on the serial monitor). I'd like to write code strings in order any group creates a different rhythmic pattern. Please help me to write this code string. N.B. I'd like to connect any button of the keyboard to every single rhythmic pattern in order to turn on/off them when I want. Moreover, how can I electrically connect all the relays?
Thanks very much in advance
Seba =(

Do you have a spec on these relays, and how fast are you planning to switch them?
Lets start with that.

Unless these are very small reed relays, you probably will not be able to drive them directly (40mA absolute limit on Arduino pins, 20mA max recommended).

You could purchase three quad-relay modules. These have built-in switching transistors and flyback diodes to prevent damage to the Arduino. Or you can create your own module(s) using the same protection principles. Add up the mA consumed by your relays though to make sure you're not exceeding the maximum 500mA an Arduino Uno can supply (for example, if you use twelve 5V relays and each coil draws 50mA each, you'll burn the Arduino if all are energized at the same time).

The Arduino has just enough pins to control 12 relays and still have a few pins left over.

As for coding the sketch, it sounds like you you want to map each letter/number of the PC keyboard typed in the Serial Monitor to a rhythmic pattern? If so, use arrays to define your patterns, use Serial.read() to capture the keystroke characters, a finally switch/case construct to start executing the pattern array associated with the keystroke character received.

Cross-posted topic merged.

Here's a 1284 board I did with 2 serial ports, one thru RS232 adapter, one thru USB adapter, that directly controlled 18 similar relays.
I had some simple code that sent a message in serially to turn one on at a time, but you could certainly drive as many as you wanted by adding a couple of buffer chips so the total current thru the uC isn't a factor.
(18 relays in the original design, 3 were removed just before the artwork went out for another connecter which didn't end up getting used).
http://www.crossroadsfencing.com/BobuinoRev17/