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

Control a motor using the PNP 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 PNP 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
2N3906 – PNP Transistor (3 pieces)
Get Item
Small Brushed DC Motor (5V 16500 RPM)
Get Item
Half-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

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

 Connections from the PNP transistor:


      • PNP emitter pin → Motor first wire


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


       • PNP collector pin → Arduino GND pin



 Connections from the motor:


       • Motor first wire → PNP 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 the PNP transistor

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

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

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

*/
//The PNP base is connected to pin 3
#define Base 3

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

//Commands inside void loop run forever
void loop() {
 //Turn the motor on
 digitalWrite(Base, HIGH);
 //wait for a second
 delay(1000);
 //Turn the motor off
 digitalWrite(Base, 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.