Programming continuous rotation on Stepper Motor with microswitches

Hi all! I am new at programming and trying to learn to program a stepper motor for my thesis project and thought I would post to get some help! My project consists of programming a stepper motor to slide a camera on a camera slider. The camera will be stopped at certain distances to collect data from petri dishes along a shelf. I am currently using a small stepper motor from a kit, however eventually I will be using a 42SHDC3025-24B 3.96V/ 14W step motor. I'm assuming I will need an extra power source for the big stepper motor but I am currently just practicing with the stepper motor in the kit. (i will figure out the code for this small step motor and then use it for the bigger step motor once it works)

For my project I am planning on using micro switches to put on the camera slider track in order to stop the camera. Once the camera stops it will wait for input from the raspberry pi camera (after it collects data) to continue down the path until it hits another micro switch which will prompt it to stop again. Once the camera reaches the end of the camera slider, it will have to return back to the beginning of the slider (where it started) and wait until data will need to be collected again (approx every 15 min). I am not entirely sure how to program the continuous movement of the stepper motor and make it stop once it reaches each switch. I have currently only gotten the stepper motor to do one rotation so far. If anyone could help me alter this code to fit my project I would be very thankful! I appreciate any input and thank you in advance to those who read this!

I have attached a picture of the layout and code.
I was unable to post the code as an attachment because I am a new user on this website, but I was only able to attach one screenshot total for some reason. sorry if that makes it difficult!!

If the photo is unclear, the pins are 8-11 and the black wire is connected to the GND on the arduino.
Components: arduino Uno R3, ULN2003 Driver Board

It were much easier to use a DC motor whose power can be cut off at every stop position.

If using a stepper, you only need one limit switch per axis to home the motor (establish a "zero" position). Then move to intermediate positions by issuing commands to move a certain number of steps. If using the AccelStepper library use the moveTo function.

Camera sliders are popular projects. They are seen here often. A search of this site should turn up lots of information.

Hi Mohanty,

there are some customs how posting in this forum is done usually:
For schematics don't use fritzing! Hand-drawn schematics with just the relevant information is much better.

postings are only re-edited for typos but no substantial changes of the text or code

modified code is always posted in a new posting. The thread can become as long as 500 posts.

try to read the code you have posted as a screenshot - - -
very hard to read

usually code is posted as a code-section:

You can post code by using this method that adds the code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

I will not download your picture and try to read the code.
I will wait to read the code until you have posted it as a code-section.

as a new user your postings are limited to 10 postings in the first 24 hours
After going to trust level 1 you are allowed to post more

Get to trust level 1 by…

  • Entering at least 5 topics = reading 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading different posts

Without knowing which stepper-motor-library you are using or not using
a specifc advice can't be given.

I recommend the MobaTools stepper-library for controlling stepper-motors.

steppermotors usually are used in a way that the stepper-motor never looses steps.

This means the microcontroller will always know where to stop because you can determine how many steps the stepper-motor has to do.

though a reference-point is needed for referencing a certain point to make the code know "now I'm at reference-point. And after that driving to any point can be calulcated as a number of steps.

best regards Stefan

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