motor with arduino!

hi every one, im trying, to move a motor with the arduino, im new at arduino, its a motor of 6 volts, i have conected the batery to arduino, but i don't now how to connect the motor, in analogs, in digitals, i dont know where.
thank you for help me(sorry for my bad english) :slight_smile:

If the motor draws more than about 30 mA (and it probably does) you will need a transistor to switch the power:

http://bildr.org/2011/03/high-power-control-with-arduino-and-tip120/

If you want to vary speed with software, use a PWM output and "analogWrite()".

If you want to reverse direction you will need an H-bridge. Look for a "motor shield".

thank you, you are my savior! you are the best! thank you!

this will be okay for the motor?
int motorPin = 9;
void setup()
{
pinMode(motorPin, OUTPUT);
}

void loop()
{
int onTime = 2500;
int offTime = 1000;

analogWrite(motorPin, HIGH);
delay (onTime);
analogWrite(motorPin, LOW);
delay (offTime);
}

That won't work well because "HIGH" is defined as 1. You'd be switching between OFF (0) and 1/256th on (1) which is almost the same thing. If you want on-off control use digitalWrite() with LOW for OFF and HIGH for ON or use analogWrite() with 0 for OFF and 255 for ON.

thank you! but the digitals pins pwm are positive? i don't now please help me!

filipeishon:
thank you! but the digitals pins pwm are positive? i don't now please help me!

I don't understand your question. Please try again.

if u mean that u can use pwm pins as power suply the anwser is: depending on the current-draw of the motor, yes (btw there is no max-Voltage differnce between digital and pwm..)
the arduino i/o pins can output max 40 mA. for example: if the motor is drawing 200mA u will need to connect the motor serpartly to a power source, than use a transistor like mentionted by johnwasser.

lots of these stuff is also all around the net (hint: google)
just search and you will find, when u still dont understand something its worth posting.

nick