Working with steppermotor

Hello Guys here question from Holland .
i have made a working stacking rail with arduino uno .only i want to start and stop the loop for the staking stepper when im ready not with power on etc.
so i have made a trottle switch .
oke with a led i have a working code but with the steppermotor not the startbutton (startknop in dutch)
is working like a normal pulseswitch whats wrong in the code ?
i hope someone can help me with this because than i happy now working almost every day on it without finding the faulere

greatings Gert-Jan

here the total code :

#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int startknop=4;       //is startknop voor beginnen met stack
int pin=2;            //is relais voor camera
int resetknop=3;          //is resetknop voor return the stappenmotor tot begin positie
int knopRead;        // variabele voor lezen van de resetknop
int knopRead1;      // variable voor lezen van startknop
int dt=100;
int startknopNew;
int startknopOld=1;
int startknopState=0;

void setup() {
 // set the speed at 60 rpm:
 myStepper.setSpeed(60);
 // initialize the serial port:
 Serial.begin(9600);
 pinMode(startknop,INPUT);
 pinMode(resetknop,INPUT);
 pinMode(pin,OUTPUT);
 digitalWrite(pin,LOW);
 
}
void loop() {
 
  knopRead= digitalRead(resetknop); //waarden van de resetknop
  if (knopRead==1) {         // controleer of de knop is ingedrukt
  Serial.println("clockwise");
  delay(dt);
  myStepper.step(stepsPerRevolution*-4);
  delay(10000);
  } 
  startknopNew=digitalRead(startknop);
  if(startknopOld==0 && startknopNew==1){
  if (startknopState==1)
      // step one revolution in one direction:
 Serial.println("counterclockwise");
 myStepper.step(stepsPerRevolution*1.0);
 delay(5000);
 digitalWrite(pin,HIGH);
 delay(2000);
 digitalWrite(pin,LOW);
  }
else{
 startknopState==0; 
}
 startknopOld=startknopNew;
}

I'm not sure I understand the problem, are you saying that the start knob doesn't make the stepper turn more than one cycle?

If so, it looks like the problem is that you only turn the stepper if the knob is pressed and it wasn't before. The next time round loop, it is pressed and it was before, so nothing happens. If you want to rotate while it's pressed, forget about the previous state.

Also, you check startknopState to see if it's one, but you never set it so. Luckily, all that affects is a serial.print statement.

When I push the button it runs 1 time the stepper and relais but than it stops until I press again and than it runs it again one time.
I want when I push the start button it runs until I pusch again the start button.

Then use this section of code to set a boolean variable that tells you whether to rotate or not.

  startknopNew = digitalRead(startknop);
  if (startknopOld == 0 && startknopNew == 1)

Flip the value of the boolean when you detect a press. Use that boolean in another (not nested) if to control whether to rotate or not.

Wild bill I'm sorry but I have tried this it still not working.
It's still only make the stepper going on time.
After you buttonswicht ones

Post the code you used.

Open Navigation
Show Cart
Arduino Forum> Using Arduino> Programming Questions> Working with steppermotorAlerts Unread Posts Updated Topics
Topic: Working with steppermotor (Read 36 times)
gvwezel

Working with steppermotor
Today at 11:27 am
Hello Guys here question from Holland .
i have made a working stacking rail with arduino uno .only i want to start and stop the loop for the staking stepper when im ready not with power on etc.
so i have made a trottle switch .
oke with a led i have a working code but with the steppermotor not the startbutton (startknop in dutch)
is working like a normal pulseswitch whats wrong in the code ?
i hope someone can help me with this because than i happy now working almost every day on it without finding the faulere

greatings Gert-Jan

here the total code :

Code: [Select]

#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int startknop=4; //is startknop voor beginnen met stack
int pin=2; //is relais voor camera
int resetknop=3; //is resetknop voor return the stappenmotor tot begin positie
int knopRead; // variabele voor lezen van de resetknop
int knopRead1; // variable voor lezen van startknop
int dt=100;
int startknopNew;
int startknopOld=1;
int startknopState=0;

