# motor speed with potenciometer help

im using a easy driver to move and control a stepper motor with arduinomy project need to control the speed of the motro using a potenciometer, i have tried the code on the examples page
and all codes work fine but the speed control not, when i move the potenciometer, the motor start like moving strange and moving step by step, or moving backwards, its not moving on lower or high speed, also on pot max or min, i get the same speed, the one that its settled by the set.speed() on the code, but, the motor does not move up od down speed, never, any ideas what can i do to control the speed??,i know there its a example on playgound, but im using a driver to move it, so its only two pins control, STEP and DIR, even dir its not necesary since i can move thar analog, by setting a spdt switch for 5v and ground, so i only need one pin in fact, to control motor, the idea its also to display the counts on steps, and so settle the number of steps the motor will spin…

im really noob at programming so i need some help in here, tanks

``````// Example5 code for Brian Schmalz's Easy Driver Example page
// http://www.schmalzhaus.com/EasyDriver/EasyDriverExamples.html

#include <AccelStepper.h>

// Define the stepper and the pins it will use
AccelStepper stepper1(1, 9, 8);

// Define our three input button pins
#define  LEFT_PIN  4
#define  STOP_PIN  3
#define  RIGHT_PIN 2

// Define our analog pot input pin
#define  SPEED_PIN 0

// Define our maximum and minimum speed in steps per second (scale pot to these)
#define  MAX_SPEED 500
#define  MIN_SPEED 0.1

void setup() {
// The only AccelStepper value we have to set here is the max speeed, which is higher than we'll ever go
stepper1.setMaxSpeed(10000.0);

// Set up the three button inputs, with pullups
pinMode(LEFT_PIN, INPUT_PULLUP);
pinMode(STOP_PIN, INPUT_PULLUP);
pinMode(RIGHT_PIN, INPUT_PULLUP);
}

void loop() {
static float current_speed = 0.0;         // Holds current motor speed in steps/second
static int analog_read_counter = 1000;    // Counts down to 0 to fire analog read
static char sign = 0;                     // Holds -1, 1 or 0 to turn the motor on/off and control direction
static int analog_value = 0;              // Holds raw analog value.

// If a switch is pushed down (low), set the sign value appropriately
sign = 1;
}
else if (digitalRead(RIGHT_PIN) == 0) {
sign = -1;
}
else if (digitalRead(STOP_PIN) == 0) {
sign = 0;
}

// We only want to read the pot every so often (because it takes a long time we don't
// want to do it every time through the main loop).
}
else {
// Now read the pot (from 0 to 1023)
// Give the stepper a chance to step if it needs to
stepper1.runSpeed();
//  And scale the pot's value from min to max speeds
current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
// Update the stepper to run at this new speed
stepper1.setSpeed(current_speed);
}

// This will run the stepper at a constant speed
stepper1.runSpeed();
}
``````

Have you the Pot wired up correctly?

Put a couple of Serial.println() statements in to see that values are coming from the pot and what values are being calculated.

...r

Robin2:

Have you the Pot wired up correctly?

Put a couple of Serial.println() statements in to see that values are coming from the pot and what values are being calculated.

...r

yes its exactly as downloaded, i have not made any changes, the motor runs, but speed never change, instead of it, its like if the driver can not read the pot, and yes the por its wired ok, its just a variable voltage, but it doesnt work

Have you checked the voltage output of the potentiometer?

copachino:

Robin2:
Put a couple of Serial.println() statements in to see that values are coming from the pot and what values are being calculated.

yes the por its wired ok, its just a variable voltage, but it doesnt work

You don't seem to have bothered to see what results it is giving you?

...R

Hi
I think

#define SPEED_PIN A0

Tom......

TomGeorge:
Hi
I think

#define SPEED_PIN A0

Tom......

im going to try that, maybe its the main problem, also does anybody knows what i dont get emal notifications of replies???

copachino:

TomGeorge:
Hi
I think

#define SPEED_PIN A0

Tom......

yep, maybe its the main problem, also does anybody knows what i dont get email notifications of replies???
just saw the thread and i got some replies on other posts but no email notifications,

i used the same code on my project but it does control speed, i will seek it to see if i change that or not, im using different driver but i think that nots the problem

Add some code to show the values that analogRead() gives you - as suggested in Reply #1

…R

Robin2:

Add some code to show the values that analogRead() gives you - as suggested in Reply #1

…R

i think my analogs pins are dead, when i print them i get this:

and thats on the 5 ins, also, i only send to printl A0 but somehow i got print 14A0, any ideas?? bad arduino??

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper motor(1,9,7); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0
#define ANALOG_IN1 A1
#define ANALOG_IN2 A2
#define ANALOG_IN3 A3
#define ANALOG_IN4 A4
#define ANALOG_IN5 A5
void setup()
{
motor.setMaxSpeed(5000);
Serial.begin(57600);
}

void loop()
{
motor.moveTo(ANALOG_IN);
motor.setSpeed(100);
motor.runSpeedToPosition();
Serial.println("A1= ");
Serial.print(ANALOG_IN);
Serial.println("A2= ");
Serial.print(ANALOG_IN1);
Serial.print(ANALOG_IN2);
Serial.print(ANALOG_IN3);
Serial.print(ANALOG_IN4);
delay(100);
}

cflores:
i think my analogs pins are dead, when i print them i get this:

If you think that then write a short 5 or 6 line program that just reads the analog pins and displays the results with different voltages applied - eg. GND and 5V and halfway between.

...R

Robin2:

cflores:
i think my analogs pins are dead, when i print them i get this:

If you think that then write a short 5 or 6 line program that just reads the analog pins and displays the results with different voltages applied - eg. GND and 5V and halfway between.

...R

already did, and got many numbers even if i dont move the pot, i get ramdon numbers, also i tried the gauss meter with a hall efect sensor, and got the same extrange gauss reading even if there its not any magetic force near, its a problem only with the analog pins, so, my arduino its dead on analog inputs, its shame, cos i cant compleate my project

`````` int analog_in = analogRead(ANALOG_IN);
motor.moveTo(ANALOG_IN);
motor.setSpeed(100);
motor.runSpeedToPosition();
Serial.println("A1= ");
Serial.print(ANALOG_IN);
Serial.println("A2= ");
Serial.print(ANALOG_IN1);
Serial.print(ANALOG_IN2);
Serial.print(ANALOG_IN3);
Serial.print(ANALOG_IN4);
``````

Why bother printing a bunch of pin numbers that never change?
Why move a motor to a constant position, repeatedly?

In other words you probably meant:

``````  int analog_in = analogRead(ANALOG_IN);
motor.moveTo(analog_in);
motor.setSpeed(100);
motor.runSpeedToPosition();
Serial.println("A1= ");
Serial.print(analog_in);
Serial.println("A2= ");