RPM input controlling Stepper motor

Hi there,

I am trying to write the code for my project.

Based on the rotational speed of a external shaft i need a stepper motor to either turn CW or CCW.

Every 15 seconds the rpm of a shaft is read.

Above 100rpm, the stepper turns CW by 15 degrees then stops.
If the rpm of the shaft remains, or greater than 100rpm, the stepper turns CW again by 15 degrees and stops.

If the rpm of the shaft fall below 100rpm, the stepper turns CCW by 15 degrees then stops.
If the rpm of the shaft remains below 100rpm the stepper turns CCW again than stops.

In both directions (CW and CCW) there is a limit switch that only allows the stepper to rotate 90 degrees in total.

I have found the code for counting the rmp of the shaft using a Photo interrupter and i have found the code for controlling stepper motors.

Combining these 2 codes or adding the 'last rpm read' or 'delay periods' is beyond me.

If there is a tutorial on this id be happy to study it.

If someone could write this code or point me in the right direction it would be much appreciated.

Thanks,

Mike.

Well, first of all if your stepper is the common 200 steps per rev type, it cannot turn 15 degrees it can turn 14.4 degrees (8 steps) or 16.2 degrees (9 steps), do you want to continue?

If you want someone to write code for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

If you want to learn to do this yourself then please post the programs you already have working.

And please post your program using the code button </> so it looks like this. See How to use the Forum

...R

Yes, 15 degrees +/- is ok. I was just speaking in general terms and yes i would like to try to learn how to write this code.

This is what i have so far.

My Stepper motor program/code outline.

NOTES -

  1. Is a Dual H Bridge necessary or will Arduino + and – commands do the job for turning the Stepper motor CW / CCW?
  2. Steps per 1 rotation =
    360 / 1.8 = 200
    Milliseconds per step @ 20rpm =

Code requirements –

// Read the RPM of a rotor shaft with a Photo interrupter. (Code copied for youtube tutorial)

volatile int counter = 0;
void setup ()
{
Serial.begin(9600); // Not necessary
attachInterrupt (0, count, Rising);
}
void loop ()
{
delay (990);
serial.print (counter*30); // count x 60 seconds
serial.println (“rpm.”);
counter = 0;
}
void count ()
{
counter++;
}

// Give a value for RPM

// Create RPM as an analog signal

// RPM analog signal as an input

void loop

// Read RPM

// If RPM is greater than 80 RPM, turn the stepper motor 15 degrees CW

// Delay for 15 seconds
{
delay (15000);
}

// Read RPM

// If RPM is less than 80 RPM, turn the stepper motor 15 degrees CCW

// Delay for 15 seconds
{
delay (15000);
}

Thanks for replies.

Is a Dual H Bridge necessary or will Arduino + and - commands do the job for turning the Stepper motor CW / CCW?

Don't know any thing about your motor:
Voltage, current (Amps), bipolar, unipolar, how many wires?
Can you post a link?
HowToPost

micky333:
My Stepper motor program/code outline.

Please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

I did mention this in Reply #2. Help us to help you.

...R

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile: