Introduction: Motor Controllers for Cheap Robots

Picture of Motor Controllers for Cheap Robots

Hey! This I'ble is now out of date!

I made an updated version which you can read here! Hope you find it fun and useful!

~~~~~

Thus far, I've shown you how to create wheels out of household items, severalmotorizedchassis out of cardboard, and a couple of simple and effective light sensors. Now, one of the last major pieces is about to fall into place.

Almost every robot needs to power a motor of some sort or another. Problem is that motors take quite a lot of power, compared to what most microcontrollers operate with. To solve this problem, robots use what is called a motor controller, which usually amounts to some form of electronic switch that can turn on a very high voltage, using a very low one. That's what we'll be making today!

Let's get started!

~~~~~
For more Instructables on building cheap robots, please check out the For Cheap Robots collection! For more things that I've done, you can check out my profile page!

For more info from Digilent on the Digilent Makerspace, check out the Digilent blog!

Step 1: What You'll Need

Picture of What You'll Need

For this project, you'll need the following:

  • At least two colors of wire.
    • I use solid-core wire. It's pretty standard to use red for power and black for ground, but my black is running low so I picked white.
  • (Optional) Two more colors of wire.
    • It can be helpful to organize your signal wires by color. I'm using yellow and blue.
  • The DP32 from Digilent.
    • Most any microcontroller board will do, but the DP32 is cheap and has a built-in breadboard where you can wire everything.
  • A couple of motors.
    • These ones I salvaged from a couple of old, broken printers.
  • A battery pack.
    • I usually use four AA or AAA batteries, because that works well for most microcontroller boards.
  • A screwdriver.
    • This is just for screwing in your battery leads.
  • Wire cutters and wire strippers.
  • Two negative transistors.
    • I'm using the N-FET transistors from Digilent's chipKIT starter kit. Make sure you're using N-FETs and not BJTs (NPN or PNP transistors), as BJTs are more complicated than MOSFETS.
    • Mine are part number ZVN2110A, in case you were wondering.
  • Two sets of two header-pins each.
    • I used these to connect my motors to the board. They're optional, but I'll explain more about why later.
    • I use male header pins, but I'd actually recommend getting female headers from Adafruit or Sparkfun and I'll explain why later.

You'll also need (but are not pictured):

  • A soldering iron.
  • (Optional) A hot glue gun.
    • I only used this for my header pins, so if you don't have any of those, you don't need it at all!

Step 2: Circuit Diagram

Picture of Circuit Diagram

I've received some requests for circuit diagrams for this and my line sensor tutorial, but it's always been my intent to provide one for you folks. However, I still haven't found a circuit diagramming program that I'm completely happy with. Instead of making you folks wait, I figured I would just use one of the black boards we have around the Digilent Makerspace, to draw up a quick diagram and explain what's going on.

This circuit is extremely simple, as you can see. The motor is connected directly to the 6 volt output of the batteries that power our board (no regulators or anything). Then, it's connected to ground through our N-FETs, and the gate pin of the N-FETs are connected to one of our DP32's output pins.

What this allows us to do is use the N-FET like an electronic switch, turning our motors on and off. N-FETs are also very fast, so if you wanted to you could switch the motor on and off very rapidly, effectively giving it less power to make it run slower! What this circuit can't let us do is change the direction that our motor runs. For that, you'll need a more complicated circuit.

Step 3: Installing Transistors

Picture of Installing Transistors

This step is best explained by the pictures above, however I'd like to add a couple things here.

Firstly, it's very important to know which lead is which on your transistors. In the case of my N-FET transistors, Drain (the leftmost pin) connects to the higher voltage (in this case my motor's negative lead), while Source (the rightmost pin) connects to ground. You can tell which direction these N-FETs are facing because the "front" is slightly rounded (which you can see in picture 2).

For BJT transistors (of which NPN transistors are one type) it's very. My partner in crime brmarcum has a tutorial all about using BJTs, but you're going to want to avoid them for this tutorial.

Secondly, I'd like to point out that I chose where I placed my transistors very carefully, so that this tutorial would be fully compatible with my Line Sensor tutorial.

Step 4: Placing Your Header Pins

Picture of Placing Your Header Pins

Once again, this step is best described by the pictures above, but I'd like to add a couple notes here.

I used male header pins for this step, as you can see above, because I had some lying around. I could get away with this because my motors both had female connectors, however many motors won't. That's why I'd recommend using female headers instead, because it's easier to simply insert wires into female headers.

That said, female headers are trickier to use, because you can't simply break them to length the way you can with male headers. Check out the Adafruit page I linked to in the parts list, because the product pictures give a good illustration on how to break female headers. (That's something that the Sparkfun page probably needs, based on all the angry comments. ;p)

But Jay! Why not just solder my motor leads to the board?

I'm very glad you asked that Strange-Voice-In-My-Head! Motor directions are tricky things! You can't always tell which direction a motor will spin when you hook it up to power and ground. If you solder your motor in and charge ahead, you might find that they don't spin the direction that you need them to! That's why I made sure to make my motor attachments changeable!

