Go Down

Topic: 6 Wire Stepper and ULN2803A (Read 4654 times) previous topic - next topic

Grumpy_Mike

Well you have mapped the reading to 0 - 100, so if it is over 50 then set the direction the other way.
Use the if statement for this.

For the speed:-
When it is around 50 you want it slow so for the speed subtract the reading from 50 and take the absolute value abs() function to always get a positive value.

graphections

Wicked thanks :)

I got it working - sort of with this

Code: [Select]
#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() {
  // initialize the serial port:
  Serial.begin(9600);
}

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 > 50) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution/50);
    Serial.print("Forward steps:" );
    Serial.println(stepCount);
    stepCount++;
  } else {
       if (motorSpeed < 50){
        myStepper.setSpeed(motorSpeed);
        // step 1/100 of a revolution:
        myStepper.step(-stepsPerRevolution/50);
        Serial.print(" Reverse steps:" );
        Serial.println(stepCount);
        stepCount++;
          }
  }
}


It seems though that the speed varience is off
For example if the POT is at between 49 and 51 the speed should be the same, just in different directions - right?
And when at 23 and 1000 - same speed just differernt directions

What is in fact happening is the the direction is changing now, but the speed variates from 0-100 not from 0 to 50 and 50 to 0.

Thoughts? Does this make sense?

Grumpy_Mike

Well you didn't do all I said did you. Here is your code corrected:-
Code: [Select]
#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() {
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int knobReading = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
   
  if (knobReading > 50) {
    myStepper.setSpeed((knobReading-50) * 2);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution/50);
    Serial.print("Forward steps:" );
    Serial.println(stepCount);
    stepCount++;
  } else {
       if (knobReading < 50){
        myStepper.setSpeed((50 - knobReading) * 2);
        // step 1/100 of a revolution:
        myStepper.step(-stepsPerRevolution/50);
        Serial.print(" Reverse steps:" );
        Serial.println(stepCount);
        stepCount++;
          }
  }
}

graphections

#18
Jan 25, 2012, 06:16 pm Last Edit: Jan 25, 2012, 06:26 pm by graphections Reason: 1
Thanks so very much for this help :)

It is working quite well.

2 Things though

1: Proir to adding the direction change, the stepper stepped very smoothly, now it seems to vibrate a lot more, almost like it is labouring to step.

2: When I max the knob out to either 0 or 100 the stepper stutters and does not rotate, it just steps in place (you can feel it stepping with no rotation).

I should probably add the I have added a 16x2 LCD and change the stepper pins from;
8, 9 , 10, 11
to
3, 4, 5, 6

I just loaded the previous Sketch to eliminate the LCD as a factor using the new pins, with the same choppy step results as mentioned above


Any thoughts on this?

graphections

Ok i seem to be the Knob here - In reguards to the post above, this issue was that the Batteries running the stepper were running low.

:) But at least we know now!

graphections

Now the next issue is that the ULN2803a just got extremely HOT, I added a new battery pack with 8aas (previously it was 4).

Would a heat synch solve this or do you think I am running too much current through it now?

I need a battery source that will last for at least 5 hours running the stepper - with as much torque as possible.

Thoughts anyone?

ajofscott

The ULN2803A has a current limit of 500mA per output device.

graphections

@ ajofscott

I have it all working now, what battery source would you suggest to retain as much torque as possible?

Currently (no pun) with 4 1.5v aa's I am getting a total of 6volts, and the stepper seems to stutter at its max speed. ULNs temp is fine

I tried running it with 8 1.2v aa's and motor control is much better (no stuttering of stepper) but ULN gets very hot - The batteries are 2200 mah recharables.

SO i suppose my questions is, can I increase the voltage as long as I keep the mah to 500 or so? Keeping in mind I need torque and long run times.

thoughts?

Grumpy_Mike

Quote
The ULN2803A has a current limit of 500mA per output device.

But only about 650mA can be switched on in any chip at any time:-
http://www.thebox.myzen.co.uk/Tutorial/Power_Examples.html

Nowhere have you said what CURRENT the motor coils are pulling. Either measure the current or measure the coil resistance. It is the only way to know what you are doing.

graphections

Hey Mike, how would I measure the coils current resistance?

Grumpy_Mike

Put a current meter in series with the motor coil.
Meters are only $10 or so, so you should have one.

graphections

#26
Feb 23, 2012, 04:54 pm Last Edit: Feb 23, 2012, 05:49 pm by graphections Reason: 1
Ah ok, or would looking up the specs on the Motors Coil Resistance work too?

So the current meter should tell me what the levels are on the stepper, and then I match a power source to those level to get the optimal performance from the motor?

Edit:

Ok i found the spec sheet for my Stepper here
http://www.slidesandballscrews.com/pdf/steppermotors/SY42STH47-1206A.pdf

The Current rating is (A) 1.2 so does this mean anything over 1.2 amps will damage the motor and over heat the ULN?
And the Voltage rating is (V) 4 - So using 4 rechargable 1.2 volt aas is an overload?

How do I figure out what the combined Amperage is with the 4 AA's?

Would Sparkfuns Easy Driver be easier to work with in this project?

Grumpy_Mike

You need a regulating stepper driver to limit the current to a fixed ammount while allowing you to feed it with a higher voltage than 4V.

graphections

Makes sense, I was tryint to keep it simple.

I have used the Pololu driver chio and I fried it, ill go with the SparkFun easy driver this time ;)

Grumpy_Mike

Quote
I have used the Pololu driver chio and I fried it,

Only because you set it to deliver too much current.

Go Up