Can't get an IR photoresistor to work

Have you tried yet pointing the "tr" (transistor) at an incandescent lamp? Plenty of IR in those!

One of these will make a difference ... or maybe just change your existing current limiting resistor for the IRLED from xxxxxΩ to 220Ω.

dlloyd:
From Datasheet "Filter bandwidth is matched with 900 nm to 950 nm IR emitters"
Well, I guess you have an 820-880 nm IR LED (which are quite common). Yeah, it doesn't take much of a mismatch to get poor response. 10K should be fine with the proper IR LED.

Then why time ago it was working fine with the same led and even with a red led?

jremington:
Have you tried yet pointing the "tr" (transistor) at an incandescent lamp? Plenty of IR in those!

Unfortunately I don't have incandescent light, only LED in my home

dlloyd:
One of these will make a difference ... or maybe just change your existing current limiting resistor for the IRLED from xxxxxΩ to 220Ω.

The resistor on the IR LED is already 220ohm

Then why time ago it was working fine with the same led and even with a red led?

Hard to believe you had the same parts ... haven't seen a dark lens ever allow red visible light through.

EDIT: OK, here's a scenerio ... the 2 parts are now mixed up ... the phototransistor is the clear part, the dark part which could actually be an IRLED, is being connected in reverse and works as a weak photodiode.

The Vishay phototransistor is black:

TEFT4300 is a silicon NPN phototransistor with high radiant
sensitivity in black, T-1 plastic package with daylight
blocking filter. Filter bandwidth is matched with 900 nm to
950 nm IR emitters.

ariesbreath:
Unfortunately I don't have incandescent light, only LED in my home

I wondered about that. In another ten years the response might become, "what's an incandescent light?"
S.

dlloyd:
EDIT: OK, here's a scenerio ... the 2 parts are now mixed up ... the phototransistor is the clear part, the dark part which could actually be an IRLED, is being connected in reverse and works as a weak photodiode.

No no, definitely not, the phototransistor is black and the IR LED is transparent

OK, then I guess you've measured about 1.2V across the clear IRLED while its powered through the 220 ohm resistor. Well, I'm out of ideas ... I guess your phototransistor went bad. Wait ... one more idea ... the part is black due to burn out / smoke damage?

ariesbreath:
No no, definitely not, the phototransistor is black and the IR LED is transparent

The IR phototransistor appears black because it incorporates an optical bandpass filter which is opaque to visible wavelengths. This is not needed in the LED because its spectral output is limited by the nature of the semiconductor junction.
S.

You may get some useful suggestions from this article

An Infrared LED should have a forward voltage around 1.2V; if you're powering it from 5V a 220 ohm resistor will allow around 17mA which should give a good response from the phototransistor.

I'm assuming you are testing the response just with a voltmeter and NOT connected to the Arduino.

With a 100k resistor you should have a responsive detector.

An Infrared LED should have a forward voltage around 1.9V

Vf of 1.9V is only possible for some specific lower wavelength types, and pulsed with at least 1 amp or higher at very limited duty cycle.

A typical Vf curve for an Infrared LED looks like this, where Vf is 1.1V to 1.2V for DC current at 10-20mA.

Thanks Mark: I got my info from this site:

However on checking a LOT of data sheets the vast majority do quote 1.2 - 1.4V for Vf at 20mA.

UPDATE:
After some trial and error I noticed that the analog readings were not accurate, to the point that when compared to something inside an "if" function they gave opposite results (is analogRead greater than x? the read gave y<x but the result of the "if" gave as y was greater than x).

So I searched a bit and found out that the multiplexed ADC gives incorrect results when asked for a read multiple times in a short timespan, and the solution to this is to re-read the pin once again or to wait some time.

I tried to read the pin multiple times and it come back to correct values after the third reading.

Given that this phototransistor have to read a piece of plastic shot at 100 m/s I don't think I have much time to do multiple readings, is there a way to solve this? I read that some capacitors can help.

Also, if I do a digital read on an analog pin, I suppose the ADC is responsible for it, right?

Also, should I make a new thread?

If your original issue has been solved - in other words if you are now getting sensible output from the phototransistor - and you now have a new problem, then it would seem sensible to start a new thread.
You can always link to this one.

I'd recommend you:
explain what you are trying to do

and what components you are using - with links to data sheets
and which Arduino you are using

post a decent accurate schematic How to make a schematic you can post.

and your code.

After some trial and error I noticed that the analog readings were not accurate, to the point that when compared to something inside an "if" function they gave opposite results (is analogRead greater than x? the read gave y<x but the result of the "if" gave as y was greater than x).

