activating stepper motor with IR fork light sensor
hi,
for school project making chewing gum dispenser. dispenser using arduino uno r3, 28byj-48 stepper motor , ir fork light barrier.
the goal of setup coin rolls through fork light barrier in turn triggers te stepper motor complete number of steps.
the problem i'm bumping code have allows stepper motor rotate when stays in between fork light barrier instead of passing through it.
i wondering if willing me adjust code solve problem.
thank you,
mitch
for school project making chewing gum dispenser. dispenser using arduino uno r3, 28byj-48 stepper motor , ir fork light barrier.
the goal of setup coin rolls through fork light barrier in turn triggers te stepper motor complete number of steps.
the problem i'm bumping code have allows stepper motor rotate when stays in between fork light barrier instead of passing through it.
i wondering if willing me adjust code solve problem.
thank you,
mitch
code: [select]
/*
byj48 stepper motor code
connect :
in1 >> d8
in2 >> d9
in3 >> d10
in4 >> d11
vcc ... 5v prefer use external 5v source
gnd
written :mohannad rawashdeh
https://www.instructables.com/member/mohannad+rawashdeh/
28/9/2013
*/
#define in1 8
#define in2 9
#define in3 10
#define in4 11
int steps = 0;
boolean direction = true;// gre
unsigned long last_time;
unsigned long currentmillis ;
int steps_left=17786;
long time;
int isobstaclepin = 7;
int isobstacle = low;
void setup()
{
serial.begin(115200);
pinmode(isobstaclepin, input);
pinmode(in1, output);
pinmode(in2, output);
pinmode(in3, output);
pinmode(in4, output);
// delay(1000);
}
void loop()
{
while(steps_left>0){
currentmillis = micros();
if(currentmillis-last_time>=1000){
stepper(1);
time=time+micros()-last_time;
last_time=micros();
steps_left--;
}
}
serial.println(time);
serial.println("wait...!");
delay(2000);
direction=!direction;
steps_left=0;
}
void stepper(int xw){
(int x=0;x<xw;x++){
switch(steps){
case 0:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, high);
break;
case 1:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, high);
digitalwrite(in4, high);
break;
case 2:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, high);
digitalwrite(in4, low);
break;
case 3:
digitalwrite(in1, low);
digitalwrite(in2, high);
digitalwrite(in3, high);
digitalwrite(in4, low);
break;
case 4:
digitalwrite(in1, low);
digitalwrite(in2, high);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
case 5:
digitalwrite(in1, high);
digitalwrite(in2, high);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
case 6:
digitalwrite(in1, high);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
case 7:
digitalwrite(in1, high);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, high);
break;
default:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
}
setdirection();
}
}
void setdirection(){
isobstacle = digitalread(isobstaclepin);
if (isobstacle == high) {
if(direction==1){ steps++;}
if(direction==0){ steps--; }
if(steps>7){steps=0;}
if(steps<0){steps=7; }
}
}
quote
the problem i'm bumping code have allows stepper motor rotate when stays in between fork light barrier instead of passing through it.you need detect when light becomes interrupted rather when is interrupted.
look @ statechangedetection example in ide
Arduino Forum > Using Arduino > Programming Questions > activating stepper motor with IR fork light sensor
arduino
Comments
Post a Comment