Introduction: Make a PWM Motor Speed Controller

Microcontrollers such as Arduinos are a great way to control your custom electronics projects. Unfortunately the digital pins have a max output of 40mA, and this isn’t enough to power most motors. This is where a motor controller shield can come in handy. But these are expensive to buy, and only let you control a few motors, especially if you are embedding them in a project.

The simplest kind of speed controller uses a Pulse Width Modulation signal to set the speed of the motor. This signal can be generated by any of the Pulse Width Modulation pins on an Arduino. So we need to use an external power source (such as a battery pack) and a transistor switching circuit. This is similar to the transistor circuit on a relay shield, but we made a few changes. I included an LED for a visual indication on the output.

In this project, I am going to show you how you can make your own simple motor controller.

This is a remix of Jason Poel Smith's "How to Make Custom Shields for Your Microcontrollers" Instructable, and I remixed the Motor Driver Shield. Please vote for it in the Remix 2.0 Contest!

Step 1: Tools and Materials

Here are the materials and tools that you will need for this project.

2x NPN Power Transistor (such as tip31a)
2x IN4001 Diode
2x 1K Ω Resistor
2x 100 Ω Resistor
2x LED in your choice of color
2x 2 x 1 Female Headers
1x 1 x 4 Female Header
1x Battery Connector
1x 30 Gauge Solid-core Wire
1x Perfboard

There are two of almost everything because we are making two motor speed controllers on one PCB. You can easily make only one circuit by cutting the double materials in half and using the schematic.

Soldering Iron and Solder
Wire Cutters
Wire Strippers
Needle Nose Pliers

Step 2: Solder the Transistors

Start off by soldering the two power transistors on the PCB. Leave space between the two to make room for the other components. Don't trim the leads yet. After we make the connections to the transistor then you can cut off the leads. Take note of the transistor pinout above to avoid making the wrong connections. To get a better understanding of the circuit and how it works, it might be a good idea to prototype the circuit on a breadboard first.

Step 3: Solder the Small Female Headers

Solder on the small 1 x 2 female headers. Alternately, you could use screw terminals (I ended up switching the two out a the end) for an easier connection. Again, leave space between the headers and transistors for other components.

Step 4: Solder the Diodes

Solder the diodes on to the prefboard, in front of the small headers. Connect the diodes to the headers as shown in the 3rd above picture. This will prevent the motor from delivering high current to the board and ruining it. Trim the leads on all diodes. Ideally you should have the silver strip facing the top of the board, to make wiring the board easier.

Step 5: Solder the LEDs

Solder on the LEDs in the back of the small headers. Any color you choose should work. You do not need to trim the leads or do any wiring yet. Keep in mind where you placed the anode and cathode for each.

Step 6: Solder the Base Resistors

Solder the 1K resistors to the base (pin 1) of each transistor. Leave room in between the resistors, and do not connect it to anything. Cut the base lead and the resistor lead connected to it.

Step 7: Solder the LED Resistors

Solder the 100Ω resistor on the perfboard, with one of the leads connected to the LED's anode (longer lead). Trim the one resistor lead and anode lead.

Step 8: Connect the Resistors in Pairs

Connect the lead from one of the LED resistors to one of the transistor resistors. Trim off the lead from the LED resistor only. Repeat with the other 2 resistors to make 2 resistor pairs.

*Remember*** which resistor is connected to which! These pairs will always be separate; we are making 2 motor controllers!

Step 9: Solder on External Power Supply Wires

Solder on the Power Supply wires. You can connect this to the power source of your choice (keeping in mind the motor and microcontroller volts and current). I connected a 9V battery clip so it can connect to a 9V or 12V source. Tie a knot near the base to prevent it from being pulled out.

*Optional*** drill a hole to slip the wires through to insure it will not come out.

Step 10: Solder the Large Female Header

Solder the large female header on to the board, in the upper hand left corner. Connect the positive wire from the power supply to the farthest pin on the left (looking at it with the header in the upper left hand corner). Connect the negative Power Supply Wire to the pin next to the positive pin you just soldered. I used red wire for positive connections and blue for ground connections.

