Let me begin by saying I'm confident on the programming side of things but when it comes to electronics I'm a novice. So if this question is too dumb, apologies in advance.
Basically, I've bought the arduino kit from OOmlout and worked my way through a few books on Arduino. most of the books involve LED's and I want to play with a DC motor. I believe the motor I have is 9 volts. I know the arduino outputs five. I'm powering the board via USB. I know that USB can output various levels of electricity. I was wondering if I plug the motor straight into the board will it draw 5 volts ad not work OR will it start to run and fry out my arduino because its sucking too much power form the board? Given I don't want to fry my Arduino to find out, I figured I'd ask on here as a first port of call.
I am trying to learn more about electronics. I bought the Make Electronics book and it's proving useful, but it's going to take a little bit till I've got the fundamentals.
Most likely this:
"OR will it start to run and fry out my arduino because its sucking too much power form the board?"
IO pins can supply 40mA, but there is no built in limiting. DC motor looks lik a short to Gnd to an IO pin
Connect +9 to Motor'+', Motor'-' to NPN transistor collector, with emitter to Gnd.
Connect arduinon IO pin to 180 ohm resistor to transistor gate. High out will turn on transistor and let current flow thru motor.
Use a PWM pin if you want to add speed control.
But you also need to worry about inductive spikes - DC motors are inductive so some protection is generally needed (as for relays).
Thanks CrossRoads & MarkT
Just to make sure I understand:
If I take a line out of one of the digital pins it will get treated as a road to a ground connection and because it wants 9V it will take 9V and this will fry the board. If I put a 180? resistor between the pin going into a transistor this will limit the flow that the motor is trying to take(?) and allow an acceptable amount of current to charge up the transistor and then pass into the motor when it's got enough charge to discharge?
Then how do I earth this larger current from the motor negative line as it will surely have to go back into the Arduino? Do I put another resistor in before going to earth to step it down? I really am very new to the electronics bit of this.
Also if I use pin 9, 10 or 11 with analogWrite, can I limit the amount of electricity sent to the motor by limiting the flow output programmatically?
See attached - motor drive using a MOSFET. Resistor from arduino pin prevents pin from being damaged by inherent gate capacitante.
Resistor to ground keep MOSFET off during reset when IO pins are defaulted to Input until sketch starts up.
MOSFET can be an NPN transistor as well; resistor to ground is not needed.
power supply ground must connect to arduino ground for common reference point.
PWM from whatever pin limits motor current by rapidly turning on/off at ~490 Hz, amount of High time (0 = off, 255 = full on) determines how fast motor will spin.
Many Thanks CrossRoads!
The diagram is most helpful.
I'm powering the board via USB. I know that USB can output various levels of electricity.
No it can't. USB outputs five volts, the same as an Arduino.
For 9V you need a different power supply.
(Or accept that your motor will run at 5/9 of normal speed...)