Learn how to use the 2N2222 NPN transistor as a switch. In this post we’ll go over how to use the 2N2222 transistor to switch a bright LED Flash on and off. We will first switch the 2N2222 using a push button, and then will transition to test with an Arduino.
The 2N2222 is an NPN bipolar junction transistor (BJT). BJTs can be used to amplify analog signals, but they can be used as switches as well. Here we’ll show how to use as a switch.
The example to show this will be based on lighting a bright LED that will need a voltage and current larger than what an Arduino UNO IO pin can supply. Transistors operating as switches work by allowing a large current to flow through the collector when a small current flows through the base. In this example the LED operates between 9V – 14.8V at a current of 15mA, which is above the voltage and current of the Arduino UNO (see below).


LED Specs:
Voltage: 9V – 14.8V
Current when lit: 15mA

Arduino UNO Specs:
I/O Pins Voltage: 5V
Current per I/O Pin: 20mA

2N2222 Standalone application
Before jumping to wiring the transistor to an Arduino, let’s try it on a standalone application where we activate the transistor with a push button. The circuit and beard board diagram below show how we’ll setup our circuit.
In this example, the current ib represents the current that will be pulled from the Arduino UNO, while ic will be the current pulled from a separate power source. For this specific example, a 4.7kohm is being recommended and we’ll use a standard 12V voltage source to power the LED. Before doing some math to show why we are using that resistor, let’s check some specific specs of the 2N2222 transistor.
*Note that the LED flash used in this example is a ready-to-use component with a built-in resistor, which is why a separate resistor is not needed.
2N2222 Specs
Minimum current gain = 35
*The gain factor (Beta) is factor by which ib will be amplified.
*Note that Beta = ic/ib.
Min Saturation voltage VBE = 0.6V
Max Saturation voltage VCE = 1.0V

Now let’s do some math
Let’s first assess the voltage drop from 12V to GND, and determine the minimum LED voltage we should expect based on the maximum expected voltage between the collector and the emitter (VCE ).

After solving for VLED_Min, we saw that the result was within the bounds of the LED operating voltage (9V – 14.8V), so we are good. Now, let’s assess the voltage drop from 5V to GND, and determine the value of the current ib.

We can see that the current ib is less than the maximum that the Arduino I/O pins can support, which is good. Now, let’s confirm the minimum current that we will be able to flow through the resistor based on the minimum current gain (remember this was 35 from the transistor specs).

The value above is higher than the current stated in the LED specs (15mA), this means that even at the lowest transistor current gain, we can still pull the required current to light up the LED.
2N2222 Testing
Now, let’s actually test this and setup a multimeter to compare the calculated values to actual values.
Base Current
Measured value: 0.91mA
Expected value: 0.94mA
*Close enough
Collector Current
I actually measured the emitter current, but iC = iE – iB. So iC = 17.61mA. The expected value was 15mA per the LED specs. The result is still acceptable.


Integrating the 2N2222 to the Arduino UNO

Click to enlarge
Arduino Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
//Arduino Code - 2N2222 int Button = 2; //GPIO 2 --- Digital Input coming from button int LED = 6; //GPIO 6 --- Digital Output to Transistor int Button_State = 0; //Variable to handle the push button state void setup() { // put your setup code here, to run once: pinMode(Button, INPUT); //Step pin as input pinMode(LED, OUTPUT); //Step pin as output } void loop() { // put your main code here, to run repeatedly: Button_State=digitalRead(Button); if (Button_State == 1){ digitalWrite(LED, HIGH); } else{ digitalWrite(LED, LOW); } } |
Testing

Components used in this example
*As an Amazon & Ebay Associate I earn from qualifying purchases.
Component | Link | Comments |
Arduino UNO | https://amzn.to/3uYVAMC https://ebay.us/veZdKX | |
Hilitchi Transistors Assortment Kit | https://amzn.to/3gf2nOl https://ebay.us/8BLbQA | Includes 2N2222 transistor |
Electronic Component Kit | https://amzn.to/3gj4r7O https://ebay.us/AdnfMw | Includes 4.7kOhm resistor, push button, and jumper wires |
Amprobe AM-510 Multimeter | https://amzn.to/32mV4Mf https://ebay.us/uwo7sC | |
Amprobe TL35B Test Leads with Alligator Clips | https://amzn.to/3dp5m4M https://ebay.us/OM4r4B | |
Breadboard (Elenco 9440) | https://amzn.to/3x23dnq https://ebay.us/FcwSdb |
This is a really excellent video, thank you for putting this on the internet. Some very clean math. This is very helpful to understand what it says on a spec sheet, thanks for making this.
You have an extensive explanation however I see no video to follow your circuit description.
This was a great tutorial for me, I’m a few months into learning electronics and I’m trying to recreate what you have done, to power a super bright IR LED from an esp32 dev board. However the maths has beaten me (I’m generally ok with basic maths, but not the principles for electronics.)
If you’re still around I’d love to get your opinion at my attempt to recreate this? I put all the details on an Arduino forum.
https://forum.arduino.cc/t/high-strength-ir-led-on-arduino-uno/1074730/10?u=madcow_uk
Many thanks.
Having some clean house between the textual content and the
pictures can enable readers to simply digest the information.