How about using an H-bridge instead?

Once again, a very good suggestion from the Strange-Voice-In-My-Head! For those of you who don't know, an H-bridge is a configuration of transistors that allows you to change the direction of your motors in your code! This is really handy when building for stuff that needs motors to run forwards and backwards. However, having used H-bridges quite a lot, I can say that I really don't like them, and for right now I just wanted to make the simplest possible motor controller. Now, I have heard that brmarcum is already working on a tutorial for a bi-directional motor controller that doesn't use an H-bridge (gasp!), so keep an eye out for that!

Step 5: Adding Signal Pins

Picture of Adding Signal Pins

You're going to want to connect pins PGC and RB2 of your board (pins 12 and 13) to the gate pins of your transistors. This will allow your DP32 to open and close the transistor's gate, which turns on and off the power for your motors, just like a switch!

I chose the PGC and RB2 pins for two reasons. First, these pins fit neatly into my Line Sensor tutorial. Second, these pins also connect to LED 2 and LED 3 on your board! That means that your on-board LEDs will light up whenever your board tries to power its motors. That's handy because if your motor or N-FET is busted for some reason, you can tell that your board is applying power, and it's not just a problem in code.

Step 6: Add Power Line

Picture of Add Power Line

The whole point of adding motor controllers to your board is because your board can't output enough power to the pins to get some motors to spin at all, let alone pull a robot around. That means that we're going to have to connect our motors to a higher voltage input. The regulated 3V input simply isn't enough, so instead we're connecting our motors directly to V IN, meaning we're essentially powering our motors directly from the batteries!

Connect a wire between the VIN pin and the rail you soldered your header pins into. It doesn't matter too much which VIN pin you connect to (there are two on the board) but I find that it makes the most sense to connect it to the one above RA4.

Step 7: Connecting Your N-FETs to Ground

Picture of Connecting Your N-FETs to Ground

The last step in the wiring process will be to connect your N-FETs to ground. Once again, I'm pretty low on black wire, so I used white for my grounding wires.

Run your wires from the third pin of your N-FETs (the right-most pin in the pictures above) to the grounding rail on the left. Solder them in and you're done!

Step 8: Connect Motors, Power, and Test It Out!

Picture of Connect Motors, Power, and Test It Out!

Now you're finally ready to connect your motors to power and load up some code!

The example code I've provided runs a simple test of both motors, turning them on and off alternatively! This will also tell you what direction the turn when powered.

This tutorial is just a jumping off point. It's the simplest thing I could come up with to run motors on the DP32, and I've already gotten a couple of line-following robots to run very well using it! I'd love to see what you folks can do with it!

As always, please let me know what you liked about this tutorial, and feel free to give me advice on anything you think could be done differently. I've already got a plan to add some circuit diagrams to this and my line-sensor tutorial, as well as an explanation of what's going on, so keep an eye out for that soon!

Comments

make

chintan tandel (author)2015-04-08

great job!!!

check this out for more accurate reasult

JayWeeks (author)chintan tandel2015-04-08

OH! OH THIS IS FANTASTIC!

I've pulled a couple motors like these from various printers I've gutted. I haven't taken the time to figure out how to get them to work properly, but this will be extremely helpful when I do!

Thanks a ton!

Crafthead3020 (author)2015-02-03

http://www.ebay.com/itm/1PC-Power-N-Mosfet-IRF1310...

Would these work as negative transistors?

Nate Ocean (author)2014-09-23

nqtronix points out a number of concerns with this design.

The schematic in Step 2 needs work:

(1) When drawing the battery symbol, the short segment is the negative terminal. Even better, usually a "+" sign is shown on the positive terminal to make things completely clear.

(2) You seem to have made up your own symbol for an N-FET. It's confusing and ambiguous. It appears to be a cross between a BJT and FET, but missing polarity markings. Check Wikipedia ("electronic symbol") for a starting point. Often the manufacturer's datasheet shows the preferred symbol.

(3) A small copy-n-paste from the manufacturer's datasheet would clarify the package and pinout of the N-FET you've chosen.

(4) The catch diodes that nqtronix mentions are much needed. Probably a simple 1N4001 diode in reverse across the motor is sufficient. It has the right voltage, current, and speed specs for your application.

Without the catch diode, voltage spikes that appears when the motor is switched off, will likely damage the N-FET. Generally you need a catch diode with any inductive load, such as when driving a motor, or relay, or solenoid.

(Diodes with even *greater* reverse voltage breakdown than the 1N4001 are acceptable for your 6V circuit. The 1N4004 or 1N4007 are good and affordable substitutes.)

[The 1N4148 is a very popular diode, but this is not the right application for it.]

(5) In your schematic, you might want to include "+" and "-" labels on the Motor as well. This helps when wiring electro-mechanical projects where the direction of rotation is important (such as a fan, or a robot wheel). Otherwise you wind up rewiring things to correct the polarity.)

(6) For clarity, you should show what point in your circuit shares a common ground with the microprocessor. Showing only a single connection point ("Pin12") often trips up those first learning circuits.

JayWeeks (author)Nate Ocean2014-09-23

