Go Down

Topic: Question about Arduino Mega with Sainsmart Relay Boards  (Read 150 times) previous topic - next topic

markmakeitso

Hello all,
New to the forum, but have been browsing a bit over the years for particular questions. Looking for some advice. I'm using LabVIEW to control a light industrial process, and byte commands to a Mega over USB to perform some light analog input tasks, and also digital I/O to a pair of Sainsmart 8 channel relay boards that control small gas flow control solenoids.

There's a separate 5V regulator in the system (off a 12 VDC power supply, which also supplies power to the solenoids), and was powering both VCC inputs on both relay boards from that 5V, and tying the Mega ground to that of the regulator. Works well except that the relay inputs are active low, so if the Mega isn't powered up all channels are active. That's not ideal, and I'd like to ensure that if the Mega isn't powered up and receiving commands all the relays default to off (and my solenoids closed).

A couple ideas I've thought of:
-Connecting my +5V regulator to the main power VCC, but VCC of the board next to the individual input connections to a digital output of the Mega. Not sure what the current requirements for that VCC input are, but they might be less than that of an output pin.

-Using a couple higher channel count logic inverters to change the inputs of the relay boards, and power the inverters from the regulator that also powers the relay boards, so whenever the regulator is powered up the inputs are held high until they get a high input.

-Pull up resistors on the relay board inputs.

-Skip my plan to power the Mega from the PC and use the +5 regulator instead. Assuming there's a way to divorce power and USB connectivity on the USB B connector.

Any feedback on these ideas, or other ideas anyone would suggest? Hopefully my description is reasonably clear.

TIA,
Mark

Paul__B

As long as you are not even dreaming about using the "Vin" or "barrel jack" of the Mega 2560 for an actual application.  :smiley-eek:

As always, you fail to tell us what "Sainsmart 8 channel relay boards" you mean.

Presuming it is one with the "VCC-JDVCC" jumper, the answer is this:


markmakeitso

Hi Paul, thanks for the reply.

My fault, good point. This is the board I'm using:
Sainsmart 8 channel relay board

No, I'm not trying to power much besides the Mega from the USB connection, and that's negotiable. The 8 channel model is very similar to the 4 channel one shown, although it has a 10 pin block (ground, 8 individual inputs, and VCC together) and 3 pins to the bottom right (ground, a pin connected to the other VCC, and JD-VCC). If the jumper is across the latter two the VCC supply from the 10 pin block is also used to actually power the relay coils (not the loads though). Supplying the VCC next to the 8 inputs from a digital output was one of the options I was considering.

Paul__B

#3
Nov 30, 2019, 11:18 pm Last Edit: Nov 30, 2019, 11:26 pm by Paul__B Reason: Always more to add ...

The diagram is correct for that board.  Just use the "JD-VCC" and GND on the right hand connector for the relay supply.

Do not connect ground from the board to the Arduino.  Unless you are actually powering the Arduino or something connected to it from the relay supply, do not connect the relay supply ground to the Arduino at all

markmakeitso

I appreciate the guidance Paul__B,
We do have 2 pressure sensors that I was planning to measure using Mega ADCs during operation, but power from the 5V regulator. That was my main motivation for sharing grounds between the regulator and the Arduino. They would probably be okay being powered from the Arduino directly if necessary however.

The relay boards do currently work. My main issue is a method to reverse the inputs of the relay boards, so an unpowered Mega doesn't result in all relays being activated. Any advice on the inverters, pull up resistors, or other potential methods listed to accomplish this?

Thanks,
Mark

gilshultz

This link will give you the schematic if you click on 8+Relay+Module.rar.  You must connect the ground to make it work with the arduino.  You can switch the VCC side with a solid stage switch or whatever you like.  Drive it directly from the mega 5V, when it goes down the relay will open. You will have powered the VCC via the NC contacts so they will deactivate.  The input to the relays is a resistor, opto coupler diode and LED in series. Removing VCC disables it completely.  You can even use a single relay board (active high input), they are inexpensive.  This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

herbschwarz

Can you just use the opposite the relay switch contacts?

Paul__B

The relay boards do currently work. My main issue is a method to reverse the inputs of the relay boards, so an unpowered Mega doesn't result in all relays being activated. Any advice on the inverters, pull up resistors, or other potential methods listed to accomplish this?
Yes, I just gave you the diagram to do exactly that in #1 (and again in #3).  :smiley-eek:

That is how it is designed.

So you understand, here is the circuit of the relay module (per relay):

Since the power to the optocoupler LED ("VCC") is derived from the Arduino, if the Arduino is un-powered, the relays cannot activate.  :smiley-cool:

One warning however - you must in your code digitalWrite the relay control pins HIGH before you declare them as outputs, otherwise the relays tend to flash on briefly due to the few microseconds your code allows between defining them as outputs and - as it presumably does - writing them HIGH to turn them off.

Go Up