Electronic – arduino – How to control the speed of a 12V DC motor with an Arduino

arduinodc motortransistors

I'm trying to figure out how to control the speed of a 12V DC motor with an arduino and a 12V battery.

I want to split the «power» and «control» parts of the circuit so the Arduino and sensors receive only 5V.

So far, this is what I've tried :

enter image description here

I am able to control the speed of the motor by changing the PWM of pin 3 on the Arduino. This opens the NPN transistor (BUF654).

The problem is that the speed of the motor doesn't change enough.

From 0% to 50% PWM on pin 3, the motor is stalled.

Above 50%, the motor is nearly reaching its maximum speed.

I wonder if I would be able to have a linear variation :

0% - 10% : very slow
10% - 20% : slow
20% - 50% : normal speed
50% - 80% : fast
80% - 100% : RELEASE THE KRAKEN!

Here are the voltage and current the motor draws when using only a battery, or the previous circuit :

+----------------------------+---------+--------+
| Directly on 12V battery    | 12.7 V  | 61 mA  |
+----------------------------+---------+--------+
| Arduino circuit (100% PWM) | 12.47 V | 60 mA  |
+----------------------------+---------+--------+
| Directly on 9V battery     | 9 V     | 54 mA  |
+----------------------------+---------+--------+
| Arduino circuit (60% PWM)  | 9 V     | 52 mA  |
+----------------------------+---------+--------+

What have I done wrong? Could the problem come from my motor?

Best Answer

Your diode is in the wrong position- it should be across the motor (blocking!) not across the transistor.

The purpose of the diode is to allow current that is flowing in the motor coil to continue to flow in the same direction when the transistor turns off. When the transistor turns off, the voltage at the transistor collector will rise as it was flowing out of the motor. From \$V_{CE(SAT)}\$ it will rise above the power supply voltage and stop only when the transistor breaks down (or when it starts to ring with parasitic capacitance). By putting a diode from the transistor collector to the +12V rail, you prevent the voltage across the transistor from exceeding 12V and and allow the motor current to continue to flow.

The way you have the diode in your pictorial, it would only conduct were the voltage to go below ground. That could only happen if someone mechanically spun the motor very fast in the reverse direction (and your diode would cause the voltage on the 12V rail to increase as a result).