color sensor

i am student in agricultural engineering. i am trying to make a sensor based sprayer. which run on green color detecting sensor
i have installed a program in arduino uno board, but now sensor sense the green color and activate the relay control, but after removing green color it does not stop relay control…
can any one help to resolve the problem??
here is the program

int s0=3,s1=4,s2=5,s3=6;
int flag=0;
int counter=0;
int motor_relay = 7;
int countR=0,countG=0,countB=0;
void setup()
{
Serial.begin(115200);
pinMode(s0,OUTPUT);
pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
pinMode(motor_relay,OUTPUT);
digitalWrite(motor_relay,LOW);
}
void TCS()
{
digitalWrite(s1,HIGH);
digitalWrite(s0,LOW);
flag=0;
attachInterrupt(0, ISR_INTO, CHANGE);
timer2_init();
}
void ISR_INTO()
{
counter++;
}
void timer2_init(void)
{
TCCR2A=0x00;
TCCR2B=0x07; //the clock frequency source 1024 points
TCNT2= 100; //10 ms overflow again
TIMSK2 = 0x01; //allow interrupt
}
int i=0;
ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function
{
TCNT2=10;
flag++;
if(flag==1)
{
counter=0;
}
else if(flag==2)
{
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
countR=counter/1.105;
Serial.print(“red=”);
Serial.println(countR,DEC);
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
}
else if(flag==3)
{
countG=counter/0.700;
Serial.print(“green=”);
Serial.println(countG,DEC);
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);

}
else if(flag==4)
{
countB=counter/1.17;
Serial.print(“blue=”);
Serial.println(countB,DEC);
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
}
else
{
flag=0;
TIMSK2 = 0x00;
}
counter=0;
delay(2);
}
void loop()
{
delay(10);
TCS();
if((countR>8)||(countG>8)||(countB>8))
{
if((countR>countG)&&(countR>countB))
{
//digitalWrite(motor_relay,LOW);
Serial.print(“red”);
Serial.print("\n");
delay(1000);
}
else if((countG>=countR)&&(countG>countB))
{
digitalWrite(motor_relay,HIGH);
Serial.print(“green”);
Serial.print("\n");
delay(1000);
}
else if((countB>countG)&&(countB>countR))
{
//digitalWrite(motor_relay,LOW);
Serial.print(“blue”);
Serial.print("\n");
delay(1000);
}
}
else
{
delay(1000);
digitalWrite(motor_relay,LOW);
}
}

What happened to your comments? What happened to the code tags?

actually color sensor detects green color and starts the motor through relay control but now i remove green color from sensor it does not deactivate relay and motor keep runnig why should this happen???