Rotation step motor arduino

41 Views Asked by At

I have an Arduino and a step motor, this is my code :

#include <Stepper.h>

// Définir le nombre de pas par tour
int NbrPas = 200; 


Stepper MonMoteur(NbrPas, 8, 9, 10, 11);

void setup() {
  // Vitesse à 60 tours/min
  MonMoteur.setSpeed(60);
 
  Serial.begin(9600);
}

void loop() {
  // Faire un tour dans un sens
  Serial.println("Sens 1");
  MonMoteur.step(NbrPas);
  delay(500);
}

It's for 1 round, I would like to know how to make several rounds with my step motor

1

There are 1 best solutions below

0
Gaetano Torrisi On

If you want to make several rounds, firstly you have to change the value of NbrPas setting the number of steps per revolution suited to your needs. In your case you must set int NbrPas = 2048;.

Another piece of advice I can give you is to put an adequate value to MonMoteur.setSpeed();. In 28BYJ-48 stepper motors the range is 0~17 rpm.


I think this code is fine for your case

#include <Stepper.h>

const int NbrPas = 2048;  // change this to fit the number of steps per revolution
const int rolePerMinute = 15;         // Adjustable range of 28BYJ-48 stepper is 0~17 rpm

Stepper MonMoteur(NbrPas, 8, 9, 10, 11);

void setup() {
  // Vitesse à 60 tours/min
  MonMoteur.setSpeed(rolePerMinute);
 
  Serial.begin(9600);
}

void loop() {
  // Faire un tour dans un sens
  Serial.println("Sens 1");
  makeOneRound();
  delay(500);
}


void makeOneRound() {
  MonMoteur.step(NbrPas);
}