When i run the code on the Arduino the Stepper only does a small turn every cycle. How can i make that constantly turning?

 #include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
//Servo Teil
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  // initialize the serial port:
    myservo.attach(3);  // attaches the servo on pin 9 to the servo object


void loop() {
  // step one revolution  in one direction:
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position

  • Does the stepper motor work correctly, when you try it with one of the libraries examples? With your current code the stepper motor should do one revolution (200 steps) per loop() iteration (stopping after the 200 steps, then the servos moves and then the stepper starts again in the next iteration). – chrisl Apr 16 at 18:55
  • rewrite the loop() code ... get rid of the for statements ... refer to the example sketch blinkWithoutDelay for a way to run code at an interval .... every 15 ms move the stepper, then move the servo ... increment/decrement pos accordingly – jsotola Apr 16 at 20:39
  • 1
    Yes it does as you say chrisl. Thx jsotola will try it. – Jonasoos Apr 16 at 20:53
  • You don't "let" a stepper rotate, to get it to move you have to actively step it. When you're not stepping it it stops. – Majenko Apr 17 at 14:34
  • create N square waves, where N is the number of phases in your stepper motor. Make sure the N square waves are appropriately out of phase with one another. Connect amplified versions of the square waves to the stepper motor. The motor will rotate continuously, at a speed determined by the frequency of the square waves. – Math Keeps Me Busy Apr 18 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.