0
\$\begingroup\$

I am trying to wire a four channel relay to a raspberry pi in order to toggle some 5v fans on and off. I have researched extensively but haven't found anything comprehensive relating to the RPI2b+.

This is very similar relay to the one shown here Not sure how to wire my 5VDC to 120VAC arduino relay board https://www.youtube.com/watch?v=oaf_zQcrg7g (that said, even directly following this tutorial doesn't seem to work for me)

Mine is the 4 channel version. I apologise but I have been unable to fully understand how to use this properly with an external power supply. I can get it to the position shown in the video, but I am unsure how to wire the external power supply and fans into the relay. I thought that this would be a universal simple process,m but it appears there are vast differences between different relays as to how the inputs and even the outputs are wired, and even though this is a low voltage situation, I just want to get it right.

here is a low quality diagram of what I want

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Is not so clear where your problem is. Have drawn the circuit you like to implement? That always helps! In general you'd want to wire one side of the fan to your 5V supply and the other side of the fan to one "pin" of the relay's output. The other "pin" of the relay's output should go to GND. And then one GPIO of the arduino should be connected to the input/control "pin" of the relay. \$\endgroup\$ – nickagian Jun 7 '17 at 6:16
  • \$\begingroup\$ I would not use the 5v power from the pi to power the relay board. Get an independent supply. Relays could create issues with the power on the pi by drawing too much current. \$\endgroup\$ – Voltage Spike Jun 7 '17 at 15:34
  • \$\begingroup\$ do I really have to use 3 power supplies to power one circuit? 1 for the pi, 1 for the fans, 1 for the relay? that seems really hamstrung to me \$\endgroup\$ – atol ikan Jun 8 '17 at 3:57
0
\$\begingroup\$

So this is my recommendation (unfortunately I cannot make any drawings at the moment):

For the output (the side where the fans are connected) - Connect the red wire of the fan to its power supply. That means to the +5V supply (red wire) from the microUSB board. - Connect the black wire of the fan to the COM pin of the relay (that would be pin no.2) - The NO pin of the relay should go to the GND from the microUSB board - And the NC pin of the relay should be left floating (or connected to the +5V from the microUSB board)

Having the above connections you achieve the following:

  • When the relay is not activated (that means the COM is connected to NC) the fan sees on its wires +5V and floating (or twice +5V), so no current is flowing and the fan is not working.
  • When the relay is activated (that means the COM is connected to NO) the fan sees on its wires +5V and GND, current is flowing and thus the fan is working.

Mind that usually the max. current from USB is around 500mA, so make sure that the total current needed by your fans (if you supply all of them in parallel from the same usb port) does not exceed this value.

Then for the input side of the relay board.

  • The inX pin of the relay should go to a GPIO of the Pi
  • The GND pin of the connector (left bottom side of the board) should go to the GND of the Pi board
  • The VCC pin of the connector (left bottom side of the board) should go to the +3.3V power supply of the Pi board.
  • I would connect the +5V to the JD-VCC pin. Also don't forget to remove the jumper on the right side of the relay board.

As you see in the diagram in the link you posted from another question, the JD-VCC is applied directly to the input of the relay and there is an optocoupler between the inX pins and the relay input. Since in your case you probably don't really need the extra isolation, connecting the JD-VCC to the +3.3V (either with another wire connection or with the jumper on the board) would probably also work. But I'm not sure what input supply voltage the relays used there are designed to work for. Chances are (but again perhaps I am wrong) that it will not work with the +3.3V supply.

\$\endgroup\$
  • \$\begingroup\$ Thanks Nick, great answer. However, I still haven't got it to work, I have some more questions. Firstly, I did a diagram to make sure I am interpreting this right because there were a few points of confusion (which ground does the rpi ground go to, the one on the left or the right?) you can find this diagram here link to check if its correct. I tried a few variations on what you suggested, giving the relay 5v / 3.3v to the left side V+ pin, and a few other variations which sometimes shorted the rpi out). What am I doing wrong in my diagram? \$\endgroup\$ – atol ikan Jun 7 '17 at 9:59
  • \$\begingroup\$ My other question refers to the usb ma max. I am actually running 4 0.5A fans in parallel, and they have worked fine for a while when the relay wasn't a part of the circuit. I am using a USB power supply designed for the RPI itself rated for 3A, so I am surprised that usb only handles 500ma? What is a better power source? I really appreciate your help \$\endgroup\$ – atol ikan Jun 7 '17 at 9:59
  • \$\begingroup\$ Regarding the second question, about the USB current, I was referring to a USB 2.0 port from a PC/laptop. If you have an external power supply device, the ones that can be plugged in the AC wall sockets, then what I said is no longer valid and the current is not an issue. \$\endgroup\$ – nickagian Jun 7 '17 at 10:32
  • \$\begingroup\$ Your diagram looks actually good. The GND pins on the left and on the right connector are most probably connected together on the board. Do you have an ohm-meter to check this? It should measure around 0 Ohm. When you say that it doesn't work, I suppose you mean that the fans are not operating? Are you sure that the inX pins have the correct voltage level? They should have a logic LOW level when you want the fans to be on and a logic HIGH when you want the fans to be off. Check this with a voltmeter or oscilloscope to be sure. \$\endgroup\$ – nickagian Jun 7 '17 at 10:40
  • \$\begingroup\$ well, I think there is an LED that should be on. \$\endgroup\$ – atol ikan Jun 7 '17 at 10:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.