The circuit shown here uses a NPN transistor connected to a an Arduino output pin to switch an LED pin, obviously this is just an example. In real life you would perhaps switch a relay, lamp , fan or a buzzer. A darlington transistor could be used to drive a motor for example.
In this example we use the 5v from the Arduino but in real life again the device that the transistor is driving may have its own seperate power supply and frequently they do particularly the examples mentioned earlier.
The example we will show is quite basic we simply send a low or a high to the base of the transistor and in turn the LED will either switch on or off.
More commonly you will see something like the following, this time driving a 12v motor using a TIP122 darlington transistor
Code
const int transistorPin = 3;
void setup()
{
pinMode (transistorPin, OUTPUT);
}
void loop()
{
digitalWrite (transistorPin, HIGH);
delay (1000);
digitalWrite (transistorPin, LOW);
delay (1000);
}