Hardware disconnects when switching relays

Hi,

In my project I control 4 relays with buttons in the blynk app.
But most off the time when I switch one, the hardware disconnects!
I am using an arduino mega, and a WW5500 ethernet module.
Everything in the project worked fine, till now.

This is the code that controls the relays (its the same for all the other relays):

BLYNK_WRITE(V61) {
  relay1_state = param.asInt();
  digitalWrite(relay1, relay1_state);
}

I hope there is a solution.
Isaak

Most certainly the switching draws too much current from the Mega pins and thus resets the chip. U probably need to use transistors to drive the relay.

2 things:

  • the relays vcc and gnd are connected to a seperate power source.
  • and the relays have to be set to LOW to make turn them on…

What type of load are you switching?
If it’s something that generates electrical noise - a motor, fan, bell, buzzer etc. - then it’s probably EMF that’s flowing back into your Arduino.
In this case the solution is usually a suitably rated capacitor across the relay terminals.

Pete.

2 lamps, a monitor. and even nothing. so if i quickly switch it on and of without a load it disconnects!
Wires are approximately 2 meters long. (form relay to arduino)
Using this relay board…

Which pins are you using to control your relays?

Pete.

pins 30 - 34

Does it help if you shorten the wires to the relays?

Pete.

No, same result

How exactly is your relay wired?
Do you have a shared ground between the relay power supply and the Arduino?
What position is the JD-VCC/VCC jumper in on the relay board?

Pete.

the JD-VCC/VCC jumper is on the board (i don’t really know what it does) but it can’t be placed on 2 other pins, what i mean by that is that there are only 2 pin headers on the board, so i can put it on or off.

And the arduino and relay share the same ground (the Arduino is powered by the same source).
Its wired to pins 30, 31, 33 and 34. 5V to VCC and GND to GND of course.

Isaak

These two statements contradict each other!

The relay needs a separate power source, and the GND of that power source needs to be connected to the GND on the Arduino.

Pete.

Ehm I think you misunderstood me, the arduino is connected to the same source as the relay… isn’t that normal?

No…

Pete.

No it doesn’t.
The relays are powered by a separate power source (12V 1A converted to 5V with this module).
That is the same power source as where the Arduino mega is connected to.

Isaak

Now I’m even more confused by your description
We need a schematic.

Pete.

I don’t have one.
Its simple… The Arduino VIN is connected to that power source as wel as its GND.
Same thing with the relay… the relays VCC is connected to the 5V output of that power source as wel as its GND…
that’s it, nothing complicated.

Isaak


Here you have your schematic.

Okay, what you are doing with this setup, and with the JD-VCC jumper in place, is oerearing without any opto-isolation in place.

To use the onboard opto-isolation of the relay board, you need to do the following…

Remove the JD-VCC jumper
Connect the 5V + output from your regulator to the pin labelled JD-VCC on the relay board (which has been freed-up by removing the jumper)
Leave the negative (Ground) wire from the 5V regulator as it is in your schematic

Connect one of the 5V VCC pins on the Mega to either the VCC terminal on the relay board, or the VCC pin that is freed-up when the jumper was removed (they are connected together, so whichever is the most convenient).

As your Mega and the relay board already share a common ground there is no need to connect a GND pin from the Mega to the GND terminal on the relay board, but there is no harm in doing this as well - just as a precaution.

Now, when you pull one of the IN1 to IN4 pins LOW (relative to the Mega’s VCC voltage) the corresponding relay will activate, but the Mega will be opto-isolated from the relay cols.

However, as both the Mega and the relay board are powered from the same supply, you may still experience problems. The real solution is to use separate power sources for the relay and the Mega, with a shared common ground only.

Pete.

Thanks For the help Pete!

For who interested:
I Used some transistors (BC547) and 1K resistors to control the relay outputs. It works just fine and i can spam the buttons as much as I want and it doesn’t disconnect!

I didn’t know that the Arduino can reset without using something like this.

Isaak