I am working on a project where I need to control a couple of relays from the GPIO header on a Raspberry Pi. I tried getting a PCB with the layout like the right version in the image below, but I cannot switch the relay by setting the GPIO pin high/low.

After some more studying I came up with version 2, which is the left version, using an NPN instead of a PNP transistor - is it correctly understood that it looks more correct than the first version?

VCC is 12v and H1PXX is the GPIO pins which are 3.3v. P1/P2 are used to determine what to switch and are not relevant for this

Can I somehow make the right version work? I already have the printed circuit boards, so if it is just a matter of soldering on a wire/resistor somewhere I could do that without too much of a problem.

The board has a 5V regulator for the Raspberry Pi, so GND on the circuit is shared with the Raspberry Pi


  • 1
    \$\begingroup\$ Regarding drawing schematics, I'd suggest to read electronics.stackexchange.com/questions/28251/… \$\endgroup\$
    – Huisman
    Jul 17, 2019 at 13:48
  • \$\begingroup\$ If the footprint is the same, you can just use the different components in the same holes. Looks like that should work for you. \$\endgroup\$ Jul 17, 2019 at 13:50

2 Answers 2


The problem with PNP circuit is that the Raspberry Pi works on 3.3V while your Vcc is 12V.
So, putting either a low signal (0V) or high signal (3.3V) always will turn on the PNP, because in both cases VBE = VCC - Vbase = about 0.7V.
The base current will be either (12V-0.7V-3.3V) / 1kΩ = 8 mA or (12V-0.7V-0V) / 1kΩ= 11.3mA.

Since you already have the printed circuitboards you should implement the NPN version.

Regarding the NPN version: as you commented you need a NPN with the correct pinning (i.e. with collector and emitter swapped) like the MMBT9013 (don't know if it still exists).

Other solutions i can come up with require rework (don't if the number of PCB's and/or the space on the PCB allows for it)

  • putting a 9.1 zener in series with R10 using the pads of R10 (placing the components diagonal like /\ instead of --)
    you may need to lower the value of R10

  • replacing the PNP with a PMOS (e.g. NTR4171P), solder an 1k 0805 resistor on top of the gate and source pin and replace R10 by a tiny 9V zener (no idea what package R10 has, but e.g CDZFH9.1B)

  • \$\begingroup\$ Unfortunately implementing the NPN version also means new printed circuitboards as far as I see it since one of the legs on the transistor needs to be switched from VCC to GND and the diode also needs to be connected, but this seems like the most correct answer based on my situation \$\endgroup\$
    – Frederik
    Jul 17, 2019 at 15:01
  • \$\begingroup\$ @FrederikNielsen Did you use SMD or through hole? I may a few suggestions, but am able to draw circuits when on PC which is in a few hours. What's the package of the PNP? \$\endgroup\$
    – Huisman
    Jul 17, 2019 at 16:21
  • \$\begingroup\$ The PNP is SOT-23, the resistor and diode is SMD and the relay is through-hole \$\endgroup\$
    – Frederik
    Jul 17, 2019 at 16:38
  • \$\begingroup\$ @FrederikNielsen Please find updated suggestions \$\endgroup\$
    – Huisman
    Jul 17, 2019 at 21:20

If your 12V supply is completely isolated from the Raspberry Pi power supply and ground you can make the right-hand version work.


simulate this circuit – Schematic created using CircuitLab

Be aware that if the 12V supply has any other connection (such as a ground) very bad (i.e. fatal) things will happen to your Raspberry Pi (and quite possibly to things plugged into it). It's better to ask a few questions than to deal with a fried board etc..

  • \$\begingroup\$ Unfortunately the 12V supply is not isolated from the Raspberry Pi since there is a 12V to 5V regulator for powering the pi from the same power source feeding the relay here, I clarified this in the original question, but thank you for answering with a possible solution \$\endgroup\$
    – Frederik
    Jul 17, 2019 at 14:38

Your Answer

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

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