Why do you need 2 resistors when hooking up a transistor as a switch
There are two possible reasons:
- As others have said, R2 acts as a pulldown in the case where the left end of R1 is left floating. This is useful in when whatever driving R1 might go to high impedance.
- As a voltage divider. The B-E voltage of a silicon bipolar transistor is around 500-750mV when on. In some cases you might want a higher threshold for the control voltage to turn on the transistor. For example, if R1 and R2 are equal, then the transistor will start coming on at twice the voltage it would have without R2.
The R2 resistor is used to bring the voltage on the base into a known state. Basically when you turn the whatever source of current you have at the other side of R1 off, the whole line would go into an unknown state. It may pick up some stray interference and that may influence the operation of the transistor or the device on the other side or it may take some time for the voltage to drop just with just the transistor base. Also note that the source of the current going through R1 may leak and that may affect the way transistor operates.
With the R2, which is in configuration called pull-down resistor, we are certain that whatever excess voltage there may be in the branch containing R1 will be safely conducted into ground.
In addition to the reasons that Olin has mentioned, there's one more: R2 ensures that the transistor turns off rapidly.
Let's suppose you have a source which is not a switch, but a TTL circuit like a 74LS04. TTL circuits (at least the TI SN74LS04) have a minimum output high voltage of 2.4V and a maximum output low voltage of 0.4V. And suppose that R1 is 1K, and the Vbe "on" drop is about 0.6V.
That gives you a 1.8mA (=(2.4V-0.6V) / 1K) current to turn the transistor on, but only -0.2mA to turn the transistor off. Bipolar transistors do have parasitic capacitance that needs to be charged / discharged (not quite the same behavior as MOSFETs).
Now put R2 = 1K: this pulls 0.6mA out of a Vbe=0.6V transistor, yielding a turnon current of 1.2mA and a turnoff current of -0.8mA, so the turnoff behavior will be faster.