L'esperienza che segue fa semplicemente girare il motore stepper un passo alla volta

Effettuare i collegamenti come in figura:

N.B. Prestare attenzione ai collegamenti, in particolare quando si utilizza la funzione

Stepper stepper(STEPS, 8, 9, 10, 11);

è necessario indicare in successione corretta i piedini ai quali sono collegate le 4 linee IN1, IN2, IN3, IN4.

Lo scketch da utilizzare è il seguente:

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}

void loop() {
stepper.step(1);
delay(500);
}

Lo sketch seguente invece fa effettuare un giro completo del motore stepper ogni 2 secondi (modalità blocking mode), la velocità di rotazione è di 10 rpm (giri al minuto).

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

void setup() {
// set the speed of the motor to 10 RPMs
stepper.setSpeed(10);
}

void loop() {
stepper.step(STEPS);
delay(2000);
}
 

Ultime modifiche: martedì, 6 aprile 2021, 17:26