Electronic – need this relay

gpioraspberry pirelay

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…???

Best Answer

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