Control a motor using the PNP transistor
You may have heard of the transistor, and you may have also learned that it is a major reason for the technological advancement we are now witnessing.
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.
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.
Overview
The transistor has three pins: the base, the collector, and the emitter.

The base pin receives the control signal from the Arduino, while the emitter is connected to one of the motor wires to control it. The collector pin will be connected to the Arduino GND pin to complete the circuit.
PNP transistors are normally switched "on" (allowing current to flow), unless the signal that is applied to the base is high.
That means when the base receives a high signal from the Arduino, your motor will be turned off. But when the base receives a low signal, your motor will be turned ON.
By now you must have understood how we will use the PNP transistor to control a DC motor. Let's discover more together! how we can use the PNP transistor to control a DC motor, we can begin to assemble our circuit.
Getting the items
For this project, you will need the following components, you can buy them from our store.
Wiring it up
To set up the PNP transistor with the motor in the correct way, follow the instructions below. The image demonstrates how to connect the wires between the PNP transistor, the motor, and the Arduino. Once they are connected to each other, connect the Arduino to your computer using the USB cable.

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
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.
This code is straightforward, and there is no need for libraries.
Let's put it to the test together!
/*
Voltaat learn (https://www.voltaat.com/pages/voltaat-learn)
Link for full tutorial: https://bit.ly/3CJiFbG
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.
What are your thoughts on the ideal application for this project?
Related Tutorials
A soil moisture sensor is a device that measures the amount of water in the soil. The sensor consists of two metal probes that can be inserted into the soil to measure the moisture levels.
Most of us are familiar with the switches used in household devices. A relay is a type of switch that can be connected to an Arduino or any other microcontroller.
The ultrasonic sensor is a device that can measure distance by sending out sound waves and calculating how long it takes for them to bounce back.