My sensor was working 5 mins ago then it stoped working

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);
}

Can you read this and provide the information we need to help you?

Namely: the parts you are using (with links ) and
how they are connected?

@arduino_king2134 - You seem to have forgotten an external power supply for the servo and the stepper driver board.

@arduino_king2134 this word conveys an important message: as you have not provided enough information, we can only imagine and speculate what the problem is.

I suggest to undo whatever you did that caused the sensor to stop working.

Sometimes it's not the code, but the hardware. The voltage regulator on Arduino boards has thermal shutdown if you exceed the max current(1.6A) on the 5V line, so basically it reboots. You need to provide the schematic for full picture, or power the motor using external power supply.

Rather then guess and burn a lot of time post your annotated schematic showing all power sources, connections, grounds, etc. Also post links to the technical information on the hardware items as we cannot see what you have. Without that information I cannot help as I do not want to play guess-guess.

Remember that rewiring a circuit that is powered up is the best way of damaging components and processors. If you have been doing this then stop doing this immediately.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.