NPN transistor to run 12V 0.5A from 3.3v 4mA
You are correct. With a gain of 40, the 2n2222A is not right for your limited current. There are four solutions.


Replace the load with something smaller. Using a smaller relay, which  turns on the electric door lock.








simulate this circuit &ndash; Schematic created using CircuitLab


Make a Darlington Pair with two transistors. The beta will square, but the voltage drop across the base will be higher (1.4V instead of 0.7V). Just need to recalculate the resistor.








simulate this circuit


Use the 2n2222 as a switch for a PNP transistor. A 2N2907 is the typical complementary PNP transistor for the 2N2222, but any suitable PN will work. R3 is a weak pull up, R2 sets the base current for Q2 when Q1 is on.








simulate this circuit


Use two NPN as a simple switch. This inverts logic. When your output is low, Q1 is Off, so Q2 is on via R2. When your output is high, then Q1 is On, pulling Q2's base to ground, keeping it off. The default state of this, when the GPIO is not yet turned on, may result in the lock opening when the GPIO is not yet turned on.








simulate this circuit