Go Down

Topic: Control bipolar stepper motor with potentiometer? (Read 4 times) previous topic - next topic

scullies

Are you suggesting that it's the speed that motor is set to or the speed that I turn the pot.
I have slowed the motor speed right down and still get the same problem when I turn the pot quickly.

I have also noticed that the stepper motor doesn't respond to well to the pot movement when the pot starts to move from the "0" position. Feels like its responds between "200 - 1023"
Could it be that it's loosing signal in the "0 - 199" range?


PeterH


Are you suggesting that it's the speed that motor is set to or the speed that I turn the pot.
I have slowed the motor speed right down and still get the same problem when I turn the pot quickly.


I was suggesting that you were asking the motor to accelerate faster than it was capable of.

I think you need to post your code. It's quite possible that you have a design fault in your sketch which is causing this behaviour.
I only provide help via the forum - please do not contact me for private consultancy.

scullies

ok, I'm with you now.

here is the sketch, its the same sketch from the "motorknob" just changed the speed and steps. I appreciate your help.

#include <Stepper.h>

#define STEPS 200
#define COIL1 8
#define COIL2 9
#define COIL3 10
#define COIL4 11

#define PotIn  0

// create an instance of the stepper class:
Stepper stepper(STEPS, COIL1, COIL2, COIL3, COIL4);

int pos = 0; //initial position of stepper

void setup()
{
  stepper.setSpeed(100); // speed of motor 4 rpm

}

void loop()
{
  // get sensor value and adjust range
  int val = analogRead(PotIn);   //get the potentiometer value (range 0-1023)
  val= map(val,0,1023,0,50);    // map pot range in the stepper range.
 
 
  if((val - pos)!= 0){
    if((val - pos)> 2){
      stepper.step(1);
      pos++;
    }
    if((val - pos)< -2){
      stepper.step(-1);
      pos--;
    }
  }
else{
  digitalWrite(COIL1,LOW);
  digitalWrite(COIL2,LOW);
  digitalWrite(COIL3,LOW);
  digitalWrite(COIL4,LOW);
}
}

scullies

I have set the step speed to 4 now, but still dont get any response from the pot untill it reaches about quarter turn  :smiley-roll:

phreeky

I have also noticed that the stepper motor doesn't respond to well to the pot movement when the pot starts to move from the "0" position. Feels like its responds between "200 - 1023"
Could it be that it's loosing signal in the "0 - 199" range?


Do a Serial.println of the analog input (your 'val' variable), open the serial monitor, and find out.

Grumpy_Mike

I don't think the speed call has any effect when you are only stepping the motor by one step at a time. Try stepping it two and see if that makes the difference.
But if the motor is skipping then you are asking it to go faster than it can.

PeterH


Code: [Select]
  digitalWrite(COIL1,LOW);
  digitalWrite(COIL2,LOW);
  digitalWrite(COIL3,LOW);
  digitalWrite(COIL4,LOW);


Are you powering down your stepper as soon as you think it is in the right place? Why are you doing that?
I only provide help via the forum - please do not contact me for private consultancy.

scullies

Thanks for the replies guys,
I have been messing around with the speed and stepping, I also swapped the +5v and ground around to use the other end of the pot range. All that has helped a lot,

I was shutting it down as it was getting so hot, I couldnt touch it. Its rated up to 36v and 3 amp so I used a 12v 2 amp supply which was making things to hot.
I have changed to a 5v 450mA now and its cool as ice. I was using laptop chargers that I have lying around the house.

Still interested if a rotary switch will work to control the stepper. My understanding is that the Arduino takes the different voltage readings from the pot and this determins the stepper motor opertaion. Would a rotary switch also put out different voltages as the switch is turned?

Grumpy_Mike

Quote
I also swapped the +5v and ground around to use the other end of the pot range.

That sounds like you have a log pot not a linear one.

Quote
Would a rotary switch also put out different voltages as the switch is turned?

No.

Go Up