Please note that angle is a char so if you type 30 angle will be first 3 and thereafter it will be zero.
you must read in multiple characters, convert that into an integer and then you can do the motor math.
void loop()
{
while (Serial.available())
{
char angle = Serial.read();
Serial.println(angle); // <<<<<<<<<<<<<<<<<<<<<< CHANGE THIS LINE TO SEE
if(angle >= 0 && angle <= 30)
{
// write output for 'M1'
analogWrite(pwm_motor1, LOW);
digitalWrite(dir1,LOW);
// write output for 'M2'
analogWrite(pwm_motor2, LOW);
digitalWrite(dir2,LOW);
}
else if(angle > 30 && angle <= 90)
{
analogWrite(pwm_motor1, HIGH);
digitalWrite(dir1,LOW);
// write output for 'M2'
analogWrite(pwm_motor2, HIGH);
digitalWrite(dir2,LOW);
}
}
}
PS,
using CTRL-T in your IDE before posting, saving or uploading makes your code more readable!