control the stepper motor

hi…
i have one problem…i try to control stepper motor to move at certain step…
but the problem is…i want it to move only when the interrupt/ sensor detect the signal.
when i try to program it, in the void loop() function…the motor keep rotate and never stop moving although there were no interrupt occur in sensor…
any idea hw to make this think happen. :frowning:

i have one problem..i try to control stepper motor to move at certain step.. but the problem is..i want it to move only when the interrupt/ sensor detect the signal. when i try to program it, in the void loop() function..the motor keep rotate and never stop moving although there were no interrupt occur in sensor..

You have more then one.

Your shift key appears to be broken. Your . key seems to stutter. You forgot to mention what sensor is generating the interrupt. You forgot to mention why the sensor needs to generate an input. What else is the Arduino busy doing that polling is not good enough? How do you know that the sensor, whatever it is, is not generating any inputs. You forgot to post any code.

any idea hw to make this think happen.

Yes.

i use 4 led as reversed bias as sensor
whenever the max val on any sensor, then it will send the step to motor to rotate…
this my trial on the code, i just place one sensor on analog 0

#include <Stepper.h>
#define STEP 200 //motor step how many?

Stepper motorstep(STEP,8,10,9,11); //define the pin on arduino

int previous=0;

void setup(){
motorstep.setSpeed(5);
Serial.begin(9600);
}
void motor(int v){ //function to turn motor
  switch(v){
   case 1:
   motorstep.step(200);//full rotate
  delay(200);
    break;
   case 2:
motorstep.step(-100);// half reverse
delay(200);
break;
case 3:
motorstep.step(); // motor stop
delay(200);
break;
 }
}

void loop()
{

int v= analogRead(0); //read from led
if (v <= 200){
 int a = 1;
  motor(a);
delay(1000);
}
else if (v>200,v=201,v<= 800){
 int a = 2;
 motor(a);
 delay(1000);}

else if(v>=801){
 int a=3;
 motorstep.step(p);
    previous =v;
delay(1000);
}
}
int v= analogRead(0); //read from led

Read from a light bulb, huh? Want to know if it’s on?

else if (v>200,v=201,v<= 800){

Please explain what you think/hope this statement is doing. It almost certainly isn’t doing that. How to fix it depends on what you think it is doing.

You have a Serial.begin() statement, to establish serial communications. Add some Serial.print() or Serial.println() statements to print out variables and other messages to show what is going on.

although there were no interrupt occur in sensor

You are not using interrupts, so this doesn’t make sense.

ok let me explain again..first, sensor is consist 4 led act as ldr(pin 0,1,2,3... then arduino read it between 4 led which one is the most light on them(read high value from led). each led stored certain step to rotate the motor eg led 3 is most light, the arduino send step=50 to stepper motor. then it will cont read the led..if the most light is now sense on led 4, the it send step=100 to motor..

im try to make an interupt if there position on led is changing, then it will sure the motor to rotate, if not motor will stay no move.

ok let me explain again..first, sensor is consist 4 led act as ldr(pin 0,1,2,3...

I don't think LEDs can act as LDRs. But, there is a possibility that I am wrong. Are you able to read changing values from the 4 LEDs?

You need to store the previous values read from the sensors, so you know whether the new values read from the sensors are different from the previous values. Only when a different sensor reports a maximum value should you call the motor function.

yes it can…this http://arduino.cc/playground/Learning/LEDSensor
let say, led 1 = 200, led2= 100, led3=1024, led3=0
then motor should turn step stored in led3

i dont what control function should i use…
when i use <stepper.h>

Stepper motor(STEP,8,10,11,12);
to turn the motor, just send step like this right? motor.step(200);
then when i send the other value to rotate 25 step, motor.step(25); it will rotate to position 225 not 25. why?

how to stored value?

yes it can…this http://arduino.cc/playground/Learning/LEDSensor

Have you verified that this works?