NI$HANT:
If Output is negative you have to turn the motor in the other direction.
Wasn't able to get it correct, Some more light?
void loop(){
Input = encoder0Pos;
myPID.Compute();
if (Output > 0)
{
digitalWrite(directionPin, HIGH);
analogWrite(5,Output);
}
else
{
digitalWrite(directionPin, LOW);
analogWrite(5, -Output);
}
}