how to conect a motorDC to arduino

hi!!!
I would like to know how to conect a motor dc to the arduino for just to control de on and off, nothing else. I tryed with this schematic and this code but doesn't work,

int motorPin =13;
void setup() {
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
}
void loop() {

digitalWrite(motorPin,HIGH);
delay(500);
digitalWrite(motorPin,LOW);
delay(500);
}

and if it's possible to conect the motor to the 5v pin of the arduino, cause the motor can work with low battery such as 1,5v to 6v.

thank you very much for your time

I'm fairly new to the Arduino but I don't think pin13 is your best choice as I think it is hooked to other things on the board. As to the power, if you are using the USB for power you have a fairly low current you can draw for everything you are powering and run the risk of reseting the Arduino if the power is pulled too low. Someone else will know more and set both of us straight I'm sure. :slight_smile:

you must connect Arduinos ground to the 9v batteri ground (-), else it wont work.

It's usually a bad idea to run motors from Arduinos powersupply.

thank you for your comments,
I've been investigating and both of you had reason.
pins 9,10,11 are analog output, or PWM, and the battery it was a bad idea, so I conected the motor to the diode in paralel, then the catode to the ground and the anode to the transistor base. the colector to the pin 10 and the emisor to 5v, and it works!!!!

(I think I explain with good words, I'm just a beginner.)

now it's time to do something good with this!!!