stepper motor control driver uno R3

hi guys.
im new to arduino and have a uno R3 board,controlling a 200 step, 12vdc, 0.4a stepper motor with a L293n driver assisted with bd139 transistors.
My aim is to control the speed, step amount and a delay in-between the steps for a label application m/c. (labels coming off a roll)'all controlled by knobs (pots).Later i suppose i’ll have to add a sensor to read the label postition (optical sensor)but for now ill leave that alone.
i’v been playing around and trying, following jigs on the net. but i cant really find something to get me started, its still alot of greek to me. i’v managed to get this going-

[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 stepCount = 0;  // number of steps the motor has taken

void setup() {
}
  // nothing to do inside the setup


void loop() {
  // read the sensor value:
int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 10) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  // set motor delay 2 sec
   myStepper.step(stepsPerRevolution);
delay(2000);
  }
}

][/code]

pls help will be much appreciated
artios

You need to tell us what actually happens when you try the code.

Post a link to the datasheet for your stepper motor.

Give details of the power supply for the motor (volts and amps).

The L298 is a poor choice for driving stepper motors. Have a look at Stepper Motor Basics

...R

Artois, I would suggest to get the motor going first without using any libraries, so you get comfortable with what is actually going on "under the hood". Get basic direction and speed control to your satisfaction and only then incorporate other sensors. I would also suggest that you look at the AccelStepper library for more advanced control. I documented my own tinkering with steppers using an H-Bridge here as well.

The L298 is a poor choice for driving stepper motors.

But its adequate for driving a high impedance motor like the one in question. You won’t
get high speeds though, for that you require a low impedance stepper (< 5 ohms) and
a chopper-drive from high voltage (24V+)

Hi, thanks for all replies. Please find attachments included.
With the above sketch the motors speed i can adjust and it rotates for one revolution then stops for 2 sec and carries on repeating. ive played with other routines and the motor goes fine.
I drive the motor with a 12v 3amp power supply it draws ± 600ma depending on the state of the motor- rotating draws ±100ma less, in delay 100ma more, confuses me but thats it.
I know the L193n is a poor choice but with the 2 x BD139 help its working fine.
What my next step would be, is to be able to adjust the stepping amount with a pot, eg pulling the label roll 35mm wait 2 sec pull another 35mm, wait 2 sec etc,
after that being able to adjust the waiting period in between the pulls with a pot. Iknow to all u pros out there its a piece of cake, to me its a headache and i would just love this to work.
I know if u look at my sketch u think what the hell is he trying to do,u can laugh i don’t mind i would too.

The other thing i did notice in all my sketches- my mot is 1.8 deg=200 steps per rev -right or am i wrong? when i do a 1 revolution run stop run stop etc it goes past the 1 rev mark bit by bit every rev ? why is that?
thanks all for help

Stepper Mptor FL39ST34-0404A.pdf (106 KB)

Why do you have these two lines of code with an irrelevant comment between them

    myStepper.step(stepsPerRevolution / 100);
  // set motor delay 2 sec
   myStepper.step(stepsPerRevolution);

I am asking about the code, not the comment

I wonder if I understand this

What my next step would be, is to be able to adjust the stepping amount with a pot, eg pulling the label roll 35mm wait 2 sec pull another 35mm, wait 2 sec etc, after that being able to adjust the waiting period in between the pulls with a pot.

It sounds like you want one potentiometer to adjust the speed and another pot to adjust the interval between movements. I presume you will always move the appropriate number of steps to give 35mm of motion.

You should separate all these parts in your mind and in your code. You need a variable that determines the stepper speed and another variable that determines the interval between movements.

Create a function to read your two potentiometers and update those variables

Then put the motor motion in another function that uses the values in those variables. Use millis() rather than delay() to manage your timing so that things can appear to work in parallel.

Have a look at Planning and Implementing a Program - both for the organization of the code and for the use of millis()

…R