I’m using 4 ultrasonic sensors which display distance and I’m trying to make them move a stepper motor. I have already figured out how to code the sensors but how do I make the sensors give information to the motor on where to go.
Make a plan. Describe what you want. Read the docs (AccelStepper linrary) and the examples.
Just come general comments and advice -
Typically with a stepper motor you need to know the position so you may need one or more home or position sensors. Once you find the starting position, the software can count the steps and the software will know the position.
Work on your input (sensors) and output (motors) separately before adding the code that ties them together. It seems like you've got a good start on that.
Start with a known working example. I usually start with the Blink LED Example. Of course, you can take-out the blink code whenever you know that everything is working and you don't need it anymore.
"Develop" your code by adding one or two lines at a time, test-compiling and test-running as you go. That's not as easy as it sounds because you can't just start at the top and work-down... The compiler needs to see a "complete program". But if you try to write the whole program at once, you'll have errors/bugs (usually more than one) and the error messages usually aren't very useful, and often the compiler doesn't know what the real error is. Once, I had one misplaced curly bracket and the complier reported hundreds of errors!
Take advantage of the Serial Monitor to "print out" useful information (like the Analog Read Serial Example). I assume you are already doing that with the distance sensors. You can print-out variable values or little messages like "moving stepper motor". It's often the only way of knowing what your program is doing, especially when it's not working as expected. Again, you can take out (or "comment-out") the extra print statements once you no longer need them.
The two most important concepts are conditional execution (if-statements, etc.) and loops (doing something over-and-over, usually until some condition is reached). Once you understand those two concepts, you can start to write useful programs.
Thank you for the advice! I’ve been working on coding the sensors and have gotten all of them to work at once. I have also gotten the stepper motor to move with the code. Now my problem is how I send the information I get from the sensors to the stepper motor
I asked my teacher and he told me that I should covert the distance from the sensors to polar coordinates and then use tell the stepper motor on what to do. I have a general idea on how to do this but I have no idea how to combine the codes.