that resistor shouldn't be 10k
Um, assuming that somebody just threw in 10k and didn't bother to calculate what the value should be, then it's misleading at best (ie, always use 10k) and won't work at worst (I realize that 10k might be the correct value for some choices of transistor, relay and microcontroller). This isn't just a pull-up or pull-down resistor. It matters what current is going through it, because the same current ends up going through the base of the transistor.
It'd be great if the original author of the jpeg would modify it to just say R and then we could put the formula for figuring out what it should be in there.
And then we could add the following text, although it sort of belongs in a transistor section or page:
If you have a microcontroller and you want to have it control an NPN transistor, you need to have a resistor in series with the base of the transistor. This is to get the voltage from the microcontroller's output level down to what the transistor wants (about 0.6V). Another way of thinking of it is to get the current through the resistor (and hence through the base) correct.
In the following description, is the driving voltage from your microcontroller's output (for example, 3.3V), is the voltage the transistor wants across the base-emitter (usually about 0.6V), is the current the relay needs running through it to be turned on (for example, 100mA), and 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 across the resistor, and if your relay needs a current to switch, then your base-emitter current should be (with the factor of 2 as a safety margin, remember the emitter-collector current can only be up to 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: , which we rewrite as and then get . 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 .
well, the <math></math> latex markup syntax seems not to to be working for me... Could someone enable that feature? The same markup works at my wikipedia sandbox: http://en.wikipedia.org/wiki/User:Mzandrew/Sandbox
Using 10k makes the current too small, so the relay might not be driven or not driven reliably.
The diode is a nice touch though.
Mzandrew 14:05, 2 September 2007 (PDT)