Oh man! Thanks for the follow-up. Now I'm definitely going to have to do a re-design of the circuit with the things you suggested. Thanks!

unseen1980 (author)2014-09-23

I added 2 dc motors into a small toy truck for my son few weeks ago and I did it in a similar way (with TIP120). The biggest disadvantage is the lack of reverse. Thats why I am going to switch to H-Bridge (L298N) Here is a link with some photos http://devacron.com/add-bluetooth-control-toy-truck/

JayWeeks (author)unseen19802014-09-23

Very cool! I want to try doing something with bluetooth at some point. I checked out the link you have for using bluetooth, but it was in Greek. Do you have a version of that page in English?

unseen1980 (author)JayWeeks2014-09-23

Sorry no, but diagram and code are there :)

JayWeeks (author)unseen19802014-09-23

Thanks!

Bowtie41 (author)JayWeeks2014-09-23

Google Translate it.It wouldn't do whole webpage(thinks already in English),but I copied the Greek parts and it worked fine.

JayWeeks (author)Bowtie412014-09-23

I'll have to try that, thanks!

nqtronix (author)2014-09-21

Even though the documentation is really good by itself and super easy to follow I'm afraid I've to tell you that form the technical point of view this instructabele isn't that great.

First of all your design is missing flyback diodes, one per motor. They need to be connected in reverse to the motors to eliminate any voltages generated by the motor when the nfets are switched off. Otherwise these voltages might kill your nfets and/or other parts of the circuit. For this purpose you might choose any diode you can get with the same rated current as the nfets and a low reverse revovery time (<100ns, lower is better). If you'd use the classic 1n4148 this would add 4ct (2ct per diode), so it would still be cheap enough.

Speaking of current you might consider to use differend nfets than the ZVN2110A. A quick look into their datasheet reveals that the maximum continous drain current is only 0.32A (320mA) which is by the looks of the motors not nearly enough. Another important thing to note is the relativly high static on resistance of 4 Ohm which causes at the rated 320mA a voltage drop of 1.28V, more than a forth of the suplied voltage!

The ZVN2110A was released more than 20 years ago. Today much better parts are widely available (at least at "professional" distributors such as digikey.com). A local distributor sells the IRLML6244 for 11ct ea. . That nfet can handle massive 6.3A (!) and has an impressive resistance of 21 mOhm (0.021 Ohm). The only downside is the SMD package which can be challanging to solder. With a bit of research you might find simliar parts at you local distributor. Have also a look at the needed gate voltage to switch (Fig. 12 in the datasheet of the IRLML6244, lower resistance is better) and the input capacitance (should be <1nF/1000pF, lower is better, important for "fast" switching).

If you feel unsure about a part you feel free to post a datasheet and I'll have a look ;)

Good luck for your future projects :)

Greetings, nqtronix

JayWeeks (author)nqtronix2014-09-21

Wow! That's a lot of really good information, especially for a total beginner like me. I'll have to use that for my next project! Thanks!

script_coded (author)2014-09-21

First of all, I love your robot instructables! Some of these have really helped me out! You deserve all my likes and all my follows!

JayWeeks (author)script_coded2014-09-21

Thank you very much! I'll do my best to keep it up!

Robson Couto (author)2014-09-20

Hey! Thanks for sharing this.

I'm still laughing because of the Strange-Voice-In-My-Head part.

I also like to savage things, printers are really good, you can find motors, sensors, gears and a lot of other things.

Take a look in my cheap robot, the wheels are from mices hehe.

Keep up the great work!

JayWeeks (author)Robson Couto2014-09-20

Very nice! I love how compact it is! That is a beautifully simple little robot!

Robson Couto (author)JayWeeks2014-09-20

Thank you!

I love robots, since Johnny Five I think.

Keep posting about them, and will be reading.

MsSweetSatisfaction (author)2014-09-20

Yay more cheap robotics! Thanks for sharing everything you've learned!

It's been a pleasure! I'm just thrilled that so many people have noticed and enjoyed my Instructables!

renzo1320 (author)2014-09-20

another excellent instructable! it would be great if you added a schematic of the circuit.

JayWeeks (author)renzo13202014-09-20

Yep! That's definitely in the works for both this Instructable and my line sensor Instructable. I've just been bogged down with school work, but I should have some spare time for that next week, so look for that soon!

Arman5592 (author)2014-09-20

Nice ! I think it wouldn't be a good idea to use BJTs as they have low switching voltage while a FET has a higher one as is more suitable for micro-controller outputs . Thanks for sharing .

JayWeeks (author)Arman55922014-09-20

I'm glad I happened to get FETs with my kit because I cannot claim to know how BJTs work at all! (Despite having been taught how they work at least twice in school.)

About This Instructable

36,681views

530favorites

License:

Bio: I build robots out of boxes! I love teaching what I've learned and seeing people add their own ideas to what they've learned ... More »
More by JayWeeks:Speed PID using Digilent Gear-Motors and Encoders!Getting Started With the Pmod HB5: Part 1Resistive Touch Screen on the DP32
Add instructable to: