1

I asked a questions about controlling a water pump with the pi and in one of the answers (https://raspberrypi.stackexchange.com/a/32014/19436) he mentioned I could get one power supply to power both the Pi and the Pump. How would one go about taking a power supply and connecting it to two different things? Would this require building your own power supply?

EDIT: So it seems as though two power supplies is the way to go using a relay. I am trying to understand how to use a relay... Is this circuit sensible for what I would like to do? Green is ground, yellow is 5V and blue is GPIO.

enter image description here

TheBlindSpring
  • 159
  • 2
  • 9

1 Answers1

3

An easy way to do this is to buy a powerful power supply (in regards to your previous question) like this one: 5V DC 3A power supply and either cut off the barrel plug - leaving you with a + and a GND wire (which is which you can easily determine with a voltmeter or by looking at the polarity of the plug and how it's wired). You then connect the positive +5V wire both to your PI (one of the 5V pins on the GPIO header, i.e. pin 2 or 4) and your relay board, and the GND wire to one of the many GND pins on the Pi as well as to the GND of the relay. Note however that doing this means the Pi and the relay board are linked in circuit and not fully electrically isolated, which defeats the purpose of the optocoupler on the Sainsmart relay board I referred to in my answer to your previous question.

If you want to full separate the two circuits, you keep your original USB wall wart for the rPi, and you get a separate supply for the relay board and pump. In this case, don't connect the separate supply's GND to the rPi's ground - the optocoupler ensures the two circuits are fully separated. Oh, and get yourself a primer on electronics, I can recommend Forrest Mims' handbook as a quick but thorough read.

EDIT: You might be able to power your relay & pump through the GPIO 5V pin if you buy a powerful enough USB 5V power supply for your rPi (would need to be 3A or more at least if this is for a B(+), 4A for an rPi 2) - the 5V supply has a 2A polyfuse which sets the upper limit for the current provided. Check this forum post on raspberrypi.org for more details. But be careful - you could pull too much current for the rPi to keep running reliably, and, as with everything electronic, take care in testing your setup step by step to avoid making a costly mistake (read: fry your rPi). Especially when working with the 5V GPIO pin it is easy to accidentally short it with another pin, potentially causing damage to that pin or the entire processor.

EDIT TWO: Got myself a bit mixed up there in all the options, but basically you have 4 things to provide power to:

  1. The rPi (typically powered via USB)
  2. The opto-coupler on the board using the 4pin header's VCC - typically powered using the 5V (or 3V3 volt) pins on the GPIO header
  3. The relays (either powered from the same 5V supply as the opto-coupler when you put the jumper across the 3-pin header's VCC and JD-VCC, or separately powered by removing that jumper and supplying 5V to JD-VCC, the latter would fully isolate the GPIO pin from the relay)
  4. The pump itself - my answer above shows how you can do this with a separate or joint 5V power supply, but you could just as well use a 12V supply or 9V supply if you have those handy. This power supply gets its positive wire attached to the middle screw terminal of the relay, and either the left or the right terminal (but not both) go to your pump.

You would need a common ground between 1&2, and if you leave the JD-VCC/VCC jumper in place, you would need to also need a common ground for 3. #4 can be independently grounded.

Check this link on raspberrypi.org for a lengthy discussion on how to set up such a relay board: https://www.raspberrypi.org/forums/viewtopic.php?t=19222

Phil B.
  • 5,043
  • 15
  • 30
  • So this would mean there would not be anything plugged into the mini-usb port then? I use a breakout, is there any reason I can t connect the 5V pin to the bread board and then connect 5V wire to that part of the bread board? – TheBlindSpring May 28 '15 at 21:35
  • Now you need to be more specific - which 5V pin, which wire, and which part of the breadboard (in other words - what does that connect to) are you talking about? – Phil B. May 28 '15 at 21:55
  • Added some more wording to deal with your last question in the comment – Phil B. May 28 '15 at 22:05
  • Well I guess I am not sure exactly what you mean. You said to connect the +5V wire to both RPi and relay. So any 5V pin on the Rpi will work? And if the wire is connected to the Rpi, how can I also connect it to the relay? Split it or something? – TheBlindSpring May 29 '15 at 14:57
  • I assume you refer to my first suggestion to take an existing barrel-plug supply, remove the plug and split the wires. Indeed, you then connect 2 wires to the +5V wire from the supply - one goes to one of the 2 5V pins on the rPi, the other to the VCC input of the relay board. Same for ground, attach 2 wires, one goes to a GND pin on the rPi, the other to GND on the relay board. Let me remind you that when you play with these GPIO pins (especially the 5V ones), there is a risk you damage something on the Pi accidentally, so be careful and proceed at your own risk. – Phil B. May 29 '15 at 15:01
  • I'd strongly suggest you read this thread: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=43827 as well as this one: https://www.raspberrypi.org/forums/viewtopic.php?t=36225 on raspberrypi.org - they go through a lot of detail on what you're asking. Powering external circuits is no trivial matter, but with a little bit of reading and googling you'll find that it is also not difficult to do. – Phil B. May 29 '15 at 15:06
  • I will absolutely check that out those links. I am looking at the Sainsmart relay link and can only guess how it is used. Correct me if I am wrong. It has 2 channels (each with the 3 connections (those 3 screws)), and we will only be using one. One connection is for 5V, one connection is for GND and the last connection is for whatever will be toggling the relay (GPIO in my case). Is that even remotely correct? – TheBlindSpring May 29 '15 at 15:41
  • Oops - I made some incorrect statements in my previous comment (minor corrections) but will have to delete them as I cannot edit. In the meanwhile - check out this link: https://www.raspberrypi.org/forums/viewtopic.php?t=19222 – Phil B. May 29 '15 at 16:51
  • 1
    We should probably move this discussion to chat - let me answer your last Q and if you have more Qs, we'll move it over. There is a 3-pin and a 4-pin header. The 3-pin header has a jumper on it and is for the supply current to the circuit you are trying to switch - you either connect JD-VCC with VCC to make this both powered from the same source, or supply 5V and GND to the JD-VCC and GND pins. The 4-pin header has VCC and GND to power the relay, and an IN1 and IN2 which you connect to your GPIO pins to switch the individual relays. The relay is double-throw, so each relay has 3 screw .... – Phil B. May 29 '15 at 16:52
  • 1
    .... terminals, the middle one is the line in, the left and right ones are the line out (at least in your application). You can connect your pump power supply's +5V line to the middle terminal, and a wire from either the left or the right (but not BOTH) terminal to your pump. Now using your GPIO pin you can switch the relay to either direct the 5V current via the left or the right terminal, effectively either supplying or not supplying current to the pump. – Phil B. May 29 '15 at 16:56
  • I added a picture of what I think you are explaining. Am I anywhere near? – TheBlindSpring Jun 16 '15 at 21:08
  • Yes, close. If you power both the optocouplers and the relay from the pi, you only need to supply 5V to the VCC on the board, and then leave the jumper on the VCC - JD-VCC connection. Also, I would not use the TXD GPIO pin but rather pick one that is not dual-purpose. – Phil B. Jun 16 '15 at 21:35
  • And note that in this setup, the pump supply does not need to be 5V, but can be any voltage within the specs of your pump (I believe you said it was 5V-12V) – Phil B. Jun 16 '15 at 21:38
  • So you are saying I could get a 3rd power supply to power the relay which would be completely independent of the rPi? And the purpose is to fully isolate the GPIO from the relay? Why do we want to isolate it from the relay? – TheBlindSpring Jun 16 '15 at 21:43
  • A relay is an inductive load and just like a body of mass resists changes in its momentum, a relay will resist changes in its electrical current. This creates backflows and ripples in the power load, which could potentially move back to your GPIO pins and negatively affect the functioning of your rPi. You are already protecting your logic GPIO port by using the optocoupler, but by using a shared ground there is still the small chance a ripple will propagate via that channel. So to be completely safe, you could provide 3 different power sources and grounds. In practice, your setup is fine. – Phil B. Jun 16 '15 at 23:11