Transistor base resistor
The base is a small lever that moves a big load. The resistor sets how hard you push the lever; pushing a few times harder than needed keeps the switch firmly closed.
Ib = k × Ic / hFE Rb = (Vin − Vbe) / Ib
Saturated NPN low-side switch. Uses the minimum hFE and an overdrive factor so the transistor turns fully on. Check the pin’s current limit, the collector current rating and add a flyback diode for coils.