How to control an encoder DC motor with the values I input on the serial monitor

const int PWM = 9;          // PWM pin
const int motorPin1 = 10;   // motor in1
const int motorPin2 = 11;   // motor in2
const int encoderPinA = 2;  // encoder PinA
const int encoderPinB = 3;  // encoder PinB
volatile long encoderPos = 0;  
const float ratio = 360.0 / 19.0 / 52.0;  // 엔코더 

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(PWM, OUTPUT);
  pinMode(encoderPinA, INPUT_PULLUP); 
  pinMode(encoderPinB, INPUT_PULLUP); 
  attachInterrupt(0, doEncoderA, CHANGE);
  attachInterrupt(1, doEncoderB, CHANGE);
  Serial.begin(115200);  
}

void doEncoderA() { encoderPos += (digitalRead(encoderPinA) == digitalRead(encoderPinB)) ? 1 : -1; }
  //Serial.println("doEncoderA"); 
  //Serial.println(encoderPos);
void doEncoderB() { encoderPos += (digitalRead(encoderPinA) == digitalRead(encoderPinB)) ? -1 : 1; }
  //Serial.print("doEncoderB");
  //Serial.println(encoderPos);

void loop() {
  if (Serial.available()) {
    float targetAngle = 0;
    targetAngle = Serial.parseFloat(); 
    Serial.print("targetAngle: ");
    Serial.println(targetAngle);
    
    float motorDeg = abs(float(encoderPos) * ratio);
    Serial.print("motorDeg: ");
    Serial.println(motorDeg);

    float angleDifference = targetAngle - motorDeg;
    Serial.print("angleDifference: ");
    Serial.println(angleDifference);

    if (angleDifference > 0) { // clockwise rotation
      analogWrite(PWM, 100); 
      digitalWrite(motorPin1, HIGH);
      digitalWrite(motorPin2, LOW);
      Serial.println("clockwise");
      Serial.println(motorDeg);
      Serial.println(encoderPos);
    } 
    if (angleDifference < 0) { // counterclockwise rotation
      analogWrite(PWM, 100); 
      digitalWrite(motorPin1, LOW);
      digitalWrite(motorPin2, HIGH);
      Serial.println("counterclockwise");
      Serial.println(motorDeg);
      Serial.println(encoderPos);
    }
    if (angleDifference == 0) {
      analogWrite(PWM, 0); // when motor arrives at targetDeg, the motor will stop.
      digitalWrite(motorPin1, LOW);
      digitalWrite(motorPin2, LOW);
      Serial.println("END");
    }
  }
}

I want to create a sketch that defines the target angle based on the values I input in the serial monitor and makes the encoder DC motor move according to the difference in the current encoder motor angle.
With the code I have written above, the DC motor doesn't move the desired angle and keeps rotating.
Please help me.

To manage certain angles stepper motors are favourable. Plesae post the datasheet of the motor and its decoder.

I use this DC motor with encoder.
The reduction ratio is 1/19 :grinning:
also motor drive I am using is L298N.

That's the encoder. Where is the motor data?
There's no data telling the number of pulses per revolution. No index pulse so a home switch will be needed
Does the encoder tell motor movements or output axle moves?

Yes, the encoder tells motor movements and output axle moves.
I think there is no problem with the connection to the Arduino board and DC motor.
It seems that the motor is continuously rotating because the sketch is not made in the direction I want. I want the encoder motor to work on the serial monitor and I want the encoder motor to rotate by that value.

What does the Seria.print tell?
The abs looks strange. What is the range You send on serial? Max resp. Min values?

The value I send to the serial monitor is the value that I want the motor's encoder to rotate to.

Why not replying to the entire question?

What more? There are more printouts.
Adding more detailed Serial.println should be used.