user11025: I have a DC motor which is rated at 11 200 RPM.
I would like to count the actual RPM (it seems to be maybe 1500 RPM from what I can tell manually.) 
I bought a Photo Interrupter, and have connected it to pin A0. When the beam of the Photo Interrupter is broken, the reading drops to zero.
All seems to work well when using a delay of 100, but as soon as I drop the delay to less than about 50, I get multiple reads.
This is my code: 
int must_print = 1;
int sensorValue = 0;

//the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  sensorValue = analogRead(A0);

  if (sensorValue > 0) 
    {
      if (must_print == 1)
      {
        must_print = 2;
        Serial.println(sensorValue);
      }
    }

  if (sensorValue == 0) {
    must_print = 1;
  }

  delay(100);        // delay in between reads for stability
}

At delay(100) the Serial Monitor looks like this for a single interrupt of 10 seconds:
354

At delay(50) the Serial Monitor looks like this for a single interrupt of 10 seconds:
298
312
328
336
349
360
366
371

Thanks!

user4143: You shouldn't use an analog pin with a photointerruptor.  The photointerruptor is a digital device.  Connect it to, preferably, an interrupt pin and use an interrupt to count your revolutions at high speed.

11025: <p>I have a DC motor which is rated at 11 200 RPM.</p>

<p>I would like to count the actual RPM (it seems to be maybe 1500 RPM from what I can tell manually.) </p>

<p>I bought a Photo Interrupter, and have connected it to pin A0. When the beam of the Photo Interrupter is broken, the reading drops to zero.</p>

<p>All seems to work well when using a delay of 100, but as soon as I drop the delay to less than about 50, I get multiple reads.</p>

<p>This is my code: </p>

<pre><code>int must_print = 1;
int sensorValue = 0;

//the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  sensorValue = analogRead(A0);

  if (sensorValue &gt; 0) 
    {
      if (must_print == 1)
      {
        must_print = 2;
        Serial.println(sensorValue);
      }
    }

  if (sensorValue == 0) {
    must_print = 1;
  }

  delay(100);        // delay in between reads for stability
}
</code></pre>

<p>At delay(100) the Serial Monitor looks like this for a single interrupt of 10 seconds:</p>

<pre><code>354
</code></pre>

<p>At delay(50) the Serial Monitor looks like this for a single interrupt of 10 seconds:</p>

<pre><code>298
312
328
336
349
360
366
371
</code></pre>

<p>Thanks!</p>
 4143: <p>You shouldn't use an analog pin with a photointerruptor.  The photointerruptor is a digital device.  Connect it to, preferably, an interrupt pin and use an interrupt to count your revolutions at high speed.</p>
