# User:Mzandrew/Sandbox

In the following description, ${\displaystyle V_{microcontroller}}$ is the driving voltage from your microcontroller's output (for example, 3.3V), ${\displaystyle V_{base}}$ is the voltage the transistor wants across the base-emitter (usually about 0.6V), ${\displaystyle I_{relay}}$ is the current the relay needs running through it to be turned on (for example, 100mA), and ${\displaystyle h_{fe}}$ is the current gain of the transistor (usually about a factor of 100, so if you have 1mA going through the base of the transistor, you can get up to 100 times that, or 100mA through the emitter/collector).
You need to drop a voltage ${\displaystyle (V_{microcontroller}-V_{base})}$ across the resistor, and if your relay needs a current ${\displaystyle I_{relay}}$ to switch, then your base-emitter current ${\displaystyle I_{base}}$ should be ${\displaystyle I_{base}={{2I_{relay}} \over {h_{fe}}}}$ (with the factor of 2 as a safety margin, remember the emitter-collector current can only be up to ${\displaystyle h_{fe}}$ times the base-emitter current and we don't want to design it to be on the edge of just barely working). We have a voltage and a current, so we use Ohm's law to get the resistance: ${\displaystyle V_{resistor}=I_{resistor}R}$, which we rewrite as ${\displaystyle R={{V_{resistor}} \over {I_{resistor}}}}$ and then get ${\displaystyle R={{h_{fe}(V_{microcontroller}-V_{base})} \over {2I_{relay}}}}$. So, punch your components' values in to that formula and you'll get the resistor value to use.
Example: Using the common values stated earlier, we get ${\displaystyle R={{100(3.3V-0.6V)} \over {2(100mA)}}=1350\Omega }$.