using the Ardruino with DC motors

Hi all,

I'm brand new to Ardruino so I have a question that has probably been answered many many times... I couldn't find it in the search however.

We are making an automated demolition derby car for my Intro to mechanical engineering class using the ardruino duemilanove microcontroller and I had a question.

I want to wire the motors directly the microcontroller, but I'm not sure how I would control the motors. By that I mean, how do I tell the microcontroller to move forward AND backward. and how do I tell it to move left AND right. I know how to set pins high, but that only works for one direction as far as I understand. Any help would be greatly appreciated.

Sounds like you need a basic tutorial on DC motor control:

http://www.societyofrobots.com/actuators_dcmotors.shtml http://www.societyofrobots.com/schematics_h-bridgedes.shtml http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

There are MANY other tutorials out there. Once you understand why you CANNOT wire the motors directly to the microcontroller, you should be able to move to the next level of understanding (and questions ;) )

-- The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected

So I cannot wire the motor to the controller under any circumstances? Even if I just want it to go in a circle?

No. The microcontroller output pins can only supply a few milliamps -- motors take a lot more. The motor will not turn. If someone turns the motor manually it can actually output a voltage that damages the microcontroller.

You absolutely need a "motor driver" that can convert the digital signals of the microcontroller to the voltage/current needed by the motor.

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

Correct - the outputs are only good for 5V, 20mA, 0.1W, just enough to drive an LED really, but plenty for interfacing with other logic parts.
A motor is just an inductor (wrapped around a magnet) and looks like a short circuit. You need to turn on/off a bigger transistor (than the arduino has in its output) to sink or source the current thru the motor. And that’s just to turn it in one direction. Like putting one side of the motor to the -terminal of a battery and the other side to the +terminal. When you open/close one side then you are acting like a transistor. If you want the motor turn the other direction you have to flip the battery over - or use transistors to do that switching for you.

Sounds like you need a basic tutorial on DC motor control:

http://www.societyofrobots.com/actuators_dcmotors.shtml http://www.societyofrobots.com/schematics_h-bridgedes.shtml http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

There are MANY other tutorials out there. Once you understand why you CANNOT wire the motors directly to the microcontroller, you should be able to move to the next level of understanding (and questions

I found these links to be very helpful (Im always asking for links!) so as a shameless plug, it looks like the rugged motor controller in your signature would work nicely for his application? ;)

Correct - the outputs are only good for 5V, 20mA, 0.1W, just enough to drive an LED really, but plenty for interfacing with other logic parts. A motor is just an inductor (wrapped around a magnet) and looks like a short circuit. You need to turn on/off a bigger transistor (than the arduino has in its output) to sink or source the current thru the motor. And that's just to turn it in one direction. Like putting one side of the motor to the -terminal of a battery and the other side to the +terminal. When you open/close one side then you are acting like a transistor. If you want the motor turn the other direction you have to flip the battery over - or use transistors to do that switching for you.

How much current can you acceptably pull through the VIn or 5v power ports?

@OP - the answer to part of your question is that your motors will spin one way when you have one of the two control pins HIGH and the other pin LOW, and it will spin in the reverse direction when you switch the HIGH pin to LOW and the LOW pin to HIGH, (assuming its a reversible motor.)

Again, DO NOT do this directly from your board, your board must be used to trigger the gate pin on a transistor.

Looks like I’m not going home for Thanksgiving then… Oh well. I’m sure I will be back on this forum asking about programming since I assume its different than just turning pins high and low…

For sure - its all about the decision making as to why & when you put those pins low & high ...

Figured out that there are H-bridges on the stock board that came with the R/C car that we had to buy with the project. So I soldered wires to those connections and those will be attached to the adruino. It move the motors left, right, front and back perfectly fine. Good thing too since I don't have time to get H-bridges before its due. this is fun stuff once ya read some literature. :)

Knowledge is power! Always easier to do electronics when you know what you're dealing with.

hopefully last question... I need to wire the dc input myself. but which part is positive and which is negative? by that I mean, is the outside shell of the dc male end suppose to be positive or negative? Thanks for all of everyones help by the way!

If you are talking about the arduino external power connector, I think the center is positive and the outside is negative. You should be able to verify this using a multimeter.

DC input to what? The arduino? Then yes, the outer ring is negative, and the inner pin is positive.

Do you have a multimeter? You should have one to make basic measurements like that to confirm for yourself. Lots of places having sales this weekend, good time to grab one.

They are not expensive, here's one for $6 even. http://www.mpja.com/prodinfo.asp?number=17191+TE

Yeah, thanks for that. Soo Im on to the programming stage and I've gotten the rear wheel to move forward with digitalWrite(rfmotor, HIGH); and I set delay(10000) for a 10 second delay. after the delay I said digitalWrite(rfmotor, LOW) with a 10 second delay after that to shut it off, but it didn't shut off... What am I doing wrong? Do I have to wire to two pins for HIGH and LOW?

with a 10 second delay after that to shut it off, but it didn’t shut off…

Maybe “loop” ran again, but how can we know?
We can’t see your code.

int rfmotor = 1;

void setup() { pinMode(rfmotor, OUTPUT);

Serial.begin(9600);

}

void loop() {

digitalWrite(rfmotor, HIGH); delay(10000); digitalWrite(rfmotor, LOW); delay(10000);

} ;)

As written, the code inside
void loop ()
{

}
will just keep repeating.
You could add something like
int cycle = 1;

While (cycle<2) {
//turn motors
cycle = cycle+1; // so is now 2

}
then it should go forward & backward 1 time & then spend eternity waiting for cycle to be reset

Or do the same with
if (cycle==1)
{
// turn motors
cycle=cycle+1; // so is now 2
}
it will go thru the if section 1 time, then jump around it after that.

Or there are other ways also.
Add code to read a push button first - when the button is pushed, delay a couple of seconds to get your fingers out of the way, do the motor turn, go back to waiting for the next button push.
From there, add 2 buttons, 1 forward, 1 back. and so on.

I want it to go in a loop. Just go through the sequence I tell it to first.

Is there anything wrong with the way I've done? telling the board to make it high for 10 seconds, then low for 10 seconds should turn it on for 10 seconds and then off for 10 seconds no?

pins 0 & 1 are the serial port pins, which you have enabled (serial.begin).

Try putting rfmotor on a different pin.

I believe I didn't connect enough wires to the H-bridges on the stock board... Does each motor require four wires? 2 for each direction?