Reputation: 10119
I am using an arduino uno and I am trying to control a motor with two inputs which I found in a small car I used to have as a child. I connected the first pin of the motor to the arduino ground and the second one to the VCC and the motor started turning. However, when I write the following code the motor doesn't work.
void setup() {
pinMode(8,OUTPUT);
digitalWrite(8,HIGH);
}
void loop() {
}
(I have connected the first pin of the motor to the ground and the second one to pin 8 of arduino). Does anybody know why that happens?
Upvotes: 0
Views: 366
Reputation: 8327
This is not how Arduino is supposed to work with power consuming stuff (like mhopeng said, you may use LED in such a scheme, but not something more consuming): a motor should be between GND and 5V and if you want to control it, you have to use a transistor connected to an output pin.
I had a similar question once, it may be of help, too. Also, it may be a good idea to ask further questions at arduino.SE.
Upvotes: 0
Reputation: 1081
You can only get a certain amount of current from an Arduino output pin. In general, you can light an LED with a direct connection to an output pin, but motors require more current. A detailed discussion is here.
To control a device such as a motor which needs more current than the output pin can provide directly, you can use an external transistor. You can buy circuits that implement this idea, such as this Motor Shield for Arduino.
Upvotes: 1