28byj-48 doesn't turn to 360°

Hello everyone, I am working on a camera that tracks an object while sliding . The camera rotates with the 28byj-48 stepper motor. In order to have the best accuracy I need to command this motor with a specific angle.
I coded a function that convert the angle required in number of steps . But when I tried this function with 360° , the motor rotates for only about 250° and I don't understand why ! If any of you have ideas on how I can get a correct angle I'll be glad to know it.
(I don't want to use an encoder, even it is the best answer. I want to use the steps of the motor).
I am using a arduino nano.
Thank you ! Here's my code:

#define SW A2
#include <stdio.h>
#include <Wire.h> // Library for I2C communication


int motorPin1 = 4;  // Blue   - 28BYJ48 pin 1
int motorPin2 = 5;  // Pink   - 28BYJ48 pin 2
int motorPin3 = 6; // Yellow - 28BYJ48 pin 3
int motorPin4 = 7; // Orange - 28BYJ48 pin 4
int motorSpeed;
int pas = 0;
int resolution_stepper2 = 4096;



void setup() {
  // put your setup code here, to run once:
 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPin3, OUTPUT);
 pinMode(motorPin4, OUTPUT);
 pinMode(Ya,OUTPUT);
 pinMode(SW,INPUT_PULLUP);
 Serial.begin(9600);
 motorSpeed = 1; 
}

void loop() {
 angle2step(360);
 delay(3000);

}

void counterclockwise (){
 // 1
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 2
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay (motorSpeed);
 // 3
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 4
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 5
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 6
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin4, HIGH);
 delay (motorSpeed);
 // 7
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, HIGH);
 delay(motorSpeed);
 // 8
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, HIGH);
 delay(motorSpeed);
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
//delay "motorSpeed" between each pin setting (to determine speed)

void clockwise(){
 // 1
 digitalWrite(motorPin4, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 2
 digitalWrite(motorPin4, HIGH);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay (motorSpeed);
 // 3
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 4
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 5
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 6
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin1, HIGH);
 delay (motorSpeed);
 // 7
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, HIGH);
 delay(motorSpeed);
 // 8
 digitalWrite(motorPin4, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, HIGH);
 delay(motorSpeed);
}

void angle2step(float angle){
  Serial.println(angle);
  int steps = round(angle * (resolution_stepper2/8/360)); //this line converts the angle required into number of steps. 
                                                          //resolution_stepper is divided by 8 because of the functions clockwise and counterclockwise
  if (angle < 0.0)
  {
    for (int i=0; i < steps; i++){
      counterclockwise ();
      Serial.println("coutnerclockwise");
    }
  }
    if (angle > 0.0)
  {
    for (int i=0; i < steps; i++){
       clockwise ();
       Serial.println("clockwise");
    }
  }
}

because you do integer arithmetic wrong :slight_smile:

int steps = round(angle * (resolution_stepper2/8/360)); //this line converts the angle required into number of steps.

4096/8=512.00
4096/8/360 = 1.42222
(int)1.42222 = 1
--> 360° is mapped to 253.12320°

Thank you ! I understand now!