that makes no sense - if y is 3 and x is 2 then y>x and an IF MUST show that.

So I searched a bit and found out that the multiplexed ADC gives incorrect results when asked for a read multiple times in a short timespan,

where did you find that?

OK, let's summarize:

  • Previously, you had everything working and were getting readings in the range of 0 to 900.
  • The IRLED is the clear component and we don't have a part#. It is connected to 5V with a 220 ohm current limiting resistor. This means the current is (5-1.2)/220 = 17.2mA (this is good).By not knowing the part#, we don't know the wavelength. From the TEFT4300 datasheet, this shows that if the IRLED is 860nm the response will be 10%, but if its 920nm, the response will be 100%. This is a big difference for a relatively small change in wavelength.

Alignment:
Even so, it's still possible that you had everything working with an IRLED rated at 860nm, because one thing that hasn't been mentioned is alignment. Your phototransistors sensitivity vs. Angular Displacement is only ±30 deg. That is, if the light source is at 30 deg, the phototransistor will only be 50% responsive. Another thing that could be even more critical is the alignment of the IRLED ... some are rated at only ±6 deg viewing angle (but we don't have a part#). Maybe previously, the alignment was ideal, but now its misaligned. Just a small misalignment can make a huge difference.

Regarding your finding that you need to take multiple readings, this is because the ADC is rated to work with input impedance up to 10K. So with higher values the readings become less reliable and stable and it can take multiple readings to charge the ADC capacitance.

johnerrington:
If your original issue has been solved - in other words if you are now getting sensible output from the phototransistor - and you now have a new problem, then it would seem sensible to start a new thread.
You can always link to this one.

Not really, I'm just using a workaround, I still don't know why it behave like this. Anyway, I'll start a new one

johnerrington:
that makes no sense - if y is 3 and x is 2 then y>x and an IF MUST show that.

In fact, the problem is that the second read is different from the first, that's why it gave a wrong result

johnerrington:
where did you find that?

Many threads here on the forum.

dlloyd:
OK, let's summarize:

  • Previously, you had everything working and were getting readings in the range of 0 to 900.
  • The IRLED is the clear component and we don't have a part#. It is connected to 5V with a 220 ohm current limiting resistor. This means the current is (5-1.2)/220 = 17.2mA (this is good).

Unfortunately I don't have code or ID, but the vendor says the IR LED is 940nm and 60° angle. Also the alignment isn't a problem as I 3d printed a case that holds them in line.

dlloyd:
Regarding your finding that you need to take multiple readings, this is because the ADC is rated to work with input impedance up to 10K. So with higher values the readings become less reliable and stable and it can take multiple readings to charge the ADC capacitance.

So because I'm now using 680k ohm resistance on the phototransistor I give the Arduino impedance greater than 10k?
Is there a way to prevent this?

Unfortunately I don't have code or ID, but the vendor says the IR LED is 940nm and 60° angle. Also the alignment isn't a problem as I 3d printed a case that holds them in line.

Ahh, like this would have been good to know just a bit sooner.

So because I'm now using 680k ohm resistance on the phototransistor I give the Arduino impedance greater than 10k?
Is there a way to prevent this?

Yes ... replace the phototransistor and maybe the IRLED too. (not very costly).

One last possibility ... solder flux/paste residue causing leakage between the phototransistor pins. I would carefully scrape-clean all residue ... use alcohol or PCB cleaner. Then re-test and see what happens.

dlloyd:
Ahh, like this would have been good to know just a bit sooner.
Yes ... replace the phototransistor and maybe the IRLED too. (not very costly).

Sorry, my bad. Why should I replace them? Anyway this is the third couple of phototransistor and IR LED I tried.

dlloyd:
One last possibility ... solder flux/paste residue causing leakage between the phototransistor pins. I would carefully scrape-clean all residue ... use alcohol or PCB cleaner. Then re-test and see what happens.

Given this is the third try and everytime I used new pins and everytime it gives the same result I don't think that could be the problem

Given this is the third try and everytime I used new pins and everytime it gives the same result I don't think that could be the problem

Yes, you would consistently have the same problem if the solder connections here have never been cleaned ... so just replacing the parts wouldn't fix this issue (if this is the issue).

I know from experience that the slightest amount of flux or solder paste can ruin the response of a phototransistor. A while back (I won't say how long) I developed a photo sensor that was retro-reflective and could detect the moving black mark on the edge of an electricity meter disk from up to 6" away and through the glass cover. The photo transistor was very sensitive - it had a 3rd pin (base) that needed to be cut and the remaining 2 connections (collector and emitter) needed to be cleaned thoroughly. Note that with 680K, there's only about 7µA to work with.