QTR-1RC Reflective Sensor for measuring RPM (Please Help)

Hi,

I wanted to use an IR reflective sensor to measure shaft RPM. I have been trying to look around to get some help with this, but I haven't been able to find the information that I need.

Below is the link of the IR sensor I am trying to use. The following is a code that I found, which I believe can be manipulated to read RPM. However, I am new to using Arduino and could use some help and guidance. Any advice would be greatly appreciated as this is for a project I am doing at University.

This is where I found the code below: QTR-1RC reflectance sensor simpler code - Sensors - Arduino Forum

unsigned long time;
int color=1,last,last_color;
void setup()
{
Serial.begin(9600);
}
void loop()
{
pinMode(9,OUTPUT);
digitalWrite(9,HIGH);
delayMicroseconds(12);
pinMode(9,INPUT);
time=micros();
while(digitalRead(9)) {}
// Serial.println(micros()-time);
 
 if((micros()-time)>last && color==1) color=-1;
     else if((micros()-time)<last && color==-1) color=1;
  
   if(color!=last_color) Serial.print(color),Serial.println(" ");
   last=micros()-time;
   last_color=color;
}

[code]

Such an analogous single-wire sensor is much too slow for RPM measurement :frowning:

You need a fast (digital) light barrier.