Tutorial – Control DC Motor with a Transistor

Tutorial – Control DC Motor with a Transistor

In this Tutorial you will learn how to control a DC Motor with a transistor and an Arduino Board!

We already explained how to control a DC Motor with a dual H-Bridge Driver. Today we will do it with a Transistor.

It will be easy to do the schematics and also to write the code to control the motor!

Let’s see how to control a DC Motor with a transistor!

What you need

  • LiPo Battery 3.7V
  • Arduino Board
  • Transistor
  • Diode
  • Resistor
  • DC Motor

That’s what you need to follow this tutorial. You can use also compatible components.


This is the schematic. We put the diode to avoid that when you shut down the motor, it generates a current that may damage the other components.

Transistor Schematic

As you can see from this schematic, we will just use a digital Arduino pin and the GND to control the motor.


That’s the Sketch for this Tutorial. Very very easy, you will change the transistor input value with an analogWrite.

First of all we declare a variable for the motor pin, then in the setup we set the pin as output.

In the loop we just make a for to increase and decrease the motor speed. The analogWrite function is used to change the voltage in the transistor. Changing the voltage in the transistor changes the motor speed.

const int motorPin= 3;
void setup()
  pinMode(motorPin, OUTPUT);
void loop()
  for(int i=0; i<360; i++)
    analogWrite(motorPin, i);

Copy and Paste the Sketch, then upload it! You will see the motor start after a few moments. It will reach the max speed, then it will slow down.

Hope you liked this tutorial!!

Don’t forget to follow us on Instagram and Twitter and to enable notifications!!

Davide Busco

Davide Busco is an engineering student at Federico II University of Naples. He uses his passion and studies to create his projects. He loves be a maker and spread his knowledge. Moreover he has gained the second place in a national makers-tournament between Italian's Universities.

Leave a Reply

Your email address will not be published. Required fields are marked *