An NPN transistor, the 2N2219 is commonly employed as a switch in numerous circuits. Let's have a look at how to use one in a circuit. Because the transistor is NPN, the load to be switched should be connected to the collector and the emitter to the ground, as shown in the diagram below.

How to use 2N2219
The base resistor is another key consideration when utilizing a transistor as a switch. To limit the current flowing via the base, this resistor is connected to the transistor's base pin. We know that the transistor is a current-controlled device, which means that to turn it on, we must flow some current (IB) through the base of the transistor. The required amount of current that will be used by the load can be used to compute the value of this current. Let's say the load draws roughly 800mA at most, hence our collector current (IC) is 800mA. The value of base current IB can be computed using the formula below to make this current flow through the transistor:
IB = IC / hFE
Where hFE is the transistor's current gain, which in our case is 50. The symbol will be used to symbolize the current gain in some circumstances.
In our situation, a base current of 16mA is required to pass an 800mA collector current. We can use the equations to calculate the resistor value of the base.
RB = (VCC – VBE) / IB
Where Vcc is the load's operating voltage and VBE is the voltage between the Base and Emitter, which in our case is 1.3V according to the datasheet. As a result, the value of RB will be
RB = (12-1.3)/(16*10^-3)
= ~660 Ohms
However, because the transistor will have an inherent voltage drop across the collector current, this value will not be very accurate, so getting the maximum current from the transistor will be mostly experimental. However, this formula will yield the closest value as a starting point.