Relay board advice

Hello everyone!

New to the community today and new to Arduino today.

Well to keep things short and sweet, I have a little project that looked like Arduino would be a great match for (and it would give me an excuse to learn about this amazing product.

In short my project is pretty simple;

I'm using a rotary switch to switch between options.
I'm using digital read for pins to determine which position the rotary is in.
Once the Uno knows which position its in, it turns on output pins. These output pins are being used to activate a sainsmart relay board

here's where the trouble lies, the relay board activates the relays when the corresponding pin is grounded, NOT when it gets power. As such my code writes all pins high in the setup, then uses an if/ifelse statement to filter though them looking for a pin that is grounded. once it does it grounds the output pins. This all works perfect EXCEPT, if the arduino looses power, all of the read pins on the relay board get grounded to the Uno. This turns them all on. Any ideas on what i can do to correct this?

Here's the code for just 2 relays, let me know if a schematic is needed or pictures or whatever

Again the problem seems to be that the pins on the arduino ground out when not powered

void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}

void loop() {
int sensorValue2 = digitalRead(2);
int sensorValue3 = digitalRead(3);
  if (sensorValue2==0)
    {
      digitalWrite(8, LOW);
    }
  else if (sensorValue3==0)
    {
      digitalWrite(8, LOW);
      digitalWrite(9, LOW);
    }
  else
  {
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
  }
delay(300);
}

When the Arduino losses power its pins float, not go to a LOW.

Schematic and links please.

I think that these relay boards have a jumper that can be used to select whether the opto-isolator inputs are powered from a 5V supply on the board, or an external supply.

The problem you mention occurs when the board's own 5V supply is connected to the optos.

You need to select the external supply, and connect it to your arduino 5V pin.

What is the model of the relay board.
8- or 16 channel.
Sainsmart 16 channel boards have this "problem".
Take care, the optos are not isolating either.
Leo..

put in debounce, heavy on the lag time.

I thought a video might be the best way to show how this thing is configured.

LarryD this is some testing I was doing regarding the ground vs float thing. It looks to me as though its grounding.

It looks like you are powering the Arduino with 3 AA batteries.

  • Are these 1.5V with fresh batteries?
    If so, this is 4.5V (new batteries) and may cause problems down the line.
    Try to stick with 5V external supplies if need be.
  • ~~Does the switch go back add forth between D2 and D3? ~~OK its a rotary switch.
  • Why would the Arduino loose power and not the relay board?
  • Are the coils of the relays rate at 5 volts?

Can you give a link to the schematic of the relay board that you have?

Yes, you do need a line from +5 to the Arduino 5 volt pin in your drawing.

I do not hear the relays click when the relay LEDs go on, do they?
Caution,I believe that relay board outputs 5V.
.

Larry,

-Yes the 3 AA’s are fresh and are sitting at 4.5v. I assumed the 4.5 would be ok for testing but i’m new to arduino so your probably correct and I should track down a 5v supply before doing much more testing. I was exceeding the limit of the USB port on my pc so I switched to this.

  • The switch does currently go back and forth between 2 and 3, but more will be added at a later time, once these get worked out.

-I would hope that I wouldn’t have a situation where the Arduino would lose power and not the relay board but I just like to vet thing completely before using them in a production situation. This will be used on my test bench and having all of the relays on could cause some problem. As such, at a point of failure, I’d like them to all turn off rather than on. A couple situations where I could see this happen would be. A) the Arduino fails and the relay board doesn’t. B) The power supply starts to fail causing less than 5v and the Arduino “might” be more sensitive to voltage causing it to shut off first. At the end of the day its more of a fail safe than anything.

-The relay coils are 12v but the signal to turn them on is 5v. The 12v supply isnt connect so only the led on the board turns on. I have tested it with the 12v supply connected and it works the same.

Attached is my revised drawing as well as 2 pdf’s from sainsmart for the relayboard.

16 RELAY.pdf (491 KB)

16 relay 2.pdf (55.1 KB)

Seems the picture didnt attach so here it is.

Are you able to try:
12v PS to the relay board connector.
Do not connect anything to the 5 pin on th relay board.
USB or wallwart to the power jack to the Arduino.
GND on the Aruino connected to the GND of the relay board.

Then unplug the USB/wallwart.

BTW, you could nix to the 10Ks and use the internal pull-ups.

.

Ok I've tried that.

-12v on its own supply
-GND from the relay board to the GND pin on the arduino
-5v pin left unconnected
-5v source from the USB

the result is the relays dont turn on. I'm guessing you were testing to see if the 5v pin on the relay board is a supply or input?

I have confirmed it does not supply 5v when the 12v is supplied.

However this little exercise does bring me to a point of understanding. If i'm using a 5v wall wart to supply the Arduino and the 5v pin on the arduino to supply the relay board, then the problem resolves its self by default.

But at the same time I'm still curious how I could resolve this in such a manner where the Arduino doesn't have to supply the 5v

Also, could you tell me more about using the Arduino as a pull up? i'm not sure how to go about doing that

Makes pin 2 input and turns on its internal ~10K PULLUP resistor.

pinMode( 2 , INPUT_PULLUP );

I have confirmed it does not supply 5v when the 12v is supplied.

According to the schematic the +5 volt pin outputs 5 volts when 12 volts is powering the relay board.
:wink:
.

If i'm using a 5v wall wart to supply the Arduino and the 5v pin on the arduino to supply the relay board, then the problem resolves its self by default.

You must use at least a 7 volt wallwart when using the Arduino power jack.

Yep your absolutely correct, it does supply 5v that was my mistake. I had a 1k resistor on the 12v supply because its capable of very high current if shorted. It was causing the relay to only get 2v instead of 12v. I remeoved it and problem solved. 12v at the relay and 5v on those supply pins.

So, not to jump ahead here, but are you thinking I should use the 5v supply from the relay board to power the Arduino and nothing else?

So, not to jump ahead here, but are you thinking I should use the 5v supply from the relay board to power the Arduino and nothing else?

I don't believe the regulator on the relay board can supply very much current to an external circuit.
If you do use this output, and the regulator gets hot, then don't use the relay board to supply power.

IMO I would not use it.