void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
pinMode(startknop,INPUT);
pinMode(resetknop,INPUT);
pinMode(pin,OUTPUT);
digitalWrite(pin,LOW);

}
void loop() {

knopRead= digitalRead(resetknop); //waarden van de resetknop
if (knopRead==1) { // controleer of de knop is ingedrukt
Serial.println("clockwise");
delay(dt);
myStepper.step(stepsPerRevolution*-4);
delay(10000);
}
startknopNew=digitalRead(startknop);
if(startknopOld==0 && startknopNew==1){
if (startknopState==1)
// step one revolution in one direction:
Serial.println("counterclockwise");
myStepper.step(stepsPerRevolution*1.0);
delay(5000);
digitalWrite(pin,HIGH);
delay(2000);
digitalWrite(pin,LOW);
}
else{
startknopState==0;
}
startknopOld=startknopNew;
}

Not sure what happened there; I was hoping to see your latest attempt.

This is the last one what must I change

Not sure what happened there; I was hoping to see your latest attempt.

gvwezel:
Wild bill I'm sorry but I have tried this it still not working.
It's still only make the stepper going on time.
After you buttonswicht ones

Was there new code associated with this?

the new code i have tryde but still the same ;

#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int startknop=4;       //is startknop voor beginnen met stack
int pin=2;            //is relais voor camera
int resetknop=3;          //is resetknop voor return the stappenmotor tot begin positie
int knopRead;        // variabele voor lezen van de resetknop
int knopRead1;      // variable voor lezen van startknop
int dt=100;
int startknopNew;
int startknopOld=1;
int startknopState=0;

void setup() {
 // set the speed at 60 rpm:
 myStepper.setSpeed(60);
 // initialize the serial port:
 Serial.begin(9600);
 pinMode(startknop,INPUT);
 pinMode(resetknop,INPUT);
 pinMode(pin,OUTPUT);
 digitalWrite(pin,LOW);
 
}
void loop() {
  startknopNew = digitalRead(startknop);
  if (startknopOld == 0 && startknopNew == 1)
  knopRead= digitalRead(resetknop); //waarden van de resetknop
  if (knopRead==1) {         // controleer of de knop is ingedrukt
  Serial.println("clockwise");
  delay(dt);
  myStepper.step(stepsPerRevolution*-4);
  delay(10000);
  } 
  startknopNew=digitalRead(startknop);
  if(startknopOld==0 && startknopNew==1){
  if (startknopState==1)
      // step one revolution in one direction:
 Serial.println("counterclockwise");
 myStepper.step(stepsPerRevolution*1.0);
 delay(5000);
 digitalWrite(pin,HIGH);
 delay(2000);
 digitalWrite(pin,LOW);
  }
else{
 startknopState==0; 
}
 startknopOld=startknopNew;
}

huidige_programme_met_resetknop_testversie_aan_uit.ino (1.58 KB)

Try this:

#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int startknop = 4;     //is startknop voor beginnen met stack
int pin = 2;          //is relais voor camera
int resetknop = 3;        //is resetknop voor return the stappenmotor tot begin positie
int knopRead;        // variabele voor lezen van de resetknop
int knopRead1;      // variable voor lezen van startknop
int dt = 100;
int startknopNew;
int startknopOld = 1;
int startknopState = 0;
bool TurnCCW = false;

void setup()
{
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
  pinMode(startknop, INPUT);
  pinMode(resetknop, INPUT);
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);
}

void loop()
{
  startknopNew = digitalRead(startknop);
  if (startknopOld == 0 && startknopNew == 1)
    knopRead = digitalRead(resetknop); //waarden van de resetknop
  if (knopRead == 1)         // controleer of de knop is ingedrukt
  {
    Serial.println("clockwise");
    delay(dt);
    myStepper.step(stepsPerRevolution * -4);
    delay(10000);
  }
  startknopNew = digitalRead(startknop);
  if (startknopOld == 0 && startknopNew == 1)
  {
    TurnCCW = !TurnCCW;
  }
  if (TurnCCW)
  {
    // step one revolution in one direction:
    Serial.println("counterclockwise");
    myStepper.step(stepsPerRevolution * 1.0);
    delay(5000);
    digitalWrite(pin, HIGH);
    delay(2000);
    digitalWrite(pin, LOW);
  }
  startknopOld = startknopNew;
}

Compiled, but not tested.

thats great Wildbill its working thanks a lot it go very good now