# Driving conveyor belts using Arduino Unos

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
– 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

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