False lectures IR sensor

Good morning,

I have a problem with my counter.

I´m using this IR sensor:
http://www.electronicaestudio.com/docs/SHT-015d.pdf

I placed a R=10K pull-up.

The problem I have: Sometimes I have false lectures and I want to eliminate it. I read about the bouncing and I tried to add a delay(500) to reduce it. Now its better than before but I still have the same problem.

Can you help me?

thanks in advance

This is my code:

void loop()
{
  lectura = digitalRead(pinsensor);

  if (lectura != 1)
  {
    contador=contador+1;
    printN(contador);
    delay(500);                   //I reduced a little bit the falses lectures
    while(digitalRead(pinsensor) != 1)
    {}
  }

You should look at the state change detection example. Count only when then switch BECOMES pressed. No delay() and no blocking while needed.

Thank you PaulS