Driving a 5v relay with a Nano - LEDs switching but relay itself doesnt

Hi,

Please help a noob out :slight_smile:

I am trying to switch a small dc pump on and off using a 5v relay.

The LEDs on the relay switch on and off as per my code, so I dont think its the code - but will copy/paste nonetheless below - but the relay itself isnt switching. If I connect the wires to the pump directly, the pump powers on. If I connect the wires to default closed, the pump is also always on (but doesnt turn off as per the LEDs ..).

I wired according to the diagram below I found elsewhere on this forum:

image

I've double checked voltage on the relay and it is indeed 5v (SRD-5VDC-5L-C).

The external power supply used to power the relay is rated at 0.2A ~ does this need to be higher for the relay to be able to switch? From what I understand one relay uses about 85mA so in my noob brain this appears to be sufficient (relay is the version with 2 relays, but only experimenting with one for now).

If the power supply should be okay, where do I start troubleshooting? I dont give up easily but am at a bit of a loss on this one.

Thanks!

#define relayPin 8

void setup() {
Serial.begin(9600); // initialize serial communication
Serial.print("lets start");
Serial.println();
pinMode(relayPin, OUTPUT);
}


void loop() {

digitalWrite(relayPin, HIGH);
Serial.println("relay HIGH – switch open");
Serial.println("HIGH = no current can pass in secondary circuit");
Serial.println();

delay(10000);

digitalWrite(relayPin, LOW);
Serial.println("relay LOW – switch closed");
Serial.println("LOW = current flows in secondary circuit");
Serial.println();

delay(10000);

}

I agree that you have everything wired correctly. Your code should work too. Some relay modules have jumpers to select whether they activate on low signal or high. Does your module have extra jumpers?

Other than that the usual suspects of bad connections and reversed polarity. I believe the Nano side is okay due to the LED lighting.

Your relay supply is a bit marginal. Relays have an inrush current when first energized. Check the voltage between RY-VCC and GND when the relay is supposed to energize.

Also try using the other relay if you haven’t already.

How many ampere is your power supply? I think the relay is not getting enough current.

Check the voltage between JD-VCC and GND with the relay activated, if it falls below 3V, your power supply is inadequate.

The relay module and Arduino need a common ground connection.
Probably the VCC of the relay board (which may need to be 12v) should not be connected to the Arduino Vcc (which is 5vdc)

Can you post a link to the exact relay board you have? Is it like this one, and there is a good wiring diagram on this page too

1 Like

Tx xfacta. The board I have is identical to the one you linked, except i have 2 channels ..

In the meantime i've upgraded the external power supply to a 1600ma one - which didnt solve my issue. I must have made an error in wiring, somewhere.. Are you saying the diagram I posted above is not correct?

I struggle to understand your comment, am noob, sorry. Where is the diagram I posted wrong?

image

In the meantime I am getting the relais to work JUST ONCE by connecting the external powersupply to the pins GND and VCC next to IN pins (see screencap below). And the jumper on pins VCC + JDVCC on the right in diagram. But just once per try, then Arduino crashes and the orange LED comes on. Not good, but that does rule out my power supply - rather its a wiring issue? Again, am noob :slight_smile:

image

That should be the schematic for your module. Or very similar, there are many makers of this module type. As can be seen the Nano Vcc is connected to the anode of the indicator LED and the opto-isolator’s LED. The Nano’s output grounds the circuit causing both the indicator LED and the opto LED to light up. Connecting the Nano’s GND to the circuit defeats the purpose of the isolation and is not required.

The above only applies if you don’t have the type of relay module that has selectable high or low signal capabilities. I have not found a schematic for that type.

I just noticed that the circuit is for the 12 volt relay version but that makes no real difference. Just use 5 volts in place of 12.

Also, welcome to the forum and congrats on getting all the basic items into your question. The problem, well stated, the schematic, and your code. Well done.

I just found this on page two of the Datasheet link in the document @xfacta linked above.

NOTES: If you want complete optical isolation, connect "Vcc" to Arduino +5 volts but do NOT connect Arduino Ground. Remove the Vcc to JD-Vcc jumper. Connect a separate +5 supply to "JD-Vcc" and board Gnd. This will supply power to the transistor drivers and relay coils.

Here is the link to the Datasheet:

I got out my brand new 2 relay module and wired it up according to your schematic. The only difference is mine is a 12 volt relay version so I used 12 volts for RY-VCC. I used your code but commented out the serial statements since I was not connected to the computer for the test. Everything worked perfectly.

The only thing we haven’t seen is how you have the pump wired. So if you could post that we’ll have a look.

Thanks a lot bitherder for the time you spent researching.

Another user gave me a bit of guidance via DM. He caught that I was using a Nano IoT 33 which operates at 3.3v by default. Even after connecting to the 5v out thats on the IO shield I am using ... still not working. I had to solder the connections labelled vusb on the back of the Nano to get 5v going .... :slight_smile: Noobs will be noobs!!

(as per this link: https://support.arduino.cc/hc/en-us/articles/360014779679-Enable-5-V-power-on-the-VUSB-or-VBUS-pin-on-Nano-boards)

Change the value of the resistors from Vcc to the optocoupler to half of the value they are now, maybe even lower. You might alo want to check the datasheet of the optocouplers first :slight_smile:

You show a 5V supply connected to JD-VCC (Ry-Vcc) OR Vcc
AND a 5V connection to the Nano IoT 33 BUT no ground connection
AND a USB supply to the Nano IoT 33

Its not good practise to connect two power supply rails together - except (usually) for the 0V rails.
It seems this relay module is an exception (thanks @Paul_B)

Good to hear you solved the problem. I really didn’t do much work. Most of the information was already in your posts and the posts of another user who had problems with their relay module.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.