PID control for a 24 DC motor

Hello,

I need to keep the speed of my motor at 2000 rpm. I'm using an Arduino UNO and an optocoupler LM 393

I already made the code to acquire the RPMs and to send the servo signal to the motor driver

Here is the code:

#include <MsTimer2.h>
#include <PID_v1.h>
#include <Servo.h>

volatile int counter=0, rotation;
//static int rotation=0; 
Servo myservo;
int val;  
double Input, Setpoint, Output;
int kp,ki,kd;
PID myPID(&Input, &Output, &Setpoint,2,0,0, DIRECT);

void docount(){  /* counts from the speed sensor */
  counter++;  // increase +1 the counter value
} 

void timerIsr() {
 MsTimer2::stop(); // stop the timer
 //int rotation = (counter*60);  // divide by number of holes in Disc
 rotation = (counter*60);  // divide by number of holes in Disc
 Serial.print("motor speed: ");
 Serial.print(rotation,DEC);  
 Serial.println(" Rotation per minute"); 
 counter=0;  //  reset counter to zero
 MsTimer2::start();  //enable the timer
}

void setup() {
  Serial.begin(9600); 
  myservo.attach(9);
  MsTimer2::set(1000,timerIsr); // set timer for 1 sec (Resolution in ms)
  attachInterrupt(0, docount, FALLING); // increase counter when speed sensor pin goes High
  MsTimer2::start();// enable the timer
  Setpoint=2000;  //rpm
  myPID.SetMode(AUTOMATIC); //turn PID on
}

void loop() {
  Input = map(analogRead(1),0, 1023, 94, 136);
  myPID.Compute();
  //val = analogRead(1);            // reads the value of the potentiometer (value between 0 and 1023)
  //val = map(val, 0, 1023, 94, 136);     // scale it to use it with the servo (value between 0 and 180)
  //myservo.write(136);                  // sets the servo position according to the scaled value
  myservo.write(Output);      
  Serial.println(Setpoint);
  Serial.println(Input);  
  Serial.println(Output);

The thing is that there are still some variations in the speed and I'd like to use a PID control to assure that the speed of the motor stays at 2000.

I'm new using Arduino and I'm not sure which should be the input of my PID System.
Firstly I thought that it should be the rotation variable but now I'm not sure if the input should also be a value with a max of 255 like the output or if its possible to use the period of the sensed pulses as the input of my system

Could somebody please give me guidance on this.

I'm thinking to calculate the constants with the Simulink autotuning tool