*Note*** This can be used to power a microcontroller or other accessory, and you can also use it as a power input if you wish to not use the attached Power Supply wires!

Step 11: Connect the PWM Inputs

Connect the resistor connected to the Base (pin 1) of the Transistor to 1 of the available pins on the large header. Do this for the remaining resistor, connecting it to the last available pin. This large header will serve for inputs/outputs. Connect a PWM pin to the PWM input pins you just soldered, and use the power supply pins as an output or input for power. I used white wire for these connections

Step 12: Ground Connections

Connect the two Emitters of the Transistors (pin 3) to ground. Connect the two cathode leads of the LEDs to ground. Trim the Emitter leads and LED leads. I used blue wire for ground.

Step 13: Connect Motor Pins to Power

Connect the positive wire to the solder joint closest to the silver strip on the diode. Look at the pictures for reference, as this part can get tricky. Do this for both sets of headers.

Step 14: Connect Motor Pins to Collector of Transistor

This is where remembering the pairs of resistors you made comes in handy. Choose a Motor connection header pin and figure out what transistor the LED near said header pin is connected to. Once you have done that, connect a wire from the remaining solder joint on said header pin and connect it to the collector (pin 2) of the transistor, that you just determined the LED is connected to. Trim the lead on the transistor, and repeat this for the other header and transistor. Use the pictures for reference.

Step 15: Upload the Code

Now you have a simple motor controller shield. You can set the speed of the motor by sending an analog write command to the base of the transistor. Download and then upload the sample Arduino code given below to an Arduino board of your choice to test the motor controller. Try playing with the numbers and code to get comfortable using the speed controller.

To use this with other microcontrollers, make sure it has a PWM output, and set the output to match the required speed. If you do not know how to do this, find a sample code for controlling an LED, and change the code to serve your needs. Basically, you can somewhat think of this as controlling an LED; it takes the PWM signal and controls the motor with a higher voltage and current.


SophaN (author)2016-11-15

Clearly detail Thanks

Guidoramacciotti (author)2016-08-15

Hi. Can I use this controller with an rc receiver by connecting ir to one chanel?

anuj1993 (author)2016-02-29

Can someone help me with controlling a 600W 36V PMDC motor??

I guess it will need atleast 30amps

nemeen (author)anuj19932016-07-11

Use MOSFET based PWM speed controller I am soon making one with P30nf10 MOSFET

DylanD581 (author)nemeen2016-07-12

That's awesome! I'd love it if you posted pictures here, when you finish your version.

DylanD581 (author)anuj19932016-02-29

Hi Anju - I don't have much experience with controlling motors this large, but I do know this controller would not work. Also, your motor should only draw around 20 amps. I did find a pre-made motor controller, which I posted the link to, below. I hope this helps, and feel free to shoot me any other questions you have.

aakashsunkari (author)2015-09-03

At first I thought the transistors were 5v regulators. :-\

Good that I read the instructions

aakashsunkari (author)2015-09-03

Hi Dylan it's me (you know who!)

I voted for you ;-)

T_Maine96 (author)2015-09-02

I bought mine from here:

I used it for a Van De Graaff Generator

Cappire (author)T_Maine962015-09-02

I've seen those! I bought the more advanced version from them, the "OCX"

zeropt (author)2015-08-30

I like your design. Nice layout and pictures.

DylanD581 (author)zeropt2015-08-30

Thanks! I think it is pretty good for a first Instructable.

Edmorbus. (author)2015-08-19

i can not download

Motor controller code please help

BeachsideHank (author)2015-08-17

I need to juice a 200 watt 24 volt d.c. motor, will this circuit handle that load? Thanks.

nqtronix (author)BeachsideHank2015-08-18

200W at 24V is about I=P/U=8.33A. The TIP31 is ratet at "3A collector current", so no, it won't work. Also the gain decreses at high currents, the 1k resistor at the base limits the maximum current to about 0.5A.

