Issue Powering DC Motor

Hi all. I just recently purchased an Arduino Starter Kit. I have no experience, but I am trying to learn my way with all the topics/videos I can find.

My first project was intended to be an object avoiding robot, but I could not get the motors to work. So I decided to take a step back and just work on powering the DC Motor that came with the Kit before moving on to anything more. However, even with this project I am facing a lot of difficulties. Again, this is my first project so sorry if I made some blatantly obvious mistake, I'm just trying to learn my way.

Attached is the image of my current schematic and the code I'm using to run the motor. I'm using a 2222A transistor, a 220 ohm resistor, and a 1N4007 Diode.

I have read through countless articles and watched way too many videos, so any help you could give would be much appreciated.

Code:

int motorPin = 3;

void setup() {

}

void loop() {
digitalWrite(motorPin, HIGH);
}

Before you use a pin as an output, you must set it as an output with

pinMode(pin, OUTPUT)j

that solved it! thank you

So I have another question now that that is solved. I can get the motors to run just fine, but I was wondering how I can go about getting them to start and stop?

I tried this code, but to no avail:

int motorPin = 3;

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

void loop() {
digitalWrite(motorPin, HIGH);
delay(1000);
digitalWrite(motorPin, LOW);
}

Put another delay after the digitalWrite(motorPin, LOW). As it is, the pin goes LOW then loop() starts right away and the pin goes HIGH. The pin is LOW only few microseconds.