Controlling a LED directly using a port is fine in most cases, because a LED only requires a small current that can be supplied by the Netduino. But when controlling components that require more current (like high-power LED’s, motors, relays, etc.) a transistor is needed. The transistor is controlled by a small current from the MCU and the transistor controls the heavy load. While transistors actually work as amplifiers, they can also be used as switches.
Transistors exist in a few main types, like bipolar (either NPN or PNP) or FET. For our purpose almost any popular bipolar transistor will work. For each main type, there are many different types to select from. Examples for NPN types are: BC547, BC548 or 2N222. Examples for PNP are: BC557, BC558 or 2N2907. I picked the BC547, a NPN type, and will use it in my example which will simply control a LED. You can use the source code from the blink example in the Netduino Getting Started document.
The schematic shows a LED, again with a resistor to restrict the current through the LED. They are connected to the collector of the transistor, while the emitter is connected to ground (or common or 0V). When the transistor is switched on, current will flow through the transistor from the collector to the emitter. This current will also flow through the resistor and LED, so the LED lights up. When the transistor is switched off, no current will flow and the LED remains off. Switching the transistor is controlled by a current through the base. The base is connected to a NetDuino port through a resistor. And yes, the resistor is there to restrict the current. Since the current is only needed to switch the transistor and not to light up the LED a small current will suffice. A high level (true) on the NetDuino port will cause a current at the base, which will switch the transistor on and the LED will light up.
The above is of course a simple (but working) example. Each specific transistor type (BC547, BC548, etc.) has its own specifications, although many can be used in a similar way or even as a replacement in a situation as simple as this.
Since the Netduino ports are at 3.3V, when set high and the base-emitter voltage is 0.7V (which is the case for most transistors), the voltage-span over the resistor is 2.6V. This gives a 0.5 mA current (I = V/R => 2.6V / 5.6KΩ = 0.46 mA) through the resistor and at the base.
A PNP transistor, like the BC557 below, can replace the BC547 in the schematic above. Although, because of the different behavior of the PNP transistor, the LED will be off when the port is high and the LED will be on when the port is low.
On a PNP transistor the collector is drawn with an arrow inwards. On a NPN transistor the arrow is outwards on the emitter.
Connecting the transistor
A transistor is almost always part of a larger circuit, as it is not much use by itself. The easiest way of putting such a circuit together with the Netduino is using a breadboard or a breadboard shield. If you want to know more about using a breadboard, there are lots of online breadboard tutorials.
To connect any transistor in the right way, you'll need to know which pin is which. The datasheet for the transistor of your choice will help you out. Just google/bing the type and 'datasheet'. Below is a part from the datasheet of the BC547.
Next: dimming a LED.