A better choice is a n-channel mosfet. It needs to be at least rated V_DS = 30V and I_D > 8.33A. It should also conductive at 4.5V, or 3V if you plan to use a 3.3V Arduino, so called "logic level" types. There are MANY parts which fit these requirements, such as Sparkfuns FQP30N06L or Adafruits IRLB8721. If you can choose pick the one with the lowest RDS_on (on-resistance) at your control (gate) voltage (thus the IRLB8721 is better). This will reduce the generated heat and so the required minimum size of the heatsink.

The circuit needs to be slightly modiefied (picture attached). The resistor connects the gate with ground to keep the mosfet switched off, even if the microcontroller is in reset. The two transistors are a simple amplifire to increse the current capability of the I/O pin up to 1A peak. A mosfet only needs current while switching and it will switch faster if it gets a lot of current. Faster switching reduces the switching losses so less heat is generated. The capacitor provides the energy to switch the mosfet. You can leave the transistors away, but I strongly recommend them. You also need to replace the flyback diode with a more powerful one, I'd suggest a schottkey diode in a to220 package. Almost any will work, just make sure it can handle the 8.33A.

May I ask what thy of project you have in mind?

simple motor driver.png
BeachsideHank (author)nqtronix2015-08-19

Thank you very much for a most comprehensive reply, you have offered a circuit that will no doubt handle my need. I published an Instructable on using a scooter motor on my 1950 Duro drill press:

It works fine for small bits, but if boring with larger ones, a reduced r.p.m. is more efficient and less liable to burn off the bit's temper. There was a controller with the motor, but it was tricked out for battery operation, with overvoltage/ undervoltage sensing, Hall effect throttle, deadman switch (brake) etc. that made it too difficult to reuse for my purpose, I just wanted something fairly simple to adjust the speed other than playing with pulleys or going with a V.F.D. and 3- phase motor, - of which I would have to purchase. The d.c. motor got me very close to what was needed, only the controller was eluding me.

R3VERSE (author)BeachsideHank2015-08-18

Or probably go for a MOSFET like the IRFB4710 which can handle 100V and 50A+

pfred2 (author)BeachsideHank2015-08-17

You might have to parallel several devices for that. 200 Watts is a lot, even for power components. Of course to get power handling capacity you should also heatsink your power parts too. That is what the hole in the tab of these TO-220 body parts is for. So you can screw them down to a heatsink. Be aware though that most TO-220 package parts the tab is connected to the middle pin. So if you do not insulate between the part, and the heatsink, the heatsink will be electrically connected to the middle pin of the part too. To fully insulate you need to use a top hat plastic washer, and a mica insulator between the component, and the heatsink.

I am constantly amazed by all of the pictures of circuits on the net of power parts with no heatsinks on them. So to buck the trend here's a PSU I finished today, with heatsinks. They are not big heatsinks, but I do not plan on pulling a whole lot of power out of this anyways. Plus the parts are only rated for 15 Watts each.

I had to make this to power a kit I am assembling

I could have probably gotten away with not putting heatsinks on. But I just don't feel right not slapping some kind of a heatsink onto a power part.

FtForger (author)2015-08-18

What about doing this for a bi-directional control?

pfred2 (author)2015-08-17

MMM a recipe for spaghetti. I love tasty pasta. Just looks at this delicious plate of noodles!

BeachsideHank (author)pfred22015-08-17

The link isn't working for me. Using the one on the edit toolbar is dysfunctional, I prefer to put the url inline, hit enter, then it works o.k.- dunno why that is.

pfred2 (author)BeachsideHank2015-08-17

Yeah it tested OK, but on the page it is no longer functional. Of course there is no edit feature here for comments either. So here is a link to that delicious serving of spaghetti

noel.kuck (author)2015-08-17

Never mind. Found the schematic included.

noel.kuck (author)2015-08-17

A schematic would be helpful. Thanks for sharing.

seamster (author)2015-08-17

Nicely done. Thanks for sharing this!

About This Instructable




Bio: I'm Dylan Desrosiers, and I was born with a passion for making. In my free time, I'm an Inventor, Maker, Hacker, Tinker, and ... More »
More by DylanD581:10 Campers You'll Actually Want to Sleep InAeroelastic Flutter Energy Harvester - More Efficient Than a Wind TurbineCustom Live Edge Table
Add instructable to: