A basic requirement for digital electronics is to switch on a higher current device using the low current capable IO pins of a microcontroller.
A microcontroller is typically capable of outputting only a limited current of 90-200 milliamps (mA) across all of its IO pins. Even if you only have to light up a couple of bright LEDs that will not be enough and drawing more current than allowed could damage the microcontroller. To limit the current drawn whilst still supplying enough power to the controlled devices you need to use a device that can act as a digital switch. A transistor can fill this role, drawing only a few milliamps from the microcontroller whilst the controlled devices draw as much as they require.
There are a several types of transistors which can allow you to switch on or off anything from LEDs to motors. The decision for which transistor to use depends on how fast the switch needs to be flipped, and how much power will flow through it.
Bipolar Junction Transistor (BJT)
A BJT transistor such as the NPN BC547 shown on the right can function as a digital switch. When a small amount of power is supplied to its base (middle leg), power is allowed to flow between its collector (left leg) and emitter (right leg). When the base is grounded no power can flow between collector and emitter.
The circuit uses the 3.3V supply from the microcontroller’s IO pin, limited to 3.3mA by the 1K resistor, to allow the 5V supply, limited to 50mA by the 100 ohm resistor, to flow through the LED.
I built the circuit using the Digi Connect ME microcontroller and a breadboard:
The gator clip wires shown on the left connect up the Digi development board’s 5V supply to the breadboard’s left hand power rail. The white wire connects the first IO pin of the microcontroller (GPIO1) to the breadboard’s 1K resistor at the base of the BC547 transistor:
If you have to switch higher current loads, say to drive a motor or a pump, different types of transistors may be applicable. The BC547 has a maximum current throughput of 100mA, so it’s only suitable for small loads such as the driving this LED. In particular Field Effect Transistors (FET) may be a better choice for many higher current robotics applications.
The Microsoft .NET Micro Framework (.NET MF) C# code used to test out the circuit is here: