how to stop the bi-directional motor

Hi, am trying to control the 12V motor which is mounted on the Thermal Imaging lens using my code. So, if i press the ‘P’ from keypad then motor will rotate in clockwise direction. And, if i press the ‘N’ then motor will rotate in anti-clockwise direction. But, now the problem is once i press the ‘P’ motor is keeps on rotating in clockwise direction(am not able to stop this). Similarly, if i press the ‘N’ motor is keeps on rotating in anti-clockwise direction(am not able to stop this). Moreover, i would like motor should be in standstill position. But, actually it is running initially as soon as i give the 12V across the coil of relay though i make LOW across the base of 2N3904 Transistor.
Here, is my code :

/*
  #sourcefile  : BidirectionalMotor_control_using_keypressed.ino
   #Description : To runs the Thermal Imaging motor Lens in clockwise direction if we pressed a key 'P' and then run in the anti-clockwise direction if we pressed a key 'N'.  
  */
//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
#define MOTOR 4                  // TIP Transitor is connected across the Common Pin of realy 
#define DIR 5                    // General purpose transistor 2N3904 connected acoss the Coil Pin of realy
char user_keypressed = 0;        // For incoming serial data

//-----------------------------------------------------------------------------
// System Initialization
//-----------------------------------------------------------------------------
void setup() 
{
    Serial.begin(9600);          // Opens serial port, sets data rate to 9600 bps
    pinMode(MOTOR,OUTPUT);       // Configures the specified pin 4 (as declared globally) to behave an output
    pinMode(DIR,OUTPUT);         // Configures the specified pin 5 (as declared globally) to behave an output
    digitalWrite(MOTOR,LOW);     // To make motor off initially
//    delay(100);                  // wait for spikes to dissipate while flyback when coil deenergizes
    digitalWrite(DIR,LOW);       // To make motor off initially
    //delay(100);                  // wait for spikes to dissipate while flyback when coil deenergizes
}

void loop() 
{

//  digitalWrite(MOTOR,LOW); 
  digitalWrite(DIR,LOW); 
     if (Serial.available() > 0)                 // send data only when you receive data
         {
              user_keypressed = Serial.read();   // read the incoming byte
                
              Serial.print("I received: ");      // say what you got
              Serial.println(user_keypressed);
                  
              if( user_keypressed == 'p' || user_keypressed =='P' )
                {
                                    Serial.println("In If");
                    digitalWrite(DIR,LOW);       //clockwise direction
                    delay(100);                  //wait for spikes to dissipate
                    digitalWrite(MOTOR,HIGH);    //Sets the Motor on
                    delay(200);                  //wait for spikes to dissipate 
                    digitalWrite(DIR,LOW);     //Sets the Motor off
                    delay(100);                  //wait for spikes to dissipate
                    digitalWrite(DIR,LOW);
                }
                else if( user_keypressed == 'n' || user_keypressed == 'N' ) 
                {
                                    Serial.println("In Else If");
                    digitalWrite(DIR,HIGH);      //anticlockwise direction
                    delay(100);                  //wait for spikes to dissipate
                    digitalWrite(MOTOR,HIGH);    //Sets the Motor on
                    delay(200);
                    digitalWrite(MOTOR,LOW);     //Sets the Motor off
                    delay(100);                  //wait for spikes to dissipate
                }
                else
                {
                  Serial.println("In Else");
                     digitalWrite(DIR,LOW);      //motor off
                     delay(100);                 //wait for spikes to dissipate
                     digitalWrite(MOTOR,LOW);  
                }                
         }
}

The circuit i have refereed from here http://www.me.umn.edu/courses/me2011/arduino/technotes/dcmotors/bidirectional/bidirMotor.html

Looking forward waiting for some suggestions!!!

Change the tests for the value of user_keypressed from if to while and set the value of user_keypressed to another value if no key is pressed. That way the motor will move while a key is pressed and stop if is not.

Change the tests for the value of user_keypressed from if to while and set the value of user_keypressed to another value if no key is pressed. That way the motor will move while a key is pressed and stop if is not.

Why not just clear user_keypressed after either P or N is pressed?

Probably not the only problem but the last command doesn't match the comments:

digitalWrite(MOTOR,HIGH);    //Sets the Motor on
                    delay(200);                  //wait for spikes to dissipate 
                    digitalWrite(DIR,LOW);     //Sets the Motor off

Should that be:

digitalWrite(MOTOR,HIGH);    //Sets the Motor on
                    delay(200);                  //wait for spikes to dissipate 
                    digitalWrite(MOTOR,LOW);     //Sets the Motor off

That site is one of the worst electronic sites I have come across, it is wrong on a lot of counts. Here there is no diode across the relay coil and the motor could do with some diodes as well. The motor is allowed to stop by simply free wheeling, where as if you can make the motor stop much quicker by connecting the windings together. Have a look at this:- http://www.thebox.myzen.co.uk/Workshop/Motors_1.html