Arduino uno and arduino motor shield with stepper motor

Hi everyone, I'm new to this so please forgive me if my question sounds stupid :blush: I have a UNO and new motor shield to run a stepper motor. I loaded a sketch that runs the motor X times (steps) in one direction, then reverses. I can change the steps etc by altering the program no. of steps. e.g 48 steps =1rev, 92 = 2revs etc.
My question is :- can i connect a potentiometer to one of the analogue inputs that will change the no. of steps, and a further pot to control the speed?
Any help and advice will be greatly appreciated, so thanks in advance :slight_smile:

can i connect a potentiometer to one of the analogue inputs that will change the no. of steps, and a further pot to control the speed?

Yes, permission is granted to do that. Was that all you needed?

Thank you for the response :slight_smile: can i be very cheeky and ask how to do it, i'm fast learning how to use the sketches, but its how the physical connections are made, and how i tell the program which terminal i connect too that is still taking time for me to understand. I guilty of trying to run before I can walk I guess :~

Look at the AnalogInput example to see how to connect and read a potentiometer.

It's simple if you use top down design,

  1. Read the pot (or any other thing that gives you input)

  2. Control the stepper motor (or that ever other thing .......)

  3. Provide some code to change the input to output

Job done, simples ......

Mark

PS - I'm not having fun with you this is the way its done by the pro's!

M

Thanks for the responses, Iā€™m beginning to get to grips with it now. This is a control sketch I downloaded that by changing the parameters controls the motor, where in the steps should I put the part that reads the analogue input value to change the number of steps and speed? :~

// Include the Stepper Library
#include <Stepper.h>

// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

// The amount of steps for a full revolution of your motor.
// 360 / stepAngle
const int STEPS = 1480;

// Initialize the Stepper class
Stepper myStepper(STEPS, dirA, dirB);

void setup() {
// Set the RPM of the motor
myStepper.setSpeed(1);

// Turn on pulse width modulation
pinMode(pwmA, OUTPUT);
digitalWrite(pwmA, HIGH);
pinMode(pwmB, OUTPUT);
digitalWrite(pwmB, HIGH);

// Turn off the brakes
pinMode(brakeA, OUTPUT);
digitalWrite(brakeA, LOW);
pinMode(brakeB, OUTPUT);
digitalWrite(brakeB, LOW);

// Log some shit
Serial.begin(9600);
}

void loop() {
// Move the motor X amount of steps
myStepper.step(STEPS);
Serial.println(STEPS);
// Pause
delay(2000);

// Move the motor X amount of steps the other way
myStepper.step(-STEPS);
Serial.println(-STEPS);
// Pause
delay(2000);
}

I have been playing around with the steps and rev values and if I increase the steps, I have to decrease the R.P.M.

P.S. I found the I.C on the motor shield seems to get rather hot at 2 amps so I glued a heatsink to it and runs way cooler now even at 2.5 amps :slight_smile:

where in the steps should I put the part that reads the analogue input value to change the number of steps and speed?

In loop(). That code is very simple. It should be very obvious what you need to change to change the number of steps and the speed.