simulate this circuit – Schematic created using CircuitLab

I am trying to make a simple switch with the 2N2222, so i can send 5 volts from a 3.3 V output pin on an arduino/raspberry pi.

I have constructed the circuit in the simulator, and it works.

In the real circuit, instead of VM1, I have placed a LED where the positive is after the diode and the negative is connected to ground.

So i was expecting, when i close the switch then the led should close instead of this the real circuit keeps the led on and the voltage is the same.

What do i miss here? Probably it is something very easy but i can not figure it out.

  • 1
    \$\begingroup\$ The base floats when your switch is open. \$\endgroup\$ Commented Jan 8, 2020 at 12:32
  • 2
    \$\begingroup\$ Perhaps I was not clear enough; you need to keep the 1.2k series base resistor and add a 10k resistor from the base to ground. \$\endgroup\$ Commented Jan 8, 2020 at 13:21
  • 1
    \$\begingroup\$ What does "not work" mean in this last case? Didn't turn on, or won't turn off? \$\endgroup\$ Commented Jan 8, 2020 at 13:46
  • 1
    \$\begingroup\$ The Circuitlab simulation runs perfectly. Open the switch and run it, then close the switch and look at the difference. \$\endgroup\$ Commented Jan 8, 2020 at 13:50
  • 1
    \$\begingroup\$ Come on -- you keep changing things!!! Put your LED where it belongs -- in series with the emitter, where D1 is. \$\endgroup\$ Commented Jan 8, 2020 at 14:42

1 Answer 1


Your original question was confusing. I have edited your question, hopefully to make it clear. So what you are building is a transistor inverting switch, and you want to turn the LED (D2) on and off by shorting it via the transistor, and the transistor is controlled by an output pin of an Arduino or Raspberry Pi.

There are several potential problems,

  1. Make sure your real circuit is identical to your schematics, and your wiring is correct. You can move the voltmeters to anywhere you want, but not other components. Nothing can be answered if you are working on a different circuit than what you've showed here.

  2. When your output is HIGH, are your 3.3 V output sourcing enough current to turn the transistor on?

    • Measure the voltage between your output and ground, you should see 3.3 V if the output is HIGH.

    • If you are using a 1200 ohm resistor, the base current is approximately 2 mA (3.3 V / 1200 Ω = 2.75 mA, without considering the pull-down resistor and emitter resistance). So you should be able to see roughly a 2 V voltage across your base resistor R1, similarly, between the collector of the transistor and ground, you should see a very low voltage, less than 1 V.

    • If you are not seeing what you expected to see, it means your output is not sourcing current correctly, or the transistor is defective, try another transistor first (it's unlikely to solve your problem, but better to double check). To isolate the potential problem of the output pin and programming, disconnect your R1 from the output, and try using a jumper wire to connect R1 directly to the 3.3 volt power pin (remember, do not remove R1), and see if you can turn the LED off.

    • A common mistake in microcontroller is forgetting that the pin was set to INPUT, then attempting to use it as an OUTPUT. It may appear to work when you probe it with a high-impedance voltmeter or scope, but it cannot source any current.

  3. If you are building a low-side switch to turn D2 on and off, why did you put the D2 between collector and ground? If the transistor is on, R1 & D1 are shorted to ground by the transistor, and the current consumption is 400 mA, (5 V - 0.7 V) / 100 Ω = 430 mA. If your transistor is off, R1 & D1 are connected to ground by D2, and depends on the color of the LED, the current consumption is (5 V - 0.7 V - 2 V) / 100 Ω = 230 mA or so. You are wasting power for no reason.

    • Normally, NPN transistor is used as a low-side switch, the load you are trying to switch is connected between the +5 V and collector.

    • Similarly, what is the purpose of D1? Are you trying to use D1 to drop additional voltage to light the LED? Why can't you use a bigger resistor? Because you can't find it?

  • \$\begingroup\$ When i set the base to 3.3v with the resistor etc shouldn't the led turn off? this is the question. i understand that the pins in arduino... have pull -up or pull-down so Low mean ground and high means 3.3v. but my problem is not that the led is turn off with i have a LOW in output pin but that the led does not turn off when i have HIGH in the output pin \$\endgroup\$
    – kyrpav
    Commented Jan 8, 2020 at 13:58
  • \$\begingroup\$ @kyrpav So what you are trying to say is, the simulation works, but the real circuit doesn't work. Is it correct? \$\endgroup\$ Commented Jan 8, 2020 at 14:11
  • \$\begingroup\$ yes this is the case \$\endgroup\$
    – kyrpav
    Commented Jan 8, 2020 at 14:19
  • \$\begingroup\$ like a not gate \$\endgroup\$
    – kyrpav
    Commented Jan 8, 2020 at 14:32
  • \$\begingroup\$ Thank you ,probably by trying to make the question simple i made it worst. I am trying to build a not gate using 2n2222 . so i can trigger the 2n2222 with 3.3v from arduino/raspberry and by this i can trigger a relay board that the enable pin has a negative logic. So the relay board that i try to control need 5v to close then Ground to open my relay. And by these i tried to create this not gate so when i open the pinout of the controller then the enable pin of the relay goes to ground and the relay opens.Ofcourse the opposite part when the microcontroller goes to LOW the enable pin will get 5v \$\endgroup\$
    – kyrpav
    Commented Jan 8, 2020 at 15:42

Your Answer

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

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