[ERROR] Stepper motor is not rotate

I uploaded this code and the stepper motor is not rotated anymore. This code is about to open the green LED, rotate the stepper motor, and RGB light sensor start detected. Then, of RGB light sensor detect green (value = 65535) the motor will stop. The result is the RGB light sensor and LED are working but the stepper motor is not working anymore (not rotate).

But I try to up the code that write only about stepper motor to rotate and it work.

Here is my code

#include <Wire.h>
#include "SparkFunISL29125.h"
#include <Stepper.h>

SFE_ISL29125 RGB_sensor;

const int stepsPerRevolution = 12 ; 
Stepper myStepper(stepsPerRevolution, 14, 12, 13, 15);
int stepCount = 0; 

//Green
const byte ledg_gpio = 32;

//Blue
const byte ledb_gpio = 35;

void setup(){
  //Initialize serial communication
  Serial.begin(115200);

  //Initialize ISl29125
  RGB_sensor.init();

  //Green LED
  pinMode(ledg_gpio, OUTPUT);

  //Blue LED 
  pinMode(ledb_gpio, OUTPUT);
}

void setZeroPosition(){
  unsigned long previousMillis = 0;
  const long interval = 1000;
  unsigned long currentMillis = millis();
  digitalWrite(ledg_gpio, HIGH);
  myStepper.setSpeed(500);
  myStepper.step(1);
  bool motor_state = true;
  while (motor_state) {
    unsigned int green = RGB_sensor.readGreen();
    Serial.println(green,DEC);
    if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
     
    if (green == 65535){
      motor_state = false;
    }
  myStepper.step(0);
  digitalWrite(ledg_gpio, LOW);
  }
}
}

void loop(){
  setZeroPosition();
}
const int stepsPerRevolution = 12 ; 

That looks like a very small number of steps per revolution. What type of stepper motor are you using ?

Nema17 Stepper Motor 42 Hybrid Stepper Motor 2 Phase 17HS2408.

Please post a link to the actual motor that you have

12 steps per revolution still seems very unlikely

You say

which implies that the motor used to work. Has it ever worked ?
How is the motor powered ?

Stepper motor > https://shopee.co.th/สเต็ปเปอร์มอเตอร์-Nema17-Stepper-Motor-42-Hybrid-Stepper-Motor-2-Phase-17HS2408-พร้อมสายไฟ-i.167942403.7311955205

L9110S H-bridge Stepper Motor Dual DC Driver Controller Board > https://shopee.co.th/พร้อมส่ง-L9110S-H-bridge-Stepper-Motor-Dual-DC-Driver-Controller-Board-i.5401692.1540697025

which implies that the motor used to work. Has it ever worked ?

  • I worked when use this code
#include <Wire.h>
#include <Stepper.h>

const int stepsPerRevolution = 12 ; 
Stepper myStepper(stepsPerRevolution, 14, 12, 13, 15);
int stepCount = 0; 

void setup(){
  //Initialize serial communication
  Serial.begin(115200);

}

void loop() {
  digitalWrite(ledg_gpio, HIGH);
  myStepper.setSpeed(500);
  myStepper.step(1);
}

Where did you get the figure of 12 steps per revolution ?

I try by myself and this number is worked.

Please post the sketch where it worked