Simple 2-way motor control for the arduino

Simple 2-way motor control for the arduino
When I say simple, I don't mean use a speed control. But control the motor directly without any external circuitry. Here's how:

How this came about:

I recently was working on an instructable about charlieplexing with an arduino. And I was wondering if the same principle would work with motors to some extent. So I came up with the idea that if you used a motor instead of an led you could have 2-way control of it & if you used 2 PWM (Pulse Width Modulation) ports you could have 2-way variable speed control for a motor with no external hardware!! So I decided to post my findings. Have fun! If you have any questions Please ask them.


Note: This is not the safest way to control a motor. Each I/O pin can only handle 40 mA of current. I would recommend using a H-Bridge as pointed out by: Bongmaster & Frollard.

I am not responsible for any thing bad that happens to you or to your arduino!


 
Remove these adsRemove these ads by Signing Up
 

Step 1The stuff you need:

The stuff you need:
Parts:
- Arduino
- Small DC motor
- Wire for motor

Tools:
- Computer with Arduino IDE installed
- A-B USB cord
« Previous StepDownload PDFView All StepsNext Step »
19 comments
Nov 2, 2009. 4:12 AMEonir says:
The power limits of the microprocessor are not the only thing you should be worried about.

A motor is not an entirely resistive object. It has also some inductance. What does that mean? It means that when you reverse the voltage on the pins, the current doesn't change its direction immediately. So, for a short moment, the motor acts like a current source.

And that could effectively blow up your microprocessor.
Nov 2, 2009. 4:14 AMEonir says:
I didn't have time to check your code, but there's one thing you can do to prevent a hot situation. Whenever you want to switch your motor, a dead time would be applied, in order to allow for the current to fall to a negligible level.
Aug 6, 2011. 8:19 AMuberdum05 says:
Or just slowly ramp the motor speed up and down
Feb 16, 2011. 12:41 PMshortcircuitaz says:
I tried this and my motor must be too big or something.. do I need to send any information through the interface to the controller?
Feb 2, 2011. 11:59 AMwfelix says:
very good for small motors... '

but, for big motors, use analog io or gnd+digital with an external driver is better (obviously)''

but, yet, is a great idea
Dec 15, 2010. 9:04 AMGitarGr8 says:
Just so you know, there is an extremely large voltage that is created when the magnetic field of a motor breaks down, ie. when you switch off the circuit. You can visually see this if you hook up a 9V batter to the motor and slowly remove a lead. The spark that is created means a LOT of volts (someone smarter than I could tell you an exact number) which WILL damage / destroy the transistors in your chip. You can get around this by using a protection diode, which will dissipate that voltage back through the coil:

http://www.kpsec.freeuk.com/trancirc.htm
(scroll down to protection diode)
Sep 3, 2010. 4:47 PMkyle brinkerhoff says:
OR! you could just buy a pwm motor controller and drive FLIPPEN HUGE MOTORS!
Sep 21, 2010. 10:28 PMthe_burrito_master says:
Try a couple transistors as amplifiers.
Oct 24, 2010. 7:53 AMbeehard44 says:
or relay?
Oct 24, 2010. 8:12 AMthe_burrito_master says:
uh yeas.
Jun 29, 2010. 8:07 PMChowmix12 says:
check out STM, they have free samples for an l298HN IC, which is an ic that incorporates 2 h bridges inside the IC.
Feb 15, 2010. 11:37 AMBrunoG says:
cool.
Nov 27, 2009. 5:20 PMdaltore says:
It seems to me like this would only be able to drive the motors at a maximum of 1/2 power each when they're reverse of each other.  You could get both to move full-power when they're going the same direction (they share either a common ground or common source), but when they're opposite, you're spending 1/2 of each PWM train on each motor (which at full power, is a 1/2 duty-cycle PWM wave).  Interesting idea though, it's crazy what you can do with microcontrollers these days.
Oct 31, 2009. 5:56 PMBongmaster says:
kool but its best not to drive a motor directly from an arduino ;) could blow ure pins..

u can make a simple h bridge from transistors like i did here
http://bongmasters-things-and-stuff.blogspot.com/2009/05/robot-h-bridge-pair-motor-driver.html

using the schematic on this page
http://www.beam-online.com/Robots/Circuits/circuits.html

there was a 4 transistor version somewhere too. cant remember where tho XD

Oct 31, 2009. 7:41 PMBongmaster says:
hell yea XD i did it this way 1st XD but i didnt want to blow my chip by drawing the current thu it to drive a motor :)

hence why i built the h-bridge pair i linked ;) better safe XD
Nov 1, 2009. 5:14 AMfrollard says:
Drawing current and especially drawing a changing current (like pwm) thru an inductive load like a motor can have disastrous results to those little pinnies :P

Totally agreed in using an h-bridge, driven by these pins.
Nov 1, 2009. 7:30 PMfrollard says:
Remembering when a motor turns on or off it has a pulse of very high inrush current to get it started.  A multimeter will probably not even detect it because its so fast - but its enough to destroy a pin.

using pwm just means you're turning it on and off MANY times...more risk of burning out that expensive pin....my 2 cents.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
40
Followers
15
Author:computergeek