RoboCup Junior IR Ball detection
The basic approach is to make an interrupt handler that will be invoked each time the IR receiver receives a pulse.

When you receive each pulse, you capture the elapsed time from the previous pulse.  If the elapsed time is 25 microseconds, you know you are in the middle of receiving a burst of pulses, and you should be counting them.  If there's a gap of 346 microseconds or more, you know you are in the inter-transmit gap.  You can then count the pulses you have received.  If there are 8 pulses, you know the ball is far away, since you only received the highest strength pulses.  If there are 12 pulses, it's a little bit closer. Likewise until you receive 20 pulses, meaning you are the closest to the ball you can measure.

Of course, being in the real world you might miss a pulse or two for some reason, so your counting method should take that into account.  Likewise, the timing might be a little bit off (either your clock or the ball's clock might be slightly off), so that would need to be taken into account as well.  If the ball is not visible at all, there won't be any pulses read.

In the Arduino environment, we would use the interrupt functions and the basic code would look something like this.  Assume the input is on digital pin 7.

volatile int npulses = 0;             // number of pulses received in this "set"
volatile unsigned long lasttime = 0;  // timestamp of last pulse received
volatile int distance = 0;


void dopulse()
{
    unsigned long now;  // the current time in microseconds
    now = micros();
    elapsed = now - lasttime;
    lasttime = now;
    if (elapsed &gt; 300) {
        distance = npulses;
        npulses = 1;
   }
   else {
       npulses += 1;
   }
}

void setup()
{
    pinMode(7, OUTPUT);
    attachInterrupt(7, dopulse, RISING);
    ...
}