Running a Dc motor.. help!!!

hi,
im fairly new to arduino programming. i was trying to connect a dc motor. i tried connecting it to pin 9 and GND but it doesn't work. here is my code

int motor = 9;

void setup(){
pinMode(motor,OUTPUT);
}

void loop(){
digitalWrite(motor,HIGH);
delay(2000);
digitalWrite(motor,LOW);
delay(2000);

}

I also tried with a transistor and a 9V battery. but still no results. can any1 help me as to where i am ging wrong..

Plz help!

Hooking it straight up to an I/O pin will have tried to draw waaaaaaaaaaaaaaaaaaay too much current . (Maybe an amp or more compared to the 10s of mA allowed.)

EDIT: It's not outside the realms of possibility that you've fried your Arduino, especially if you didn't have a flyback diode.

It's impossible to tell why your transistor set-up didn't work without a schematic.

MORE EDIT: Have a look at this tutorial

Arduino working fine. thankgod! :smiley: I connected an LED to check and it works :slight_smile: I hv attached the circuit diagram that im using to hook up the motor to the Arduino. plz check. thankyou :slight_smile:

motor circuit diagram.jpg

Circuit is good but which transistor? How much current does the motor draw
under load? Can the transistor handle a current that large? Will it saturate
with only 4mA of base current at that load?

I'd definitely change the 1k resistor to 150 ohm, you want to saturate the
transistor, not just have it vaguely conducting.

Small motors typically take 0.1upto 1A depending on load, few small switching
transistors can handle 1A given 30mA of base drive, for instance. 30mA is
about the maximum you can pull from an Arduino pin safely (absolute maximum
current 40mA).

CassWin:
I hv attached the circuit diagram that im using to hook up the motor to the Arduino. plz check.

You need to hook the ground from your pic (the battery -ve) to an Arduino GND pin, else the transistor won't recognise the 5V on its base, since it'll have no 0V to measure against.