Really new to Arduino

What I am trying to do is to control the speed of a DC motor using a Arduino and a potentiometer

As in the more I turn the potentiometer the faster the motor spins

Currently I have the potentiometer directly connected like this

and I have the motor directly connected to the Digital 9 pin and the other end of motor connected to ground on Arduino

This is the code that I wrote

#include <Servo.h>
#include <avr/pgmspace.h>

//Servo range closed 63-155 open

int potentiometer = 2;
int Motor = 9;
int val;
int val2;

void setup()
{ Serial.begin(9600);
pinMode(potentiometer, INPUT);
pinMode(Motor, OUTPUT);
}

void loop()

{
val = analogRead(potentiometer);
val2 = map(val, 0, 1023, 0, 255);
analogWrite(Motor, val2);

}

When I turn the potentiometer I get a small humming sound from the motor but it does not get enough power to move, the motor is rated 1.5 volts

so can please someone tell me what I am doing wrong?

so can please someone tell me what I am doing wrong?

you are in your own words:-

have the motor directly connected to the Digital 9 pin and the other end of motor connected to ground on Arduino

While the motor may be only 1.5V it is taking more current than the arduino can supply and in the process damaging that output pin.

You need a transistor, see:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

Okay I have been working on my project

I bought a transistor, a diode, a voltage controller and a 9 volt battery

I used a diode between the emitter of the transistor and changed the output to the 8 pin and connected it to other end of diode.

I basically hooked up the voltage controller so I can get 5 volts to run my motor, the output of the voltage controller goes to the motor, the negative part of the motor goes to the transistor collector, and the emitter goes to the common ground.

and my project is still not working

Is it because I am using the wrong specs for transistor?

specs are power dissipation = 75w
collector emitter voltage = 60v
collector base voltage = 70v
emitter base voltage = 5v
collector current = 10 A

You are wiring it up wrong. Wire it up like in the link.
Emitter to ground, base to a resitor and then on to an arduino output. Motor to collector, other end to 5V. Diode across the motor, cathode to +.
Remember to make the arduino pin an output in your sketch.

Heres a picture of my setup, I wired according to your last post but it is still not working

And here is the code I am using, I am seriously stumped any help you can provide will be appreciated

#include <Servo.h>
#include <avr/pgmspace.h>

//Servo range closed 63-155 open

int potentiometer = 2;
int Motor = 8;
int val;
int val2;

void setup()
{ Serial.begin(9600);
pinMode(potentiometer, INPUT);
pinMode(Motor, OUTPUT);
}

void loop()

{
val = analogRead(potentiometer);
val2 = map(val, 0, 1023, 0, 255);
analogWrite(Motor, 255);

}

It is very hard to see everything but there are many things wrong.

  1. When posting code select it and then hit the # icon.
  2. The diode is the wrong way round, you have probably by now blown this up now.
  3. You have no capacitors on the input and output of your regulator.
  4. You are using pin 8 to produce a PWM output. PWM does not work on pin 8, look at the board and you might see (depending on the board) a ~ symbol in front of a pin number. This means it is capable of PWM. On the Uno this is pins 3, 5, 6, 10 & 11.
  5. You are using a small 9V battery, these have very little capacity and don't last very long.