Sunteți pe pagina 1din 11

(http://cdn.instructables.com/FWH/F88U/G0SD2ZKW/FWHF88UG0SD2ZKW.LARGE.

jpg)
About This Instructable
License:
104,857 views
78 favorites
computergeek
(/member/computergeek/)
(/)
let's make
share what you make >
(/editInstructable/)
(/)
Explore (/tag/type-id/) Create (/about/submit.jsp) Contests (/contest/) Community (/community/) Login (/you/)
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
(http://www.instructables.com/id/CharliePlexed-LED-string-for-the-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 (http://en.wikipedia.org/wiki/H-bridge)
as pointed out by: Bongmaster & Frollard.
I am not responsible for any thing bad that happens to you or to your arduino!

Related
(http://cdn.instructables.com/FMI/CKF9/G0SD2Z0E/FMICKF9G0SD2Z0E.LARGE.jpg)
(/member/computergeek/)
Follow 70
(/id/DIY-Apple-Remote-
Shield-for-the-Arduino)
(/id/CharliePlexed-LED-
string-for-the-Arduino)
(/id/Rubber-Band-Powered-
Altoids-Boat)
More by computergeek
arduino (/tag/type-id/category-technology/keyword-
arduino/)
motor (/tag/type-id/category-technology/keyword-
motor/)
2 (/tag/type-id/category-technology/keyword-2/)
way (/tag/type-id/category-technology/keyword-
way/)
speed (/tag/type-id/category-technology/keyword-
speed/)
control (/tag/type-id/category-technology/keyword-
control/)
mac (/tag/type-id/category-technology/keyword-
mac/)
os (/tag/type-id/category-technology/keyword-os/)
x (/tag/type-id/category-technology/keyword-x/)
variable (/tag/type-id/category-
technology/keyword-variable/)
Tags:
Processing Controls R/C
Car with XBee modules
(/id/Processing-Controls-
RC-Car-with-XBee-
modules/)
Control Arduino Board
Wirelessly With iPhone,
iPad or iPod Using
iArduino App and Ether
(/id/Control-Arduino-
GOduino II = Arduino +
L293D Variable Speed
Motor Controller
(/id/GOduino-II-Arduino-
L293D-Variable-Speed-
Going Beyond
StandardFirmata - Adding
New Device Support
(/id/Going-Beyond-
StandardFirmata-Adding-
Remove these ads by Signing Up (/account/gopro?sourcea=removeads&nxtPgName=Simple+2-
way+motor+control+f or+the+arduino&nxtPg=/id/Simple-2-way-motor-control-f or-the-arduino/)
Step 1: The stuff you need:
Parts:
- Arduino
- Small DC motor
- Wire for motor
Tools:
- Computer with Arduino IDE (http://arduino.cc/en/Main/Software) installed
- A-B USB cord
Step 2: Connecting the motor
See More (/tag/type-id/?q=)
(http://cdn.instructables.com/FFU/O1DL/G0SD2ZL3/FFUO1DLG0SD2ZL3.LARGE.jpg)
Brain-Controlled
Wheelchair (/id/Brain-
Controlled-Wheelchair/)
(http://cdn.instructables.com/F7W/MPI2/G0SD2ZLF/F7WMPI2G0SD2ZLF.LARGE.jpg)
(http://cdn.instructables.com/FWH/F88U/G0SD2ZKW/FWHF88UG0SD2ZKW.LARGE.jpg)
Simple 2-way motor control for the arduino by computergeek (/member/computergeek/)
+ Collection I Made it!
Download (/id/Simple-2-way-motor-control-for-the-arduino/?download=pdf)
(/id/Simple-2-way-motor-control-for-the-arduino/?ALLSTEPS) 4 Steps (/id/Simple-2-way-motor-control-for-the-arduino/step4/How-this-works-more-Ideas/)
Favorite
Next (/id/Simple-2-way-motor-control-for-the-arduino/step4/How-this-works-more-Ideas/)
View All Steps (/id/Simple-2-way-motor-control-for-the-arduino/?ALLSTEPS)
Connect your DC motor to your arduino.
- Connect one wire from the motor to pin 5 on you arduino
- Connect the other wire from your motor to pin 6 on your arduino
The hardware setup for this is pretty simple.
Step 3: Coding the Arduino
Here's some basic steps to program your arduino.
1) Download the source code from below
2) Open the file in the Arduino IDE (http://redirectingat.com/?
id=487X782&url=http%3A%2F%2Farduino.cc%2Fen%2FMain%2FSoftware)
3) Press the "Upload to I/O Board" button
4) Once the program is uploaded it will start running
I tried to add a good amount of comments to the code, but if you have any
questions, please ask them.
_2Way_Motor_Control.pde (/files/orig/FP6/380S/G0SD2Z09/FP6380SG0SD2Z09.tmp)1 KB
(http://cdn.instructables.com/FMI/CKF9/G0SD2Z0E/FMICKF9G0SD2Z0E.LARGE.jpg)
(http://cdn.instructables.com/FZR/9TQA/G0SD2ZLE/FZR9TQAG0SD2ZLE.LARGE.jpg)
(http://cdn.instructables.com/FJZ/3U84/G1BBDD6G/FJZ3U84G1BBDD6G.LARGE.jpg)
Previous
Make Comment
(/member/danimalik/)
19 days ago
Reply (CNCJ91DHUWMC3G5)
(/member/dsilva33/)
7 days ago
Reply (CXL1QXXHV9I1SU8)
(/member/racataca/)
1 month ago
Reply (C89WSSPHTBIX6CZ)
(/member/mfusaro/)
4 months ago
Reply (C3XLL9JHPTXER46)
(/member/shanymz/)
1 year ago
Reply (CFS8B81HDOW6TTX)
(/member/diy_bloke/)
7 months ago
Reply (CP64WNYHM8DBVF4)
(/member/asarris/)
1 year ago
Reply (C7B6EOBHGH0938L)
(/member/gee12/)
1 year ago
Reply (CNK3YGXHAQ30X49)
danimalik (/member/danimalik/)
im using arduino with atmega 328p-pu
motor is not runing. wat isue can be ?
dsilva33 (/member/dsilva33/) danimalik
The motor is not running because the motor is using to much current from the
arduino. You can damage your arduino because the pins can short out. I don't
recomend this method for you.
racataca (/member/racataca/)
that I can do to convert 2 PWM inputs (rc servo) to 5Vdc analog?
mfusaro (/member/mfusaro/)
my motor runs when hooked up to a 1.5v battery, yet when I run this code hooked up
to my laptop, I get nothing. Why?
shanymz (/member/shanymz/)
Hi,
I tried your code to run a 12 V dc motor, and it doesnt work. I just hear beeping from
motor,
it is connected directly to computer using arduino uno.
I am a newbie! so I really appreciate your help
diy_bloke (/member/diy_bloke/) shanymz
the arduino is 5Volt, yr moor is
12 Volt. I am sure you can do
the math on that yourself :-)
asarris (/member/asarris/)
I am not sure if this is my fault or instructable's fault, but when I try to download this file
I get a temporary file.
gee12 (/member/gee12/)
Good Tutorial,
msurguy (/member/msurguy/)
(/member/msurguy/)
1 year ago
Reply (CYX23XLHAM7MSI8)
(/member/Lenny24/)
1 year ago
Reply (CW7MT4THAOPQU89)
(/member/msurguy/)
1 year ago
Reply (C3BA3FMHAOPSXT0)
(/member/acain3/)
1 year ago
Reply (CDAFAQHH3QFJRIO)
(/member/vkarpuram1/)
1 year ago
Reply (CTCKFI3H2WEJKLM)
(/member/acain3/)
1 year ago
Reply (CTF3P67H3QFJQBM)
(/member/David97/)
2 years ago
Reply (CW7XGW2GYSIMCI8)
(/member/Eonir/)
4 years ago
Reply (CL390YYG1BBE2B5)
So I am planning to drive a small Electromagnetic coil with this code, it is 120
Ohms so the power consumption will only be 20-40mah max, this code should
work, right?
Lenny24 (/member/Lenny24/) msurguy
Hey, since motors, coils and/or
speakers are complex loads,
meaning they do not only consist
of a resistance that might be
defined by Ohm's Law, even a
small electromagnet with a static
resistance thats > 1000 Ohms
could easily kill your Arduino.
The Code should work just fine,
but you might consider using an
H-Bridge for controlling current.
msurguy (/member/msurguy/) Lenny24
Thanks ! I might use TI DRV883x
series chip for the H Bridge driver
then!
acain3 (/member/acain3/)
I'm working on a schematic that uses four transistors per engine, a universal ground,
a universal power, and an Arduino Uno. It will allow you to use two wires to control
both motor directions. It switches two transistors on at a time.
vkarpuram1 (/member/vkarpuram1/)
You must not use this method to control a motor with the arduino as it could blow up
the whole board, instead you could use a motor driver like the l298n. Here's a tutorial
- http://vkwarehouse.blogspot.in/2012/05/bidirectional-motor-control.html
(http://vkwarehouse.blogspot.in/2012/05/bidirectional-motor-control.html)
acain3 (/member/acain3/) vkarpuram1
Your link popped up containing Malware.
David97 (/member/David97/)
I wold not trythhis with big motors anyone looking at doing it for several reasons.
#The current draw would be too big for the arduino
#the back EMF could produce a huge voltag spike and blowing up your arduino.
#Do you think its a good idea when most instructables and projects have
motorcontrollers to prevent blowing up the arduino?
Eonir (/member/Eonir/)
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.
(/member/Eonir/)
4 years ago
Reply (CAJBT69G1BB3VU0)
(/member/Callum+Snowden/)
2 years ago
Reply (CUYW5XBGQYG5SU2)
(/member/shortcircuitaz/)
3 years ago
Reply (CVG22JMGJQEB89X)
(/member/wfelix/)
3 years ago
Reply (CVNXM0BGJHVLKVW)
(/member/GitarGr8/)
3 years ago
Reply (CZW2UCPGHFK83I7)
(/member/kyle+brinkerhoff/)
3 years ago
Reply (C4HR1RAGDNIUIRJ)
(/member/the_burrito_master/)
3 years ago
Reply (C5M58WXGE7LFDIQ)
(/member/beehard44/)
3 years ago
Reply (CH543V1GFMCCVFR)
And that could effectively blow up your microprocessor.
Eonir (/member/Eonir/) Eonir
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.
Callum Snowden (/member/Callum+Snowden/) Eonir
Or just slowly ramp the motor
speed up and down
shortcircuitaz (/member/shortcircuitaz/)
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?
wfelix (/member/wfelix/)
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
GitarGr8 (/member/GitarGr8/)
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)
kyle brinkerhoff (/member/kyle+brinkerhoff/)
OR! you could just buy a pwm motor
controller and drive FLIPPEN HUGE
MOTORS!
the_burrito_master (/member/the_burrito_master/) kyle brinkerhoff
Try a couple transistors as
amplifiers.
beehard44 (/member/beehard44/) the_burrito_master
or relay?
the_burrito_master (/member/the_burrito_master/) beehard44
(/member/the_burrito_master/)
3 years ago
Reply (CRBLS7WGFMCCVRY)
(/member/Chowmix12/)
3 years ago
Reply (C5UTJMNGAPV3OZS)
(/member/BrunoG/)
4 years ago
Reply (CFLB58TG5KP7UZ1)
(/member/daltore/)
4 years ago
Reply (C4NT7Z2G2HDZ2LG)
(/member/Bongmaster/)
4 years ago
Reply (CS68JDWG1BBDGVJ)
(/member/computergeek/)
4 years ago
Reply (C1PBWSGG1BB3UFX)
(/member/Bongmaster/)
4 years ago
Reply (CO2DN81G1BB3UJ7)
(/member/frollard/)
4 years ago
Reply (CZKQROMG1BB3URI)
uh yeas.
Chowmix12 (/member/Chowmix12/)
check out STM, they have free samples for an l298HN IC, which is an ic that
incorporates 2 h bridges inside the IC.
BrunoG (/member/BrunoG/)
cool.
daltore (/member/daltore/)
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.
Bongmaster (/member/Bongmaster/)
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
computergeek (/member/computergeek/) (author) Bongmaster
I'm glad you like it! It is definitely
not the best way, but probably
the simplest. You do have to be
careful using this approach.
Bongmaster (/member/Bongmaster/) computergeek
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
frollard (/member/frollard/) Bongmaster
Drawing current and especially
drawing a changing current (like
pwm) thru an inductive load like a
motor can have disastrous
(/member/computergeek/)
4 years ago
Reply (C6TURIIG1BB3UUO)
(/member/frollard/)
4 years ago
Reply (C9CDCEHG1BB7YN8)
Make Comment
results to those little pinnies :P
Totally agreed in using an h-
bridge, driven by these pins.
computergeek (/member/computergeek/) (author) frollard
I looked at the Arduino Specs
(http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove),
and found each I/O pin can only
handle 40 mA of current. I
measured the current draw of my
motor & found it was at the max
35 mA's. So I decided to put a
warning in my instructable.
Personally I prefer continuous
rotation servos over motors.
frollard (/member/frollard/) computergeek
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.
About Us
Who We Are (/about/)
Advertise (/advertise/)
Contact (/about/contact.jsp)
Jobs (/community/Positions-available-at-Instructables/)
Help (/community?categoryGroup=Help)
Find Us
Facebook (http://www.facebook.com/instructables)
Youtube (http://www.youtube.com/user/instructablestv)
Twitter (http://www.twitter.com/instructables)
Pinterest (http://www.pinterest.com/instructables)
Google+ (https://plus.google.com/+instructables)
Tumblr (http://instructables.tumblr.com)
Resources
For Teachers (/teachers/)
Artists in Residence (/group/air/)
Gift Pro Account (/account/give?sourcea=footer)
Forums (/community/)
Answers (/tag/type-question/?sort=RECENT)
Go Pro Today (/account/gopro?sourcea=footer)
We're Hiring! (/community/Positions-available-at-Instructables/)
Mobile
Download our new apps for iOS,
Android and Windows 8!
Android
(https://play.google.com/store/apps/details?
id=com.adsk.instructables)
iOS
(https://itunes.apple.com/app/instructables/id586765571)
Windows
(http://apps.microsoft.com/windows/en-
us/app/7afc8194-c771-441a-9590-
54250d6a8300)
Join our newsletter:
Terms of Service (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21959721) |
Privacy Statement (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21292079) |
Legal Notices & Trademarks (http://usa.autodesk.com/legal-notices-trademarks/) | Mobile Site (http://m.instructables.com)
(http://usa.autodesk.com/adsk/servlet/pc/index?id=20781545&siteID=123112)
Join!
2014 Autodesk, Inc.
English enter email

S-ar putea să vă placă și