Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
90 min
Share

Control a motor using NPN transistor

A transistor is a device that can be used as a switch. It is made from a special material and has at least three terminals for easy connection to an external circuit.

Project Video

Overview

In this tutorial, we will learn how to use a NPN transistor to operate a DC motor. It will provide the motor with the necessary power.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
2N2222 – NPN Transistor (3 pieces)
Get Item
Small Brushed DC Motor (5V 16500 RPM)
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the NPN transistor, the motor and the Arduino, as shown in the image below.

 Connections from the NPN transistor:


 • NPN emitter pin → Arduino GND pin


 • NPN base pin (middle pin) → Arduino pin 3


 • NPN collector pin → Motor first wire


 Connections from the motor:


 • Motor first wire → NPN collector pin


 • Motor second wire → Arduino VCC pin (5V)

Coding


/*
 Voltaat learn (http://learn.voltaat.com)
 Link for full tutorial:

 Tutorial: Control a motor using NPN transistor

 The function of this sketch is to control a DC motor using the Arduino with the help of the NPN transistor.
 The motor will be switched on for one second, then turned off, and the process will be repeated

 Connections from the NPN transistor:
 • NPN emitter pin → Arduino GND pin
 • NPN base pin (middle pin) → Arduino pin 3
 • NPN collector pin → Motor first wire

 Connections from the motor:
 • Motor first wire → NPN collector pin
 • Motor second wire → Arduino VCC pin (5V)

*/
//Commands inside void setup run once
void setup() {
 //Pin 3 is defined as an output
 pinMode(3, OUTPUT);
}

//Commands inside void loop run forever
void loop() {
 //Turn the motor on
 digitalWrite(3, HIGH);
 //wait for a second
 delay(1000);
 //Turn the motor off
 digitalWrite(3, LOW);
 //wait for a second
 delay(1000);
}

Testing it Out

After uploading the code to your Arduino board, you will observe the motor turning on and off every one second. You may modify this period by changing the value in the code for the delay function and trying out various outcomes.

Resources

No items found.