All About That Base Are Belong To Us: Controlling an LED with an NPN Transistor

unforeseen problemFull disclosure: I have no idea what I’m doing. If you arrived here by googling CONTROL LED NPN TRANSISTER then you probably know only slightly less about electronics than I do.

Frankly I’m not real clear on exactly what voltage is. People keep telling me charge is like a swimming pool, and the voltage is how much water pressure you have, and the current is how much water flows out of the pool, and resistance is how big the pipe is that the water’s flowing out of, but honestly that makes no intuitive sense to me. No sense at all.

Apparently resistors have something to do with Buddhism because ohms? What. Evs.

I’m a huge fan of getting things working first and understanding them later, so let’s just barrel right ahead and be willing to break stuff for science. These components are relatively inexpensive, so even if you burn a few bucks you’ve gained some knowledge from the carnage.

Here’s what you’ll need:


One. A power source. I’ve got an old 7.5V wall wart power adapter scavenged from what I’m guessing was a D-Link router at some point in the past. You can use any power source you like for this, just so long as you’re pushing somewhere around 5V. Four AA batteries will work great for this. Don’t get your power directly from the wall unless you’re seeking a new career as a fried ham.

The leads on this power supply are stranded wire, which doesn’t jam into breadboards very well. I’ve soldered them solid– not strictly necessary but helpful. If you do this yourself please don’t solder the leads while the power supply is plugged in. Is bad idea.

I’ve used blue painters’ tape to indicate the positive lead on this. Red’s the conventional color, but I ain’t got no red tape, son. Blue it is.

Two. An LED! You can buy these guys by the dozen for cheap, and some places will even sell you resistors in the package. I’m using a green LED. These tend to run somewhere around 3.3V (this matters, and you’ll see why in a moment.)

Any DIY project is improved by adding LED’s to it, so you really ought to have a few thousand of these at the ready. Making a Halloween costume? LED’s. Grade school diorama? LED’s. Bran muffins? LED’s, baby.

Three. Some resistors! Here’s why that 3.3V matters: remember that the power supply I’m using is 7.5 volts. Hook that puppy up to a dinky little 3.3V LED and kablooie– the LED will flash briefly and then die forever. The resistor’s going to limit the amount of juice flowing to the LED by turning excess electricity into heat and dissipating it into the air.


I’m using a 12K and a 5.6K resistor for this project, which I picked at random from a pile of bent resistors in the bottom of my toolbox after a 100K resistor blocked too much current to light an LED.

Voltage calculations and predictions as to whether I will eventually burn up my components are left as an exercise for the reader. EE’s are free to leave helpful comments below.

Fo’. An NPN transistor! It’s tough to buy just one of these. Here’s a pack of one hundred, so you can screw up a bunch of times. We’re going to use one transistor as an electronic switch. What you do with the other 99 is up to you.

Five. A short length of hookup wire. Pretty much anything conductive will work for this– don’t worry about gauge as we’re not exactly building a space probe here. Use a paper clip if you’ve got nothing else.

Six. A solderless breadboard! (not pictured) You’ll probably want at least three of these in your house so that you can leave half-finished projects assembled while you attend to more pressing duties, but you only need one for this project.

The Basic LED Circuit

Let’s assume that you’ve never done this before. We’ll wire up a basic LED circuit to build confidence and then move on to adding the transistor.

Step 1: Connect the power to the breadboard. Plus to plus, minus to minus.

power hookup

Step 2: Connect the 12K resistor to the + strip and somewhere else on the breadboard. We’ll use a second resistor later when we want to avoid frying the transistor.

add resistor

Step 3: Connect the long lead of the LED to the free end of the 12K resistor.

add LED

Step 4: Connect the short lead of the LED back to ground with a piece of hookup wire.

LED circuit

And if all goes well, you should have glowing LED, with brightness dependent on your combination of resistor and power source.

So that’s LED’s 101. I still don’t know how this relates to swimming pools.

The Transistor Circuit

Let’s complicate things just a bit by adding the NPN transistor. Pro tip: It’s always helpful to remove all cats from the work area.


Let’s not dwell on the difference between NPN and PNP transistors: there are plenty of other places on the internets to explain that, full of confusing diagrams and weird-ass equations. For morons at our level it’s enough to understand that when electricty touches the middle pin of an NPN transitor, current flows through the transistor. Otherwise, the transistor acts like a closed gate, and no electricity passes through it.

I’m using a 2N4401 transistor, but any NPN should work for this little tutorial.

Step 6: Take out the LED and hookup wire and insert the transistor so the curved side is facing away from you.

add transistor

Step 7: Connect the long lead of the LED to the rightmost leg of the transistor. Wire the transistor’s leg back to ground with your little piece of hookup wire. If you’re fortunate, nothing will happen.

wire to ground

The LED should still be dark, but if it’s glowing dimly then (I guess?) a little bit of current is passing through the transistor. You can use a more powerful resistor or lower your input voltage by swapping out your power supply.

Or just plow on ahead and don’t worry about incinerating your components. That’s what I’d do.

Step 8: This is where the magic happens! We’re going to apply current to the transistor’s middle leg, which will permit current to flow through the transistor and light up our LED.

transistor circuit

Just to be on the safe side I put my 5.6K resistor in between the source voltage and the transistor’s middle leg. Of course you could read the datasheet and know for sure how much voltage that middle leg can handle (spoiler: it’s 6V read Andy’s comments below) but reading datasheets is for suckers who didn’t buy a 100-pack of transistors.

This Circuit is Stupid

Yeah, I know. But it’s a proof of concept, right? Instead of keeping an LED lit (lame) one might be using this transistor with an Arduino digital pin wired to the middle leg. One could toggle massively interesting circuts by writing HIGH or LOW to the circuit from the Arduino.

Or, OR! In theeeeeeeeeeory, one could use this basic circuit to resolve conflicts among I2C devices with identical hardware addresses by interrupting the SCA signal, if one had accidentally purchased A TSSOP multiplexer and SOIC breakout boards and had a week to kill while the proper components were being shipped to his lab and needed to feel like he was making forward progress on some front for the love of Pete, because none of us are getting any younger, you know, and Time is the enemy.

I’m not saying that happened. But it could have. In theory.

#staytuned, my friends. Lao Zheng out.

2 thoughts on “All About That Base Are Belong To Us: Controlling an LED with an NPN Transistor

  1. Andy

    (spoiler: it’s 6V)

    Alas, no. You won’t be able to raise the base potential to more than about 1.2 volts without killing the transistor. The 6 volt number is the maximum reverse potential – meaning it can be minus 6 volts without killing the transistor.


What do you think?