Tracking position of disc using photodiode

Hello Everyone. I am trying to track the position of this disc that is mounted on to a motor using a OPT101
Monolithic Photodiode and Single-Supply Transimpedance Amplifier. On the disc i have placed 6 q-tips that hang off the edge of it. These q-tips interrupt a 635 nm laser that is pointed at my photodiode. Each time a q-tip passes over the photodiode, the position is increased by 1 until position 6 is reached where it starts over from position 1 the next time a q-tip passes over it. The problem is that since this disc is spinning at 130 RPM sometimes it does not detect when a q-tip passes over the photodiode. I do not know why this is happening... could it be that the arduino is not sampling fast enough? Or could it be that my photodiode has a poor response time? If so, is there a photodiode you could suggest for me to use instead of my current photodiode?

I would check that your q tips are interrupting the light correctly , then it's about your coding.
I would be using the photodiode to create a interrupt to the processor and use that to calculate position.

You might be better off with drilled holes in the top of the disc and multiple sensors under it - less processing demand and you can get the absolute position of the disc

So what is the timing of the optical path being blocked? What is the photodiode circuit?
Where is your code? Lots of details are missing without which there's no way to tell anything.

MarkT:
So what is the timing of the optical path being blocked? What is the photodiode circuit?
Where is your code? Lots of details are missing without which there's no way to tell anything.

I will try my best to answer these questions. First the way I have my photodiode wired to the arduino is attached below. I also attached a diagram of my setup. Second the code I am using goes as follows:

unsigned long start;
int sensorPin = A0;
int sensorvalue = 0;
int position1 = 0;
int increment1 = 0;
int differencesensorvalue = 0;
int sensorvalue2 = 0;

void setup() {


  Serial.begin(9600);
  Serial.println("State Last Position");

  
}
void loop()
{
  if(increment1 == 0){               // This is put in this if statement so that the setupposition function is only used once in this program
    setupposition();
    }
    positionofwheel();              // This function will determine the position of the wheel each time a q tip passes over it, there are only 6 positions
}

void setupposition(){
    delay(4000);
    if (Serial.available())
   {
     position1 = Serial.parseInt();
     if (position1 < 1 || position1 > 6)
     {
       Serial.println(position1);
     }
     
   }
   increment1 = 1;
}

void positionofwheel(){
  sensorvalue = analogRead(sensorPin);
  differencesensorvalue = sensorvalue2 - sensorvalue;
  if(differencesensorvalue >= 40){
      if(position1 == 6){
      position1 = 0;
    }
     position1 = position1 + 1;
     Serial.println(position1);
    
  }
    sensorvalue2 = sensorvalue;
}

Third, I am not sure what you mean by "optical path being blocked"

Setup.png

photodiode setup.png

So what is the timing of the optical path being blocked? Your diagram doesn't have any dimensions
on it from which to calculate this.

Can you provide a circuit diagram of your photodiode, which is intelligible (ie has all the
components drawn with component symbols, and connected as they are connected). We
need to know it is a fast or slow circuit.

MarkT:
So what is the timing of the optical path being blocked? Your diagram doesn't have any dimensions
on it from which to calculate this.

Can you provide a circuit diagram of your photodiode, which is intelligible (ie has all the
components drawn with component symbols, and connected as they are connected). We
need to know it is a fast or slow circuit.

I have uploaded three more attachments and I believe this is what you are looking for. Quick note for the file labeled "setup2" I used an op amp to represent my OPT101 Monolithic Photodiode and Single-Supply Transimpedance Amplifier. So I have also uploaded my pinout for my photodiode/op amp.

pinout.png

You have given no means of calculating the timing of the optical path being obscured. An object
is passing in front of the photodiode at some speed, it has some width. What is the radius at the
point of sensing, and what is the thickness of the Q-tip and of the sensor?

I can determine that the angular velocity is 13.6 radians/second, so if the radius at the sensor is 70mm
as in the circle on that diagram, that gives a linear velocity of 0.95m/s. Say the Qtip is 3mm across,
that would imply about 3ms to cross the diode. If the diode's sensitive area is 1mm across that's a
rise- and fall-time of about 1ms.

That photodiode amp seems to have a 23kHz bandwidth in that configuration, which is sluggish
for a photo diode detector - fast photo diode circuits sense the current at constant reverse bias voltage.

But for the sorts of speeds you are using it should be fast enough.

The next stage involves looking at the waveform really.

My first suggestion is that the obscuration isn't as clean as I'm imagining, and a wider object should be
used to block the light.

Is there a lot of stray light?

MarkT:
You have given no means of calculating the timing of the optical path being obscured. An object
is passing in front of the photodiode at some speed, it has some width. What is the radius at the
point of sensing, and what is the thickness of the Q-tip and of the sensor?

I can determine that the angular velocity is 13.6 radians/second, so if the radius at the sensor is 70mm
as in the circle on that diagram, that gives a linear velocity of 0.95m/s. Say the Qtip is 3mm across,
that would imply about 3ms to cross the diode. If the diode's sensitive area is 1mm across that's a
rise- and fall-time of about 1ms.

That photodiode amp seems to have a 23kHz bandwidth in that configuration, which is sluggish
for a photo diode detector - fast photo diode circuits sense the current at constant reverse bias voltage.

But for the sorts of speeds you are using it should be fast enough.

The next stage involves looking at the waveform really.

My first suggestion is that the obscuration isn't as clean as I'm imagining, and a wider object should be
used to block the light.

Is there a lot of stray light?

Ahh I see what you are looking for now. I am unsure of what the radius at the point of sensing is.

As for the q-tips, their widths are listed below:

2 q-tips are about 9.525 mm in width

1 q-tip is about 4.6355 mm in width

1 q-tip is about 6.35 mm in width

1 q-tip is about 3.175 mm in width

1 q-tip is about 7.9375 mm in width

The width of my op amp is about 4.7625 mm and the length is 6.35 mm.

I believe there is a lot of stray light sometimes. Sometimes I try to run it with the lights off(except my laptop light, which is not pointed at my photodiode) and sometimes I run it with the light on. In both cases the positioning seems to be off. Thank you for all your help so far.

1 q-tip is about 7.9375 mm in width

You shouldn't quote 5 significant figures when you say "about"!! Its about 8mm.

The variation in sizes is a big issue here, you won't find a threshold level that's good for all of them
unless they are similar in size. You should probably consider lollipop sticks which are about 10mm
wide and all the same size...