I'm brand new to the Arduino, already had a lot of fun with it though. As a programmer, the language is coming to me very easily.
What I'm trying to do is get a motor to run when I set a pin to HIGH, or however else I can do it.
If I could specify how much voltage is being sent to it to control the speed, that would be cool too.
Anyway, below is the code I have.
/*
This is a motor test.
I'm checking to see if I can run a motor
(in one direction) by setting a pin to HIGH.
*/
int motorPin = 8;
void setup() {
pinMode(motorPin, OUTPUT);
}
void loop() {
digitalWrite(motorPin, HIGH);
}
As you see, it's extremely simple - can't get simpler. However, when I run the code, it does nothing. The pins are all set correctly with the wires and whatnot - so that's not the issue.
Any ideas?
EDIT: When I plug an LED into that same pin, it lights up just fine.
First of all its not a good idea to run the motor directly from the arduino pins. You can damage the arduino. If you want good control of motors you'll want to get or make a motor shield. This site should tell you all you need to know about controlling motors. http://www.ladyada.net/make/mshield/index.html
You'll also find there are motor libraries that give you more specific control of motors. Calling direction and speed.
If your motor doesn't draw too much current, you could make a simple mosfet on/off control like below. If you wanted to control the speed then you could send send varying PWM to the mosfet.
Thanks everybody for the great tips! I really appreciate it. I'll definitely be reading these links today and learning more about MOSFET... whatever that is
Essentially, they are transistors which have largely taken over the role of what used to be done by larger power transistors (those in TO-3 cases and larger); they tend to be smaller and switch faster, and are able to handle higher currents with less heat loss than a regular transistor (or at least, that is how I understand things). That doesn't mean you can't drop the heatsink; you should still account for that. They also tend to be simpler to interface with; you don't (typically?) need a "bias" resistor to control the gate of the FET (unlike transistors, which need the bias resistor on the base to control current running into it).
There are many different kinds of FETs available (just like transistors) - choose wisely (maybe others here will reccommend what they like to use for general purpose needs like driving relays, solenoids, motors, lights, h-bridges, etc).