We are planning to drive conveyor belts with Arduino Unos using stepper motors. We are planning to use easy drivers, so that we control at least 3 motors with one Uno. Currently we are still at an initial stage, we are designing and planning the setup of conveyor belts. But what I wanted to ask was, regarding the coding.

How would I code so that say the belt moves forward for x seconds, and then after time it moves backwards for y seconds. Any basic idea on the code would be great thank you. I could do the basic code, but I just need help with timers part.

  • Steppers may not really be the best motor technology for that, but they are conceptually simple. Time based control is extremely simple, but often poorly suited to the real world. However, if you wanted to do it, and are using stepper motors, a possible way would be to figure out your steps per unit time, and issue that many steps. In reality, stepper systems with mass will need acceleration and deceleration, so you'd have to work that in too - maybe instead of time, you could work in terms of a desired total number of steps. Don't forget operator safety! Jan 19, 2015 at 5:37
  • Have you checked this out 1 link & 2 link
    – Sarenya
    Jan 19, 2015 at 7:32
  • The clocks of the Unos have only ~ 0.5% accuracy. This may be an issue if you need several of them working in unison. Mar 20, 2015 at 21:28

1 Answer 1


In regards to time control use the mills() function. You start by creating an:

unsigned long lastTime = millis();

Then later in the program create another variable:

unsigned long currentTime = millis();

Next Compare the two:

unsigned long elapsedTime = currentTime - lastTime;

For the most part I normally just shorten the last two lines into one:

unsigned long elapsedTime = millis() - lastTime;

Stepper motors are not needed if you are just doing timed control, but the advantage of stepper motors are you can move them with pin point accuracy based on the number of steps per rotation. If there are 60 steps per rotation then 360 degrees per rotation/ 60 steps per rotation and you get that each step is 6 degrees. So in order to turn the motor 6 degrees you would turn it 6 steps. This also allows you to keep track of angular velocity.

When I control motors I normally create an array of the different parts of the cycle then loop through the array.

  • yeah we are going for stepper motors because in some cases we need the conveyor to oscillate back and forth, so we would need to play with time ofcourse and also accuracy of steps also, that it needs to oscillate x steps forward for y seconds then reverse x' steps backwords for y' seconds. So I think stepper motors would be a good choice here. We will not be using an external sensor to detech the change motor speed or steps. It will all be done in coding only. Also with stepper motors we can utilize full 360 degree angle, which would be required, unlike servo motors which only go upto 180.
    – riju
    Jan 20, 2015 at 7:43
  • Did my answer answer your question? If so please mark it as the answer. If not, how can I improve it to help you best?
    – Joel
    Jan 21, 2015 at 4:39
  • @Joel..yes I was replying to you. we are still in process of developing the basic automation idea. The electronics part of driving motors etc comes later on. So I will surely refer to you..once we start electronics part. I hope you read my comment, you reckon stepper motors would be a good choice??? Thanks
    – riju
    Jan 22, 2015 at 7:25
  • Steppers motors will work well with a conveyor. In order to get accurate position data you will need to convert steps to distance moved which is centered around your gearing. Make sure to check there torque specs, depending on the conveyor size you will need larger stepper motors which require larger hardware to control them.
    – Joel
    Jan 23, 2015 at 4:43
  • @joel...yeah ok, let us see how it goes, I will contact you once the prototype is ready. I reckon I posted a bit early, but anyways stepper motors then it shall be...mind you for prototyping we will be using arduinos unos just to check the feasibility and the results..for the original setup we will probably use PLC..
    – riju
    Jan 23, 2015 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.