Go Down

Topic: How to control 16 relays when running out of pins? (Read 5031 times) previous topic - next topic

guix

Sep 22, 2012, 06:16 am Last Edit: Sep 22, 2012, 06:25 am by guix Reason: 1
Hello :)

I plan to buy a 16 opto-isolated relays board from Sainsmart.

But, I run out of pins on the Arduino mega2560 (from Sainsmart too) because I have sensors, touchscreen, and sd card. In fact, I still haven't received my Arduino, I'm just anticipating!

Those relays will control lights, pump, fans, whatever... following a program depending of the sensors's values.

So I need a solution to control all of the 16 relays individually, not just one at a time, they could be all turned ON if necessary, or just few of them, or most of them...

I have read about multiplexers and shift registers, but I'm so much confused, I don't really understand both and I'm not even sure if one of them is a solution for me. In this tutorial they use a shift register and call it multiplexer, so I'm even more confused.

Help a newb' please :)



retrolefty

Have you used up all 16 of the analog pins also? I ask in case you weren't aware that they can be used as digital input or output pins also.

Lefty

guix

#2
Sep 22, 2012, 07:52 am Last Edit: Sep 22, 2012, 07:54 am by guix Reason: 1
I'm not sure yet, how many pins will be remaining once I plugged all sensors, touchscreen, real time clock, etc :D, in fact I would like to not run out of pins (when relays are connected) so I can extend my project by adding other sensors or whatever, at a later time. The damn touch screen is annoying, it uses 46 pins (including the sd card slot)...But I need it.


nickgammon

Example circuit and code here for controlling multiple LEDs using a shift register.

http://www.gammon.com.au/forum/?id=11518

Doing relays instead is just a different device.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Grumpy_Mike

Well depending on the current requirement of the relay you might have to follow the shift register output with a transistor to drive the relay.

nickgammon

Indeed. And maybe a diode to protect the Arduino/transistor from the relay coils.

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

guix


Doing relays instead is just a different device.


But, I think I have read somewhere that the LEDS aren't all turned ON at same time but rather only one at a time, very fast switching to the next LED (persistance of vision). If it's true then it will not work well with mechanical relays such as the ones I linked to :/ . True, or false?


Well depending on the current requirement of the relay you might have to follow the shift register output with a transistor to drive the relay.


I'm not sure what you mean, the relays are opto isolated so all the shift register have to do is turning a small LED ON or OFF, to activate or deactivate a relay, correct? Relays themself are powered by the 12VDC from the relay board and require 20mA each.

It's OK or do I really need a transistor? Sorry, I'm very beginner..


Indeed. And maybe a diode to protect the Arduino/transistor from the relay coils.


Please see my reply to Grumpy Mike and tell me if diode is still necessary :)

You can see relay board here, and full diagram is available in this .rar!

nickgammon


But, I think I have read somewhere that the LEDS aren't all turned ON at same time but rather only one at a time, very fast switching to the next LED (persistance of vision). If it's true then it will not work well with mechanical relays such as the ones I linked to :/ . True, or false?


False in this case. You are thinking of multiplexing displays which indeed work like that, but shift registers like the one I linked to have independent outputs which you load up by shifting out the bits you require (using SPI for example) and then "latch" the new configuration which copies the bits from an internal buffer to the output drivers.


I'm not sure what you mean, the relays are opto isolated so all the shift register have to do is turning a small LED ON or OFF, to activate or deactivate a relay, correct? Relays themself are powered by the 12VDC from the relay board and require 20mA each.


In that case you should be in spec for the 595 shift register. You also would not need the diodes then because the opto isolators isolate the relay coils from the 595 chip.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

guix

Thank you Nick Gammon, I have favorited your interesting website.

And Karma++ for everyone :)

Go Up