Home Arduino Arduino and NPN transistor example

Arduino and NPN transistor example

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.

arduino and transistor schematic

arduino and transistor schematic

 

More commonly you will see something like the following, this time driving a 12v motor using a TIP122 darlington transistor

arduino to motor

arduino to motor

Code

 

const int transistorPin = 3;

void setup()
{
pinMode (transistorPin, OUTPUT);
}

void loop()
{
digitalWrite (transistorPin, HIGH);
delay (1000);
digitalWrite (transistorPin, LOW);
delay (1000);
}

You may also like