I tried experimenting with transistors for the first time and using my Raspberry Pi to try to control a higher voltage circuit. Using a breadboard, this is the circuit I tried to build (apologies for the poor hand-drawing):

Circuit diagram

My thought was that the 9V battery would operate the motor, and by having a common ground between it and the Pi, I would be able to use the Pi input to turn the transistor on or off.

About midway through, I realized that the pin voltage from the Pi wouldn't be high enough to flip the PNP transistor, but I went ahead anyway thinking that, in the worst case, the transistor would just be left continueously open. What I did not expect was that the circuit would fry my Pi entirely! (at least I was itching to upgrade it anyway :).

I'm pretty certain that I didn't inadvertantly short any pins or connect the 9V hot to the Pi's GND, so what went wrong in this circuit?

  • \$\begingroup\$ the base of the transistor has 8.4V on it. there is around .6V drop between the emitter and base. that is how you let out the magic smoke that makes all the electronic devices work \$\endgroup\$ – jsotola Dec 2 '17 at 8:14

The transistor E-B junction is forward biased from the +9V input, which puts 9V minus a diode drop on the Raspberry Pi input, which will indeed damage it. So it did exactly what we could have predicted it would do. If a fuse blew, your abuse of the GPIO probably caused the entire chip to latch up, drawing very high current and causing a silicon firestorm on a chip-wide scale as many thousands of transistors lost their lives in a matter of milliseconds.

It might have been possible to get this to work with a PNP transistor (by tying to the 3.3V supply since your motor supply is isolated) but I would strongly suggest using a logic-level n-channel MOSFET with some gate resistance in series, like 10K. The usual circuit looks like this.


simulate this circuit – Schematic created using CircuitLab

R2 is to emphasize that the high motor current flows through the wire from the battery (-) terminal to the source of M1 and not through the RPi. The Schottky diode D1 is to absorb the inductive kick when the transistor turns off.

Note: The MOSFET part number I show is an SOT-23 type. There are few through-hole MOSFETs guaranteed to work well with 3.3V drive- you can use a breakout board if you find the part a bit small to work with directly.

  • \$\begingroup\$ Thanks for this, I definitely should have read more about where the voltages were heading on the PNP transistor. Did not expect the base would be at ~8.3V at all! Will be sure to pick up a MOSFET as well when I order a new chip :) \$\endgroup\$ – bream Dec 2 '17 at 9:57

A pnp transistor at 9V would be way above the 3.3V safe voltage of your Rpi. The lack of a resistor would make the problem worse by not limiting the current to the 16mA limit of the RPi main chip.

Typically you want a low side npn driver for a RPi type board.

But this would not blow the fuse on a Rpi. Only a higher current would. Double check your circuit


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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