Go Down

### Topic: How do I make the stepper motor perform a complete revolution? (Read 110 times)previous topic - next topic

#### jpaulo69

##### Mar 21, 2019, 03:08 amLast Edit: Mar 21, 2019, 07:15 pm by jpaulo69
This code works continuously with intervals, I want it to one full turn and stop.
Obs(the relays no control the motor )
Code: [Select]
`#include <AccelStepper.h>// Define a stepper and the pins it will useAccelStepper stepper(AccelStepper::DRIVER, 5, 2);int pos = 50;int teste;//Porta ligada ao pino IN1 do moduloint porta_rele1 = 7;void setup(){   Serial.begin(9600);  stepper.setEnablePin(8);  stepper.setMaxSpeed(4000.0);//0  stepper.setAcceleration(4000.0);//0  stepper.setCurrentPosition(0); //zero  pinMode(porta_rele1, OUTPUT);}void loop(){while (Serial.available()>0)  teste = Serial.read () ; '-0';  if (teste == 116)    {              digitalWrite(porta_rele1, HIGH);  //Liga rele 1       Serial.println(teste);    digitalWrite(porta_rele1, LOW); //Desliga rele 1if ((stepper.distanceToGo() != 0)) {    stepper.run();}    if (stepper.distanceToGo() == 0)      {        delay(500);        pos = -pos;        stepper.moveTo(pos);      }    stepper.run();   }  } `

#### MorganS

#1
##### Mar 21, 2019, 09:33 am
How many steps per revolution? Do you think it would be a good idea to move that many steps instead of just 50 steps?
"The problem is in the code you didn't post."

#### Robin2

#2
##### Mar 21, 2019, 09:37 am
The usual way to make a stepper motor move one revolution is to tell it to move 200 steps (or however many there are in a revolution).

...R
Stepper Motor Basics
Simple Stepper Code
Two or three hours spent thinking and reading documentation solves most programming problems.

#### MarkT

#3
##### Mar 21, 2019, 03:56 pm
You need something more like:
Code: [Select]
`setup(){  stepper.setEnablePin(8);  stepper.setMaxSpeed(4000.0);//0  stepper.setAcceleration(4000.0);//0}loop(){  stepper.run();  // must call this all the time, so every time through loop.  Don't use delay()  if (Serial.available()>0)   // use if, not while...  {    char teste = Serial.read () ;    if (teste == 116)      stepper.move (200) ;  // initiate relative move - AccelStepper library does the rest.  }}`
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up