More than 10 relays

Greetings All:

I am a complete noob at programming an Arduino. I searched the internet and found several pieces of code and advice on how to setup my device. Here's what I'm doing:

I'm using and Arduino Mega to control a Sainsmart 16 Channel Relay Board. I can get ten of them working just fine but I can't seem to get the other 6 to do anything at all. I have 12 volts supplied to the relay board and all of them switch properly when I move the pins around but I just can't seem to get the last 6 working in the sketch. Please help, and be easy on me, don't send me to school I'm looking for a quick way to get this done. School is an on-going process that I started a long time ago, I just can't get completely into this while studying to be an electrician. Thanks for everyones help and I hope you all have a great day.

Glenn

Test_Sketch.ino.ino (30.8 KB)

Not that pins 14-18 are your serial port pins ... are any of these being used for something else?

You have a lot of attached libraries (and peripherals?) ... SPI, Ethernet, eeprom, SD. Also, the opto LEDs would take about 5mA each x 16 = 80mA. I'm thinking your power supply has run out of available current.

Do the last 6 relays work on their own with other stuff disconnected?

Are you using 12V @ Vin? If so, lowering this to 7V-7.5V will increase the available current from
Mega's regulator.

EDIT: DO NOT CONNECT 5V FROM THE RELAY BOARD TO 5V ON THE MEGA. IT WILL BACKFEED AND CAUSE MULTIPLE ISSUES.

There's a problem with the 16 channel relay board in that its 5V circuit is connected throughout (on both sides of the opto isolators) so its not possible to use the isolation feature. If the 5V terminals are connected to the Arduino 5V, it will essentially parallel the supplies, so this should be avoided.

Hello and thanks for the quick response. I'll jump right into answering your questions:

  1. Pins 14-18 are not used, I used pins 2-9, 34 & 36, and 41-46
  2. The libraries are installed but not being used at present. The only LED's are on the boards (Arduino and relay) and I'm using a 12 volt power supply, don't have a lower voltage one at the moment.
  3. The last 6 relays do not work unless I put the pins into the first 6.

Thanks again for your help.

P.S. If you'd like to see the web page you can view and control it by going to http://24.154.99.20:8091
Note the last 6 seem to stay on all the time.

And another thing I should note, there is nothing connected to the relays so you can click all the buttons you'd like. I'm obviously still in the testing phase.

If you have 16 separate relays, I'd really suggest a couple of shift registers (either separate or chained) and something like a darlington array chip to drive the actual coils.

A shift register is like one byte of memory that you load up with bits by pushing them into the end. To switch a single bit, you need to push all 8 bits into it again, but this only takes a microsecond or so and the relays never notice. To do this, you need two pins: one to say 'this is the bit' and the other to say 'now push it in'. It's pretty simple.

You can chain any number of shift registers together, at the price of having to load all the bits each time you want to change one. This takes time, but 16 bits? Totally worth it. If the relays are "seeing" the bits flicker past as they are loaded (and honestly - they won't), you can get a pair of latching shift registers. These have two bytes of memory - one that you load with bits, and another that you dump those bits into as a single step with a pulse on another pin.

A darlington array is a chip with transistors on it wired up in pairs so that the final one is saturated hard on or off. A chip will have 7 or 8 of these pairs on it. They will handle a considerable amount of current, and the circuitry has diodes to deal with the inductance spikes that result from switching coils on and off. They are basically a sold-state relay in themselves, but one where the data input is safe to hook to a digital pin. You need relay for 240v, AC current, or heavy loads, but if you are switching 12v DC and not drawing a heavy current, you may not need relays at all.

These components will cost you 20 bucks, maybe. With shift registers driving the darlington pairs, and the darlington pairs driving the relays, you need two pins or three if you use latching registers. Some strip board, IC sockets, and a little solder and you're good to go.

Plus, it's expandable.

Thanks PaulMurrayCbr,

Could you point me to the parts and possible elaborate a little more please? I have never heard of these items since I'm not very good at doing this sort of thing. As I said before I compiled the sketch by piecing things together from other peoples projects on the internet. But what you're describing sounds good as long as I am able to do it. Thanks again for your help.

Glenn