i have also pluged in a stepper motor in 5 mins ago pls help idk hoe to solve
also code
#include <Servo.h>
#include <Stepper.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int Forward;
const int trigPin = 5;
const int echoPin = 6;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = A0; // analog pin connected to X output
const int Y_pin = A1; // analog pin connected to Y output
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute = 15; // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
float duration, distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(11, OUTPUT);
myservo.attach(3); // attaches the servo on pin 3 to the servo object
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
myStepper.setSpeed(rolePerMinute);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Servo
//val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
//val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
val = (val + 2);
myservo.write(val); // sets the servo position according to the scaled value
if (val > 175) {
val = -40;
}
//Path Finding Here
if (distance > 23) {
myStepper.step(stepsPerRevolution);
}
else if (distance < 23) {
myStepper.step(stepsPerRevolution);
}
else {
Serial.print('ERROR');
}
// JoyStick
int X = A1;
int Y = A2;
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print(" ");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print(" ");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("Distance: ");
Serial.println(distance);
//Serial.print("Motor:");
//Serial.print(val);
Serial.print(" ");
//Path Finding
//if (Forward = 'true') {
// myStepper.step(stepsPerRevolution);
//}
//else if (Forward = 'false') {
// myStepper.step(-stepsPerRevolution);
//}
delay(100);
}