Arduino pulsein function missed pulses..

Hi guys, I dont know how it works for others. Really

Every time when I use this function, it misses pulses. I controled these missed pulses from relay's led.

In below program I tried to get pulse values from flowmeter with pulsein function.

For example I write 6 to serial monitor and programs swich on the relay. when i count 6 pulse from flowmeter, relay is swiched off and dosing finished.

Please help me, I m thinking suicide anymore. :)(

//eprom değişgenleri
const byte interruptPin = 2;
const byte rolePin = 3;
int incomingByte;
float toplampulse;
unsigned long duration;
void setup() { 
// pinMode(interruptPin, INPUT);
 pinMode(rolePin, OUTPUT);
Serial.begin(9600);


  pinMode(interruptPin, INPUT_PULLUP);

}



// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(rolePin, LOW);   
  toplampulse2=0;
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.parseFloat();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);

toplampulse=0;

digitalWrite(rolePin, HIGH);   


do{
//Serial.println(toplampulse);

  duration = pulseIn(interruptPin, HIGH,2000000);
  if(duration>200)
  {


toplampulse++;
Serial.println(toplampulse, DEC);
Serial.println(duration, DEC);

  }
  

 if((toplampulse-1)==incomingByte)
{

  Serial.println("Dozajlama Bitti.");
    digitalWrite(rolePin, LOW);
      
  
}

}while(digitalRead(rolePin)==HIGH);


     
        }
        

}

Anyone can help me?

I'm still looking at your code. In the meantime, I've taken the opportunity to re-format it so it looks a bit more like what we're used to do perhaps others may see the issue more clearly...

//eprom değişgenleri
const byte interruptPin = 2;
const byte rolePin = 3;
int incomingByte;
float toplampulse;
unsigned long duration;

void setup() 
{
    // pinMode(interruptPin, INPUT);
    pinMode(rolePin, OUTPUT);
    Serial.begin(9600);
    pinMode(interruptPin, INPUT_PULLUP);
}

// the loop routine runs over and over again forever:
void loop() 
{
    digitalWrite(rolePin, LOW);  
    toplampulse2=0;
    if (Serial.available() > 0) 
    {
        // read the incoming byte:
        incomingByte = Serial.parseFloat();

        // say what you got:
        Serial.print("I received: ");
        Serial.println(incomingByte, DEC);

        toplampulse=0;

        digitalWrite(rolePin, HIGH);  

        do
        {
            //Serial.println(toplampulse);
            duration = pulseIn(interruptPin, HIGH,2000000);
            
            if(duration>200)
            {
                toplampulse++;
                Serial.println(toplampulse, DEC);
                Serial.println(duration, DEC);
            }

            if((toplampulse-1)==incomingByte)
            {
                Serial.println("Dozajlama Bitti.");
                digitalWrite(rolePin, LOW);
            }
        }
        while(digitalRead(rolePin)==HIGH);
    }
}

if((toplampulse-1)==incomingByte)

This is an equality test between two floats. Almost never will they be the same. Think of testing the difference between the two being less than some threshold, i.e. a - b < .01.

pulseIn() is not a good function for detecting a pulse. Try treating your input as a button press using the example File->Examples->02.Digital->Debounce Your increment of the count would replace " ledState = !ledState;".