The formula
To use a bipolar transistor as a switch, you drive it into saturation, so it drops only a few tenths of a volt and stays cool. Datasheets give the saturation voltage VCE(sat) with the base current set to a tenth of the collector current, so a forced gain of 10 is the safe design choice:
IB = IC ÷ 10 and RB = (Vdrive − VBE(sat)) ÷ IB
Pick the next standard value below the result, so the base gets at least the current you designed for.
Check the pin can supply it
10 mA is a lot to ask of some microcontroller pins. An Arduino Uno pin is fine: the ATmega328P's absolute maximum is 40 mA per pin, and 20 mA is the usual design limit. A Raspberry Pi Pico pin is set to 4 mA drive strength by default, and its voltage sags if you draw more. For loads over about 100 mA from a 3.3 V board, a logic-level MOSFET is usually the better choice: its gate draws almost no current. See transistors as switches.
Things to know
- If you only need a light load, you can use a lower forced gain, as long as the base current is at least two or three times IC ÷ hFE(min). The tool shows that margin.
- Relay coils, motors and solenoids need a flyback diode across them (cathode to the positive supply), or the voltage spike at switch-off can destroy the transistor.
- Check the transistor's maximum collector current and power: P ≈ VCE(sat) × IC.
- Put the load between the supply and the collector, with the emitter to ground (low-side switching). The grounds must be common.