Hello, I'm currently repurposing my old kevin the minnion toy by disecting it and inserting an Arduino R3 UNO, a HC-SR04 ultrasonic sensor for avoiding obstacles, a ULN2003 Motor Driver Board and a 28BYJ-48 Stepper Motor to control side wheel one, a Breadbord power supply model connected to a 9v battery connecter transmitting power to the module via a 9v battery, a servo motor to control side wheel 2, and lastly a 3v DC motor in the back for stability. Honestly, I think this is a suitable beginner project to get me used to doing big projects without following any 1 specific video guide, but I'm open to listening if you disagree.
Till now, I have disected Kevin, connected the ultrasonic sensor, power supply module, 9v battery, 9v battery connecter, arduino, Motor Driver Board, and the stepper motor all together and managed to combine two different .ino files from github to make the code you can see below.
My issue here is that the stepper motor will not rotate even though they are no errors whatsoever. I tripled checked the pins and they are correctly arranged and what makes it even more weird is that the ultrasonic sensor is doing exactly what it needs to.
If you have any other concerns such as questioning if I can do it, giving me tips on what to use etc, feel free to post them I am very open to listening and I truly welcome it as I am new to engineering. Here are my components:
#define STEPPER_PIN_1 9
#define STEPPER_PIN_2 10
#define STEPPER_PIN_3 11
#define STEPPER_PIN_4 12
int step_number = 0;
long duration;
int distance;
const int trigPin = 6;
const int echoPin = 5;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(115200);
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);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, 20000); // 20ms timeout (~3.4m max)
distance = duration * 0.034 / 2;
Serial.println(distance);
delay(100);
}
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);
}
}
step_number++;
if(step_number > 3){
step_number = 0;
}
}
// Thank you for your assistance.```