Electronic – Transistor question and is the circuit safe for Raspberry-Pi

raspberry piswitchestransistors

This is my first circuit designed from scratch (that actually does something interesting), so please be patient with the beginner's mistakes (and maybe point them to me).

My circuit is the following:

circuit

What the circuit does is:

  1. When switch SW1 is open, the D2 LED turns ON and the D1 led turns OFF
  2. When switch SW1 is closed, the D2 LED turns OFF and the D1 led turns ON (they switch state)

Most probably this circuit has a common name (astable ?) but I don't know it.

I've tested the circuit at 9V (with R1 & R2 at 470 ohms) and it workes like a charm.

This circuit will be used with Raspberry-Pi's GPIO. Basically, the SW1 will be replaced by a GPIO pin.

My questions are:

  1. Is it ok what I did there with Q2 by not using any resistor for the base ?
  2. Considering that the GPIO pin will create a -3.3V drop when ON and the GPIO on Rasperry-Pi has no protection (AFAIK) and the 3.3V is supplied by the Raspbery-Pi itself: is this circuit safe for my Raspberry-Pi ? I've read in some place that by drawing to much current from GPIO may brake the device, but I still didn't wrap my head around how a circuit may draw more current than what it's given 🙁

Thank you!

Best Answer

About the question 1, it is not necessarily wrong provided that you have a load between its collector and the positive or between its emitter and the negative, and its impedance is high enough to reduce the current through the transistor. That's the main problem here: Q2 is shorting the battery, which will probably result in one of two things: fry the transistor or exhaust the battery (or maybe both).

So my advice: put the LED and the resistor in series with Q2, not in parallel, and use a PNP transistor for Q2 instead of an NPN.

About the question 2, if you want to wire a GPIO to the circuit to replace the switch (i.e. connect it to the 100K resistor), I don't see a problem, the resistor is high enough to limit the current drawn from the board.

It could be a problem if you tried to power an LED directly from the GPIO.

Of course you'll have to remove the switch, because if it is closed when GPIO is high, you'll be shorting the GPIO output to the ground.