I have a question about the stepper motor.

Excuse me, I have a question
It is error when I verify the code.
‘STEPPER_PIN_1’ was not declared in this scope.
Can anyone help me? I have no clue why this is happening.
Thanks!

#include <Stepper.h>
#define STEPPER_PIN 9
#define STEPPER_PIN 10
#define STEPPER_PIN 11
#define STEPPER_PIN 12
int step_number =0;


void setup() {
 pinMode(STEPPER_PIN_1,OUTPUT);
 pinMode(STEPPER_PIN_2,OUTPUT);
 pinMode(STEPPER_PIN_3,OUTPUT);
 pinMode(STEPPER_PIN_4,OUTPUT);

}

void loop() {
  OneStep(false);
  delay(2);
  

}

void OneStep(bool dir){
if (dir)
switch(step_number){
 case 0:
 digitalWrite(STEPPER_PIN_1, HIGH);
 digitalWrite(STEPPER_PIN_2, LOW);
 digitalWrite(STEPPER_PIN_3, LOW);
 digitalWrite(STEPPER_PIN_4, LOW);
 break;
 case 1:
 digitalWrite(STEPPER_PIN_1, LOW);
 digitalWrite(STEPPER_PIN_2, HIGH);
 digitalWrite(STEPPER_PIN_3, LOW);
 digitalWrite(STEPPER_PIN_4, LOW);
 break;
 case 2:
 digitalWrite(STEPPER_PIN_1, LOW);
 digitalWrite(STEPPER_PIN_2, LOW);
 digitalWrite(STEPPER_PIN_3, HIGH);
 digitalWrite(STEPPER_PIN_4, LOW);
 break;
 case 3:
 digitalWrite(STEPPER_PIN_1, LOW);
 digitalWrite(STEPPER_PIN_2, LOW);
 digitalWrite(STEPPER_PIN_3, LOW);
 digitalWrite(STEPPER_PIN_4, HIGH); 
 break;
}
  } else { 
  switch(step_number)
 case 0:
 digitalWrite(STEPPER_PIN_1, LOW);
 digitalWrite(STEPPER_PIN_2, LOW);
 digitalWrite(STEPPER_PIN_3, LOW);
 digitalWrite(STEPPER_PIN_4, HIGH);
 break;
 case 1:
 digitalWrite(STEPPER_PIN_1, LOW);
 digitalWrite(STEPPER_PIN_2, LOW);
 digitalWrite(STEPPER_PIN_3, HIGH);
 digitalWrite(STEPPER_PIN_4, LOW);
 break;
 case 2:
 digitalWrite(STEPPER_PIN_1, LOW);
 digitalWrite(STEPPER_PIN_2, HIGH);
 digitalWrite(STEPPER_PIN_3, LOW);
 digitalWrite(STEPPER_PIN_4, LOW);
 break;
 case 3:
 digitalWrite(STEPPER_PIN_1, HIGH);
 digitalWrite(STEPPER_PIN_2, LOW);
 digitalWrite(STEPPER_PIN_3, LOW);
 digitalWrite(STEPPER_PIN_4, LOW);
}
 }

28BYJ-48_motor.ino (1.72 KB)

#define STEPPER_PIN 9
#define STEPPER_PIN 10
#define STEPPER_PIN 11
#define STEPPER_PIN 12

You have all your pins the same name and none of them have _1 on the end. So yeah, compiler is right. There’s nothing named STEPPER_PIN_1 in this code.

The compiler isn’t going to try to guess what you meant. If you want these to have numbers on the end then out numbers on the end.

Thanks for you help!
But, there is other question!
It is error for the “else”
expected unqualified-id before ‘else’
Can you help me?

#include <Stepper.h>
#define STEPPER_PIN_1 (9)
#define STEPPER_PIN_2 (10)
#define STEPPER_PIN_3 (11)
#define STEPPER_PIN_4 (12)
int step_number =0;

void setup() {
pinMode(STEPPER_PIN_1,OUTPUT);
pinMode(STEPPER_PIN_2,OUTPUT);
pinMode(STEPPER_PIN_3,OUTPUT);
pinMode(STEPPER_PIN_4,OUTPUT);

}

void loop() {
OneStep(false);
delay(2);

}

void OneStep(bool dir){
if (dir)
switch(step_number){
case 0:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
}
} else {
switch(step_number) {
case 0:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
}
}

You got your brackets mixed up. You need an opening bracket after if(dir)

Please read the “How to use this forum” post and come back and post your code properly. Post the entire error message, don’t paraphrase it.