Pages: 1 [2]   Go Down
Author Topic: Control bipolar stepper motor with potentiometer?  (Read 3939 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12541
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
 }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12541
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: