In this blog we will learn how to use and control a DC motor, by using a transistor, and diode. We will also use a potentiometer to control the speed of the motor. Please click here to learn how to use a potentiometer.

Components needed

  • DC motor
  • Transistor
  • Diode
  • Resistor
  • Potentiometer
  • Jumper cables
  • Arduino Uno board
  • A computer with the arduino IDE installed

What is a DC motor?

A DC motor is an electrical device that converts electrical energy to mechanical energy. The basic principle of how a DC motor works is “whenever a current carrying conductor is placed in a magnetic field, it experiences a mechanical force.”, which makes the DC motor rotate.

Why do we need a transistor?

The DC motor is likely to use more power than what an Arduino board can provide. So, if we connect a DC motor directly to an Arduino pin, it might damage the Arduino board. A transistor is used to control the amount of power a motor is consuming.

A transistor has 3 pins. The collector, base, and emitter. The power flows from the collector to the emitter. The base pin is connected to the Arduino pin which controls the the flow of the power of the DC motor from the collector to the emitter. The diagram below shows how to connect the transistor.


The base pin of the transistor is connected to pin number 3 on the Arduino board, which controls the flow of the current.

Why do we need a diode?

The diode allows the electricity to flow only in one direction. When you turn the power off to a motor, you get a negative spike of voltage, that can damage your Arduino or the transistor. The diode protects against this, by shorting out any such reverse current from the motor.

Completed circuit

The program

int motorPin = 3;
int pMeterPin = A0;
int motorSpeed = 0;
void setup() 
  pinMode(motorPin, OUTPUT);
  pinMode(pMeterPin, INPUT);
void loop() 
     motorSpeed = analogRead(pMeterPin);
     analogWrite(motorPin, motorSpeed/4);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s