Controlling DC Motor with PWM

I am attempting to hardware hack a toy with two DC Motors in it

I have measured the voltage required to power the motors and it came out to 3 v

I have my arduino outputting a regulated voltage via PWM on pin 11 and have it sending out a voltage at max power (4.97)

The pins output voltage reads a full 4.97 volts steady until I connect it to the device, at which point my load drops to less than a volt.

Any idea why this is happening?

You should NEVER try powering a motor directly from an Arduino pin, period!

The pins can handle only 40ma each safely (max), and if you're trying to run a motor from a pin, you're trying to pull 60ma++ so you may damage a pin soon if you don't stop!

You can look into an h-bridge circuit, or purchase an h-bridge chip, such as the L293D. This will enable you to control the motor safely, and in both directions.

:slight_smile:

Thanks CaptainObvious (sound sarcastic its not)

Was looking into H bridge chips earlier, care to describe exactly how they work, or link me to some documentation?

http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/

lol :slight_smile:

Here's just an example, there are a few ways to hook them up that I've seen. And keep in mind, with the 293's, there's a 1.5 volt ish drop from the supply. Which is good, you should keep motors at the voltage they're meant to run on, the closer, the longer they tend to last. :slight_smile:

http://letsmakerobots.com/node/2074

Be sure to check out other schematics online, as this one is just a basic on-off setup. There's a few that will allow you to control the speed.

Best of luck! :slight_smile:

http://www.barello.net/Papers/H-Bridge.pdf
http://itp.nyu.edu/physcomp/Labs/DCMotorControl
http://www.bobblick.com/techref/projects/hbridge/hbridge.html

That should get you started...

An H-Bridge just allows power (typically external power) to flow through a motor (or other device) in either direction.

Everyone always suggests an H bridge, but personally, I just prefer some regular old Transistors :P. Of course, those will only work if you don't plan on powering in both directions, so I suppose it's really up to what you're trying to accomplish :).

You can build an H-Bridge with transistors. But transistors tend to be a bit inefficient, absorbing too much of the juice that you want going into your motor. Personally, I prefer using MOSFETs for motor control. They're more efficient.

I'm not actually planning on controlling direction at all... just want to send a controlled voltage (make shift digi-pot).

I want to be able to output 3.5 volts from my arduino... and send 3.5 to the toy... and then move between 0 and 3.5 with a digital slider.

So is the H-Bridge necessary? If not how could one accomplish this with just transistors?

So basically what I am looking to do is to connect the power of my device to the H bridge, and use my PWM to control the Gates?

I would still use Transistors (but that's just what I know best :P). You connect your external power supply to the collector, and then connect a PWM to the Base (vary the amount of power going into the base to determine how much gets sent out of the Emitter), and then Connect the motor to the Emitter (and then to ground :P).

And do I need to connect the ground from the motors to the ground on the arduino board? (I'm new to this :S)

Im not sure if I understand you correctly, but yes you always want a common ground. What I dont quite understand is when you say the "ground from the motors" as it sounds like the motors are being powered by something else and you are just trying to send a 0-3.5V varying voltage to the controller of that motor. If indeed that is the case then you just want to make sure the ground for the motor controller, and the ground for the arduino are connected.

The motors are normally powered by the toy... but I want to install a trip switch which will allow the power to be controlled by the arduino,

I think this is what he's pointing you toward:

First off look at this:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html
The simplest way is to use a relay to act as your switch.

Oh sure... So Grumpy_Mike dances in with his oh so informative web pages and makes us all look ill prepared :wink: