Electronic – needed to switch a relay via logic output (e.g. from Raspberry Pi)

raspberry pirelay

I'm working on a project with a raspberry pi involving some sensor and a relay.
Actually I'm Using a board like this one:
enter image description here
So I connect GND,5V, and a GPIO to the IN pin to control the relay state: ON/OFF.

Now I'm starting to move from the prototype stage..

I'm working on create the PCB, and I'm wondering if I can drive the Relay, with a "naked" version like this:

enter image description here

  1. is it possible? Why all the other components are required on the board, figure 1? resistor, transistor etc..

  2. I'm expecting to connect:

    • D to the source and one between A or B to the destination
    • C to GND
    • E to a GPIO ..correct?
  3. Maybe I'm using "rocket to kill an ant".. I'm using the relay for control a low voltage (between 12V and 24V DC)..is there any more appropriate component or integrated circuit that you can propose?

Best Answer

  1. The transistor is used to drive the coil that activates the relay. The diode is a flyback diode which is used to discharge the coil when switching the relay off, otherwise the transistor will be damaged. You need to design those components onto the board if you want to use this relay "naked".
  2. Basically, you are right but you need a transistor to drive the relay because the microcontroller can't deliver the required ~90mA at 5V.
  3. It looks a bit overdesigned if you only want to switch 24 VDC. It depends on many parameters (current, voltage, switching frequency) which relay you can use.