Controlling the speed of a dc motor?

AWOL:
So, no code and no schematic?
Good luck.

Well the schematic is https://sites.google.com/site/arduinosoapy29/motor-speed-controller/diagram2.png?attredirects=0 and i believe i followed it correctly, however there are a few differences

tonyrogers10195:
2k resistor, a 9v battery, a 2N3904 transistor(also an NPN so it shouldn't matter) and instead of a potentiometer for PWM I'm using a button that increases the value by 15 each time it's pushed.

Heres my code...

#include <Servo.h> 
#include <IRremote.h>

int RECV_PIN = 11; 

Servo myservo;  // create servo object to control a servo 
int val = 130;    // variable to read the value from the analog pin 
int motor = 0;
IRrecv irrecv(RECV_PIN);
decode_results results; 

void setup() 
{ Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  irrecv.enableIRIn();
 } 
 
void loop() {   
  if (irrecv.decode(&results)){
    Serial.print("motor = ");
    Serial.print(motor);
    Serial.print("\t remotevalue = ");
    Serial.println(results.value);
    analogWrite(3,motor);
  
  if (results.value == 89149445){ //this is the IR code for "UP" button
    motor = motor + 15;}
    
  if (results.value == 83908956){//IR for "down"
    motor = motor - 15;}
     
   
  if (results.value == 83887105){
  val = val - 15;}
  
  if (results.value == 83920001){
  val = val + 15;}
  
  if (results.value == 87556157){
  val = 90;}
 
  myservo.write(val);  // sets the servo position according to the scaled value 
  

irrecv.resume(); // Receive the next value

  }
}