# Issues with Photointerrupter

Hi, I’m building a circuit in which the speed of a spoked wheel is being measured through the use of a photointerrupter connected to an Arduino Uno pin. When the spoke of the wheel blocks the LED there is a LOW signal, and when the light shines through, a HIGH. By measuring the speed at which the signal changes from HIGH to LOW, the speed of the wheel can be measured. This works so far, but at higher speeds, the signal stays on HIGH, and if I switch to analog read, I see that the LOW voltage is higher than it should be. Does anyone have any insight as to why this might be, and how it can be fixed? I’ve tried different pull-down resistor values, but perhaps I’m doing something wrong.

The circuit is attached.

The code I’m using is simply:

``````int photo;

void setup() {
Serial.begin(1000000);
//pinMode(2,INPUT);
}

void loop() {
Serial.println(photo);
}
``````

Thanks!

Does it help if I tell you that analogRead takes around 100 microseconds?

(I don't see why "photo" needs to be read twice, or why it is a global)

AWOL:
Does it help if I tell you that analogRead takes around 100 microseconds?

(I don't see why "photo" needs to be read twice, or why it is a global)

Edited it, one of them was supposed to be commented out. And that does help! Let me try again and see how it performs if I only do digitalread at high speeds.

If that’s a commercial photo-interrupter, which one?

Have you tried a 10K pull-down?

It looks like your circuit would work but typically you’d use a pull-up resistor (with the emitter grounded).

This works so far, but at higher speeds, the signal stays on HIGH, and if I switch to analog read, I see that the LOW voltage is higher than it should be.

Digital low is 1.5V or less (0.3Vcc). Digital high is 3V or more (0.6Vcc).

A lower value for the load resistor will speed up the response. 10K is typical.

Try reducing the current to the LED. Perhaps light is refracting from the edges of the interrupter. Does the interrupter have a Schmit trigger output?

Paul

How many pulses per second do you want to detect?

Be aware that Serial.print() is a slow function so you probably don't want to print each pulse.

...R

DVDdoug:
If that's a commercial photo-interrupter, which one?

Have you tried a 10K pull-down?

It looks like your circuit would work but typically you'd use a pull-up resistor (with the emitter grounded).
Digital low is 1.5V or less (0.3Vcc). Digital high is 3V or more (0.6Vcc).

It is the EE SV-3 photo-interrupter. I tried using a pull-up resistor, but it didn't seem to work properly. Would the pin still be in the same location on the circuit?

jremington:

A lower value for the load resistor will speed up the response. 10K is typical.

10K did work, thanks to you and the above poster.

Robin2:
How many pulses per second do you want to detect?

Be aware that Serial.print() is a slow function so you probably don't want to print each pulse.

...R

Hmm perhaps this is the main problem. We are actually using the serial monitor so that another program (Unity) can read from it to get information from the sensors for a virtual reality bike, so if serial.print is really slow, maybe we should look for alternate ways.

Please correct your circuit diagram, as the original shows a PNP phototransistor, not an NPN. The correct EE-SV3 internal diagram is as follows, and it is important to know how you have wired the phototransistor part.

jremington:
Please correct your circuit diagram, as the original shows a PNP phototransistor, not an NPN. The correct EE-SV3 internal diagram is as follows, and it is important to know how you have wired the phototransistor part.

Yeah, you're right. I just didn't have a proper circuit diagram software so I wasn't paying attention. Fixed.

deliand:

How many pulses per second do you want to detect?

Be aware that Serial.print() is a slow function so you probably don't want to print each pulse.

Hmm perhaps this is the main problem.

So why didn't you answer my question?

...R

Robin2:
Hmm perhaps this is the main problem.

So why didn't you answer my question?

...R

I want it as fast as possible with the given hardware, I don't really have a way to count how many pulses per second I want in any quantifiable way. I know that the wheel being measured is spinning at most 300RPM, so 5 revolutions per second, and there are 4 spokes on the wheel, so I guess 20 pulses per second?

deliand:
It is the EE SV-3 photo-interrupter.

10K did work, thanks to you and the above poster.

Which one. They come in four apertures.

10k (0.5mA) should have worked.
The transistor can sink almost 6mA with that LED current (19mA).
1Megohm is wrong.

You should write a short program to see is the sensor outputs the right digital levels.
e.g.
digitalWrite(13, digitalRead(2)); // onboard LED follows sensor connected to digital pin 2.
Leo..

Wawa:
Which one. They come in four apertures.

10k (0.5mA) should have worked.
The transistor can sink almost 6mA with that LED current (19mA).
1Megohm is wrong.

You should write a short program to see is the sensor outputs the right digital levels.
e.g.
digitalWrite(13, digitalRead(2)); // onboard LED follows sensor connected to digital pin 2.
Leo..

It's EE-SV3-D.

And, yeah I did that, and the LED does seem to follow exactly. So I guess my initial problem is solved. Now I am wondering of a faster way to transfer data than serial.print. Does anyone know if serial.write is better? Or would using interrupts help in any way?

deliand:
so I guess 20 pulses per second?

That is very slow for an Arduino.

...R

For polling, it's important to know the time of the shortest pulse (the spoke?).
So what size are these spokes compared to the space between the spokes.
A picture might help.
Leo..