Arduino Code to rotate a stepper motor 360 degrees continually

Hello everyone,
I am working on a project in which I need to rotate a stepper motor 360 degrees continually and in one direction ( clockwise). I need the motor to make each 360 degrees in 5 seconds.
I am new to Arduino and only know the connections. I truly appreciate it of someone could help with code.
Also, will the code be different if I use a servo motor instead?
Thank you in advance !

Welcome to the forum

It sounds like you need to move the stepper one step, wait a bit, move the stepper, wait a bit and so on for ever

Have you looked at the Stepper examples in the IDE ? How is your stepper powered and how is it connected to the power supply ?

The code would, of course, be different if you used a servo but be aware that the position of a servo that can rotate continuously through 360 degrees cannot be controlled (unless it is s very special servo) and that you can only control its speed and direction.

Depending on the accuracy that you require that may be good enough but the speed can vary with the supply voltage

If you want to move a stepper motor with constant speed and direction, a microcontroller is not needed, you only need a multivibrator - for example with a timer 555. In this way you can use other types of motors such as ordinary DC and continuous 360 degree servo.

Thank you for your reply, UKHeliBob,
I am using an angle stepper motor connected to the Arduino through a Digital Stepper Driver (Model): DM542T. The stepper is powered through an a switching power supplies (NES-350-36 power supply).
The motor is currently controlled to rotate 180 degrees and then stop 30 seconds and then continue rotate for another 180 degrees (same direction) and so on. This control has been done by a previous student using Arduino and I want to make the motor rotate continually for 5 second per full revolution (360 degrees). I appreciate if anyone could help with controlling the motor as I need.
Thanks again

Thank you, but I want to use the current motor and system.
I am using an angle stepper motor connected to the Arduino through a Digital Stepper Driver (Model: DM542T). The stepper is powered through a switching power supplies (NES-350-36 power supply).
The motor is currently controlled to rotate 180 degrees and then stop 30 seconds and then continue rotate for another 180 degrees (same direction) and so on. This control has been done by a previous student using Arduino and I want to make the motor rotate continually for 5 second per full revolution (360 degrees). I appreciate if anyone could help with controlling the motor as I need.
Thanks again

Post code in code tags.

It should be trivial. Even with the code already for 180 you can just take out the delay and repeat that X2 for 360 although it would make more sense to actually understand how to code a step and how many steps make 360

Look up examples

Write a flow diagram of what you want to achieve then break it up into code.

Start by posting your current sketch here, using code tags when you do

I'll assume 200 steps per revolution. To rotate at 200 steps in 5 seconds (5000 milliseconds), step every 25 milliseconds.

unsigned long LatStepTime = 0;

void loop()
{
  if (millis() - LastStepTime >= 25)
  {
    LastStepTime += 25;
    digitlWrite(StepPin, HIGH);
    digitlWrite(StepPin, LOW);
  }
}

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