Go Down

Topic: motor with arduino! (Read 854 times) previous topic - next topic

filipeishon

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) :)

johnwasser

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".
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

filipeishon

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

filipeishon

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);
}

johnwasser

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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up