Conveyor programming

Hi, I am new for arduino, I doing the conveyor project with programming code as per below:-

#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor1 = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myMotor2 = AFMS.getStepper(200, 2);

void setup() {

AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz

myMotor1->setSpeed(100); // rpm
myMotor2->setSpeed(100); // rpm

pinMode(2, INPUT); // CV present snesor
digitalWrite(2,HIGH);
pinMode(4,INPUT);//CV stop sensor
digitalWrite(4,HIGH);

}

void loop() {

if(digitalRead(2) == LOW && digitalRead(4) == HIGH){
digitalWrite(2,LOW);
myMotor1->step(200, FORWARD, DOUBLE);
if(digitalRead(4)==LOW){
digitalWrite(2,HIGH);

}

when i put the box on conveyor, the present sensor detect and conveyor is continuous running until stop sensor detect.

the problem is when i put the box, the present sensor detect but i take out the box from conveyor, the conveyor is always running.

the conveyor image as per attachment

any idea to program the conveyor to solve the problem.

thanks

It would help you get better answers to give things names instead of numbers. It'll help you too, down the road. Get rid of all the

digitalWrite(2,LOW)

kind of stuff and put in names. Is output 2 driving a motor? Call it motorOne or somesuch.

unsigned char motorOne = 2;

And put your code inside code tags so the forum doesn't convert it to smilies.

It wouldn't hurt either to look over the 'how to use this forum' sticky at the top.