RPM measuring

A small project for measuring the RPM speed of a DC motor using the TCRT-5000 sensor. Everybody are most welcome to view, and comment.

http://yohizu.wix.com/yohizu#!motor/c7es

It looks like the delay(80) is masking a bigger problem. Instead of just looking to see whether it is black or white, you need to keep track of whether you last saw white on the sensor or not so you can tell when the start of the white tape is. The transition between black and white is what matters.

For example, the loop could look like this (it’s pseudocode, you can write the real code). I’m using a boolean justSawWhite to keep track of whether we see black change to white, or whether it was already white:

//If we see white now, and didn't see it before, increase the counter and set justSawWhite to true
if (tcrt>500 and justSawWhite==FALSE) {
  justSawWhite = TRUE;
  //increase counter here
  //update the LCD here
}

if (tcrt<=500) { //we see black, so reset justSawWhite
  justSawWhite = FALSE;
}

Thanx. A good idea. I will try and inform. Have a nice weekend.

One of the arduino example sketches deals with detecting state transitions, called StateChangeDetection