4
\$\begingroup\$

Hopefully I don't get torn apart for such a noobie question (but how else do you learn right?). I got a Raspberry Pi to hopefully learn a bit about electronics (and because it was 35 dollars). I asked a question on another Stack Exchange site:

https://raspberrypi.stackexchange.com/questions/32012/electronics-of-a-water-pump/32014#32014

I got a great detailed answer but in turn had questions about that answer.

The answer mentions that I need a relay to switch the pump. To my understanding a relay is a device that opens and closes an electrical circuit.

I dont know enough about electronics to know why I need a relay, but here is my sad attempt at a guess:

The Raspberry Pi's GPIO pins do not provide enough current for the water pump, so I need an alternate power supply to provide enough current to the pump. So in order to turn the pump on or off I need a relay (which I assume would be toggled by a GPIO pin) to open or close the circuit which turns the pump on or off.

If this is correct, wouldn't everything stop getting power? Once the relay opens the circuit, wouldn't the GPIO lose control of the relay... since the circuit is open...???

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Yup. The GPIO would control the relay, which in turns controls the pump. \$\endgroup\$
    – efox29
    Commented May 28, 2015 at 20:14
  • 2
    \$\begingroup\$ Some relays might need a transistor interface between GPIO and relay (usually because 3V3 relays are fairly rare). Other than that, spot-on. \$\endgroup\$
    – Andy aka
    Commented May 28, 2015 at 20:17
  • \$\begingroup\$ This is a stupid question (and maybe better asked as a new one). When the relay "opens the circuit" what is happening? Without having a circuit, how would the GPIO signal the relay to close the circuit? I mean wouldn't GPIO lose control of the relay the instant the relay opens the circuit? Does the relay have the ability to "bridge" a circuit or like cut out part of a circuit? Hopefully that wasn't complete nonsense. \$\endgroup\$ Commented May 28, 2015 at 20:50
  • 4
    \$\begingroup\$ @TheBlindSpring Relays are effectively two isolated electrical circuits which are mechanically coupled. When a relay "opens", only the load is disconnected. Your GPIO/control circuit is still a complete circuit with the relay control coil, so it is able to re-connect the load at any time. \$\endgroup\$ Commented May 28, 2015 at 22:03
  • 1
    \$\begingroup\$ Think of a relay as an electrically-operated switch. The switch contacts are electrically isolated from the controlling circuit. The controlling circuit energizes an electromagnet, which attracts the moving contact of the switch, causing the contact to change position. You will almost certainly require a transistor to operate the relay, as the RPi GPIOs can only handle a few mA. \$\endgroup\$ Commented May 28, 2015 at 23:12

2 Answers 2

3
\$\begingroup\$

A relay is like a wall switch that turns on the lights in a room. The difference is that it is electrically controlled, instead of a little lever that you flip with your hand. Inside the relay is a small electromagnet, which drives the switch for you. When the electromagnet is energized (a voltage is applied to it), then the switch is held one way, otherwise a spring holds it the other way.

The voltage and current it takes to run the electromagnet can be much less than what the switch can switch. A 5 V relay, for example, might only take 60 mA to energize the coil, but the switch can handle 5 A at 120 V AC.

While relays can have a lot of gain (takes a lot less power to run the magnet than the power the switch can switch), the kind of relay to run a water pump will still take more power than a typical digital output can provide. One way to get from a digital output to driving a relay coil is to use a transistor. The digital output switches the transistor, which in turn switches the relay coil. This works because transistors have gain too.

There are many simple circuits for driving a relay from a digital signal, probably a bunch on this site (I'm pretty sure I've answered that question several times here), so I won't repeat that here.

\$\endgroup\$
3
\$\begingroup\$

A relay is a device comprising an electromagnet (the "coil") and a set of contacts which are activated when the electromagnet is energized.

The moving contact (the "COMMON", or "COM", or "C") is attached to the "armature", a magnetically soft structure which is commonly spring loaded and is used to connect the moving contact to one of the fixed contacts depending on whether the coil is energized or not.

The contact to which COM is connected - and held against by the armature spring - when the coil isn't energized is called the normally closed (NC) contact, and the contact to which COM is connected when the coil is energized is called the normally open (NO) contact.

As shown on the schematic below, with S1 OFF, current from BT1 is prevented from passing through K1's coil and, consequently, the coil is de-energized and COMA is connected to NC, keeping BT2 disconnected from R1.

With S1 ON, the coil will be energized and the magnetic field generated by the current through the coil will attract the armature, which will carry COM with it and make a connection between COM and NO. When that connection is made, BT2 will become connected to R1 through the made contacts, and current will then flow from BT2, through COM and NO to R1, and then back to BT2.

So, you can see that even though closing S1 causes current to flow through R1, both circuits are linked only by the magnetic field generated by K1's coil, their operating currents being independent by virtue of their isolated supplies.

"GPIO DIRECT", below, shows the case where an MCU I/O is connected directly to the relay coil, which will energize the relay if the MCU can supply the current the relay needs without dropping too much voltage internally. The diode is there to suck up the Ldi/dt spike generated by the coil when it's turned off abruptly.

"GPIO WITH GAIN" shows the most likely scenario if an I/O is used to operate the relay, and functions by using a small current from an MCU I/O to turn ON Q1, which in turn allows current from BT1 to flow through the relay coil and the transistor collector-to-emitter junction back to BT1, energizing the relay. The diode is there to suck up the Ldi/dt spike generated by the coil when it's turned off abruptly.

"COMMON SUPPLY" shows a way to use a common supply to power the load,(R2) the relay, and the MCU. \$ \ \ \$ NOT GENERALLY RECOMMENDED.

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ Soooo I am doing my best to make sense of this, but I had a question about your sentence "When that connection is made, BT2 will be connected to R1 and current will flow from BT2 through the made contacts, then through R1 and back to BT1." Is it supposed to go back to BT1 or BT2? If BT1, I am not sure how it would flow back to BT1. BT1 and BT2 are batteries I presume (Sorry, new to circuit schematics)? And what is Q1? Also, you mention PT1 in your answer, should that be BT1? \$\endgroup\$ Commented May 29, 2015 at 14:20
  • \$\begingroup\$ @TheBlindSpring: AARGHHH!!! You're right, of course; it's now fixed. Trypo, brain fart, whatever, it was an error. Good catch, thanks. :) \$\endgroup\$
    – EM Fields
    Commented May 29, 2015 at 14:42
  • \$\begingroup\$ Stupid questions... I believe you are saying both GPIO Direct and GPIO With Gain will work, so whats the draw to one or the other? And why must there be another battery if we use gain? \$\endgroup\$ Commented May 29, 2015 at 15:03
  • \$\begingroup\$ @TheBlindSpring: Not stupid at all... 1.)If you have a relay which can work directly from an MCU I/O, then the draw there is that it'll just cost you a diode to get the thing working. If, on the other hand, you have a relay which requires more coil current than the MCU can supply, the draw is that instead of being up against a brick wall you can make the thing work with just a transistor, a resistor, and a diode. \$\endgroup\$
    – EM Fields
    Commented May 29, 2015 at 17:25
  • \$\begingroup\$ @TheBlindSpring: 2.) Depending on the application, it may be possible to use a single battery, but then you lose the isolation between the MCU and the load because they'll need a common ground. Also, the junk on the coil and the load tends to dirty up Vcc and get into the MCU, so a single supply is generally avoided, if possible. Even so, I'll edit my answer to show how it can be done. \$\endgroup\$
    – EM Fields
    Commented May 29, 2015 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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