control stepper motor over serial

Hello guys,
i’m currently working with my coursework project which is controlling stepper motor over serial. so i sent number from 0 until 360 over serial and the motor will be step according to the angle that i’ve sent but the motor is not working according to the objective. All the electrical connection same like picture that i have attach together. The motor driver that currently i’m using is Easydriver from sparkfun.

Here is my code so far.

#define DIR_PIN 2
#define STEP_PIN 3

void setup() { 
  pinMode(DIR_PIN, OUTPUT); 
  pinMode(STEP_PIN, OUTPUT); 
  Serial.begin(9600);
} 

void loop(){ 
  float val;
if (Serial.available() > 0 );
val = Serial.read() - '0';
  //rotate a specific number of degrees 
  rotateDeg(val, .1); 
  delay(1000);

  rotateDeg(-val, .1);  //reverse
  delay(1000); 
}
void rotateDeg(float deg, float speed){ 
  //rotate a specific number of degrees (negative for reverse movement)
  //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
  int dir = (deg > 0)? HIGH:LOW;
  digitalWrite(DIR_PIN,dir); 

  int steps = abs(deg)*(1/0.225);
  float usDelay = (1/speed) * 70;

  for(int i=0; i < steps; i++){ 
    digitalWrite(STEP_PIN, HIGH); 
    delayMicroseconds(usDelay); 

    digitalWrite(STEP_PIN, LOW); 
    delayMicroseconds(usDelay); 
  } 
}

Hopefully u guys can help me out. Thanks.

val = Serial.read() - '0';

This ensure that you can only ever rotate between 0 and 9 degrees. Is that what you want?
Is that what is happening?
Because:-

but the motor is not working according to the objective.

Does not cut it here as an explanation of what is happening.

Post the datasheet for your MOTOR

raschemmel:
Post the datasheet for your MOTOR

this is the datasheet of my motor

Minebea 17PM-J.pdf (85 KB)

Grumpy_Mike:

val = Serial.read() - '0';

This ensure that you can only ever rotate between 0 and 9 degrees. Is that what you want?
Is that what is happening?
Because:-

but the motor is not working according to the objective.

Does not cut it here as an explanation of what is happening.

so then just leave the code like this

val=Serial.read();

so then just leave the code like this

No.
Serial.read only reads one character that is one key stroke an ASCII character it can only be between 0 and 9.

You need to take a photo of the s/n label on the motor and post it so we can see the ENTIRE part number.
17PM-J is just the prefix, and the datasheet lists data for all the flavors, so without your complete part number it is not much help.

Minebea 17PM-J.pdf (85 KB)

stepper-motor-wiring.png

unipolar_ill_02.jpg

No.
Serial.read only reads one character that is one key stroke an ASCII character it can only be between 0 and 9.

thanks for the tips man!

i just simply change the code from

val = Serial.read() - '0';

to this

val = Serial.parseFloat();

thanks again.