Hi mates!
I´m building a rotating platform for a webcam. But I´m new to motors!
I get an electric motor from a toy car!
Then I connected the first wire to the arduino´s ground pin and the second wire to the +5V pin ,and the motor works! I also connected it to +3.3V pin and it also works.
However as I want to have the ability to switch on and off the motor rotation , I connected one wire to ground and another one to a digital pin ( for example pin 8). To test i wrote this small piece of code:
int motorPin = 8; // motor connected to digital pin 8
void setup()
{
pinMode(motorPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(motorPin, HIGH); // sets the motor on
delay(1000); // waits for a second
digitalWrite(motorPin, LOW); // sets the motor off
delay(1000);
I was expecting to have the motor rotating during 1 second, stopped during another 1 second and so on....
However nothing happens... the motor don´t rotate...
Setting the motorPin HIGH doesn´t mean that we´re providing +5V to pin 8?
What I´m doing wrong?
Generally speaking you probably can't directly drive a motor off of an arduino pin. You will probably need a transistor or relay to indirectly drive the motor. A search of the forum for "motor" will provide an evening's worth of reading.
If you haven't fried your Arduino yet, you are on the way to doing it!
Those little motors put reverse voltage spikes onto whatever power source is driving them. You need "the diode", at least, in addition to an answer to the power issues discussed by others.
"The diode" is the same one that needs to be on the coils of a relay to sink reverse voltage spikes arising from collapsing EMF when the coil is disconnected from its power. Google will find you lots of help.
Hope that reached you in time!
===
Motors: Two great classes: servo motors and the other (don't know their name... the ones that just turn and turn whenever energized)
Servo motors are more "work", but they let you say, for example, "turn 5 degrees clockwise". (When the motor is "running", it is just doing lots of "turn 5 degress"es, one after the other.)