Getting a relay to work

Hey,

I'm trying to have a relay working with Arduino.

I am total noob on electronics.

I am running this simple code and I get the relay LED on channel 1 blinking every 3s:

int in1 = 7;

void setup() {
  pinMode(in1, OUTPUT);
  digitalWrite(in1, HIGH);
}

void loop() {
  digitalWrite(in1, LOW);
  delay(3000);
  digitalWrite(in1, HIGH);
  delay(3000);
}

My problem is that I am not getting the multimeter to bip when trying the normal open output of the relay channel 1.

The multimeter bips on the normally closed contacts, but never on the contacts that should be closed by Arduino.

I also don't hear the clicking sound of the relay.

What I'm using:

  • HW-131 source board powered by a new 9V battery. I measure 5V on the output and 5V on the relay contacts JVDcc and Gnd
  • HL-525 board with 2 relays
  • 5V going from Arduino's 5V pin to VCC (2nd group of relay's pins)
  • Arduino pin 7 going to relays In 1

As I was saying the In1 relay LED blinks every 3s.

I don't get a bip on the multimeter on normal open contacts no matter what I've tried: In1, In2, on In LED on and off.

Have I broken the relay or am I doing something wrong?

Attached are some pictures.

Thank you

Need a common ground between Arduino and external power supply?

mmitchellmoss:
Need a common ground between Arduino and external power supply?

Thanks for your answer.

I was following this scheme:

From here: Arduino Relay Tutorial - Control High Voltage Devices with Arduino

And the grounds are not connected.

Just tried connecting Arduino ground directly to external source ground and it didn't help.

Also tried conneting pin 7 to external source ground and external source ground to In1, it didn't help.

And finally tried connecting the relay without an external power supply:

  • put jumper back on relay (JDVCC to VCC)
  • added Arduino ground to the pins group with In1/2

Didn't help. :frowning:

What am I doing wrong?

And if I have shorted the relay is there a way to check this?

What is this "external source ground" that you speak of? :slight_smile:

The Arduino ground and the relay board ground must be connected together.

aarg:
What is this "external source ground" that you speak of? :slight_smile:

The Arduino ground and the relay board ground must be connected together.

Hmm, how exactly do I do that?

Can you please explain on this picture or draw on top:

Thank you!

GND on the right side of the relay board to GND on the Mega, right next to the 5V pin.
Edit - wait no, you don't need it:

  pinMode(in1, OUTPUT);

Does that look strange to anyone else?

aarg:
What is this "external source ground" that you speak of? :slight_smile:
The Arduino ground and the relay board ground must be connected together.

No.

If - and only if - the 5 V relay power supply is also being used to power the Arduino, then separately to the 5 V and ground wires from the power supply to relay board, you would run 5 V and ground wires from the power supply to the Arduino.

If the onboard relay LED is blinking, and the relay is not operating, your problem is on the relay driver side of the optocoupler. Check for 5V 12V power on JDVcc/GND. You have 12V relays (see the photos). 5V will not operate them reliably, if at all.

PaulS:

  pinMode(in1, OUTPUT);

Does that look strange to anyone else?

No, because "in1" is here referring to the pin on the relay board. :grinning:

However the sequence is incorrect.

Should be:

  digitalWrite(in1, HIGH);
  pinMode(in1, OUTPUT);

Otherwise the relay may briefly click on when booting.

mmitchellmoss:
Need a common ground between Arduino and external power supply?

No.
The opto LED is connected between VCC and IN1/2.
Ground of the relay board should NOT be connected to Arduino ground.
You can, but then you loose opto isolation.

PaulS:

  pinMode(in1, OUTPUT);

Does that look strange to anyone else?

Confusing name, but code seems ok.
int in1 = 7;

If the indicator light goes on/off, but you don't hear the relay click, then it could be the 9volt smoke alarm battery.
Relays like this draw about 75mA coil current each, and your 9volt smoke alarm battery might not be able to provide that when it's not fresh.

void setup() should look like this to prevent relay chatter during boot-up.

void setup() {
  digitalWrite(in1, HIGH);
  pinMode(in1, OUTPUT);
}

or

void setup() {
  pinMode(in1, INPUT_PULLUP);
  pinMode(in1, OUTPUT);
}

Leo..

aarg:
You have 12V relays (see the photos). 5V will not operate them reliably, if at all.

Wow. Good catch.

Wawa:
Relays like this draw about 75mA coil current each, and your 9volt smoke alarm battery might not be able to provide that when it's not fresh.

Yes, especially when the relay is a 12V relay, and it's powered from a 5V regulator powered from that battery...

aarg:
If the onboard relay LED is blinking, and the relay is not operating, your problem is on the relay driver side of the optocoupler. Check for 5V 12V power on JDVcc/GND. You have 12V relays (see the photos). 5V will not operate them reliably, if at all.

Yuhu!

9V to the relays instead of 12V was indeed the issue!

Thanks @aarg and everyone for your help.

Wawa:
Wow. Good catch.

Nah. I just learned more about relay boards today. I've never actually used one. :slight_smile:

overview.jpg

contacts-not-biping.jpg

Wow! So many things wrong here.

Trying to get something in before work here, didn't have time to go through the motions - I mean, the photos!

From the top: Pseudo-UNO (actually a SMD Duemilanove clone) is fine.

12 V relay module wired absolutely correctly, but needs 12 V as the relay supply. Quite possibly would work on 9 V and might even work on that battery if it is alkaline and only one relay actuated.

"Breadboard" power supply is generally pretty useless due to its limited heatsinking of the regulator(s). Would probably manage to power one 5V relay only. But in any case, relays should be operated at their specified voltage from a power supply designed for that voltage (which may include a battery - a 6 V battery is fine for driving 5 V relays).

"PP3" battery - AKA "smoke alarm battery" is of extremely limited use in powering Arduino projects due to its low current provision capacity (it consists of six "AAAA" cells) and limited mAH overall capacity. Alkaline versions might last a little while. :grinning: