2
\$\begingroup\$

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!

\$\endgroup\$
  • 1
    \$\begingroup\$ "but I still didn't wrap my head around how a circuit may draw more current than what it's given" -- The GPIO pin is like a low resistance voltage source so you are given as much current as you demand until something burns itself up. It could be your voltage regulator that pops or the GPIO output resistor or drive transistor. The datasheet for the RPI should tell you the maximum allowable current from an output pin. \$\endgroup\$ – Analog Arsonist Oct 25 '12 at 18:57
3
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ So, this is what you meant, right: i.stack.imgur.com/waZX6.png ? \$\endgroup\$ – Nicu Surdu Oct 25 '12 at 17:19
  • \$\begingroup\$ Exactly! Just a sidenote: since R4 is not fed directly from Vcc, maybe you need to reduce its value a bit to make D2 brightness the same as D1. A handy thing would be to use a trimpot for both R3 and R4 so you can adjust them more easily. \$\endgroup\$ – fceconel Oct 26 '12 at 0:48
  • \$\begingroup\$ There seems to be a small problem: some current appears to flow from the emitter of the Q3 to the anode of D1 (or something else) because my D1 stays partially lit when it should be turned off, and I don't manage to find the issue. It worked before. Tried to change the transistors, thought I've damaged one, bit the problem persists. Any idea ? \$\endgroup\$ – Nicu Surdu Oct 27 '12 at 22:16
  • \$\begingroup\$ I don't think the problem comes from Q3, R4 is so high that the voltage it can produce across the LED is far from what would be necessary to make it emit light. More probably Q1 has some small power coming to its base when the switch is off (that may be by inductance, or some other side effect) and its gain is high enough to make this noticeable. \$\endgroup\$ – fceconel Oct 28 '12 at 0:14
  • \$\begingroup\$ Try using a 3-pin switch: in one position, it'll connect the resistor to the ground (like before), in the other to the VCC. That'll make sure the transistor will be shut off. \$\endgroup\$ – fceconel Oct 28 '12 at 0:18
4
\$\begingroup\$
  1. Put a resistor at the base of Q2 because it is required for D1 to turn on, otherwise it will suck up all the current that Q1 can provide and the voltage will not rise much more than 0.7V.

  2. As it stands, Q2 will try to short the power supply when turned on. Use a pnp instead, and in series with D2 and R2.

\$\endgroup\$
4
\$\begingroup\$

The major issue here as brought up already is that you are shorting your source when the switch is closed. Whenever you use a npn bjt as a switch it is good practice to place a resistor on the base for current draw since \$I_c = beta*I_b\$. You will run into a substantial current draw through Q2 since the current through R1 is \$2.6v/100ohms = 26mA\$ and depending on what your GPIO pin sources it could lead to a big current through the base of Q2 (current division) which can lead to bigger current through the BJT causing you to fry your pin. I think a better configuration would be to tie both the bases of an NPN and PNP to that pin and put the LED with a current limiting resistor in series with each BJT that way when the switch is open you will turn on the PNP and when closed you will turn on the NPN.

Note: always make sure you saturate your NPN.

\$\endgroup\$

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.