IR Sensors - Working, but confused re Photodiode v Phototransistor

I'm experimenting with a "Beam-Breaker" setup to sense presence of rolling stock on a model railway layout. I'm using a TSUS5400 IR emitter and have paired it with the following sensors, which appear to work equally well

1) A BPW41 IR diode (2 legs), used the "Right" way around i.e. anode to the + side of the circuit, cathode to the A0 pin (with the resistor to ground, circuit schematic attached).

2) A L-7113P3C Phototransistor

Each seems to work perfectly well - so I have a couple of questions.

What I mean by "Works" is that (after juggling with the resistor value) I get a max reading of 1023, LED On, for distances up to about 5cm, tailing off up to 10cm, and with drops in readings of varying amounts depending on the sort of rolling stock I pass through the gap, whether the item is closer to the emitter or the sensor etc. - in short, beam not broken get high reading, beam broken get low reading. Plus various ambient effects depending on lighting, sunshine etc. But the circuit I'm using looks too simple!

My questions are

1) I've read in several places (but can no longer find the links!) that the IR Photodiode should be connected the "Wrong" way around i.e. with the Cathode to the + side of the circuit (Schematic attached), but I don't see the benefit of this - or even that it would work. Could someone explain please in simple terms? NB I haven't tried it yet in case I've misunderstood, and end up blowing something up!

2) I'm not sure of the differences/benefits of the IR Photodiode v IR Phototransistor - again is there a simple explanation (in my context)

Many thanks for your help, just want to understand what I'm doing and why, rather than settling for an "It works" approach, but my electronics knowledge is almost zilch so I don't understand most of the explanations I've "googled"! - Dick.

PS Once I've finished I'll be happy to post up my results

UPDATE Please see my somewhat embarrassed "Reply" of 25/02/2014 @ 19:25

Photodiodes and phototransistors work on the same basic principle: when light falls on a diode junction, a small current is generated but it flows in the opposite direction of the diode "arrow" symbol. For reliable operation the current from a photodiode generally needs to be amplified before detection by an Arduino, which is done for you by the transistor action of the phototransistor.

Either a photodiode or a phototransistor can be made to work in your situation but you've already noticed the real problem: sensitivity to changes in ambient light levels. You will generally be better off using a phototransistor with matching light source (e.g. IR LED) but in difficult cases you may need to modulate that light source so that it is much more easily distinguished from the background. IR remotes work this way, but modulating the beam (turning it on and off) at a frequency of typically 38 kHz. You can buy modulated photointerruptors for this case.

Update 25/02/2014 - a bit of egg on face here - had another look at the Vishay datasheet and realised that what I’d thought was a top-down drawing of the item was a bottom-up one, so I had connected the cathode to positive after all! In my defence I have to add that the wires are both the same length :blush:

Which means that I’m measuring the current described by JRemington (thankyou J) after all, somehow, and my understanding of how the IR photodiode works has now changed. I’m effectively removing the “block” on current transmission when the IR LED is shining on the sensor, and gradually replacing it as I “Break the Beam”, rather than the diode being activated while IR light is shining on it which is how I thought it worked :astonished:.

Am I getting readings on A0 simply because I’m measuring the current being passed from the +5V supply, in addition to the current generated by the Photodiode itself?

Updated schematic attached to this reply, original removed from the original post.

If your most recent diagram is correct (what is the value of the resistor?) then you are measuring the voltage drop across the resistor, due to the photo-induced current in the diode. To check if this assumption is correct, put the assembly in pitch darkness -- you should measure 0 V. Furthermore the voltage should increase linearly with light intensity, but you would need some other way to measure light intensity to verify that.

Readings go down to 1 or 2 when the IR LED is switched off, and 0 when there is no light.

The resistor is 100k. Smaller resistors give smaller readings, larger resistors give larger readings.

The readings when I block the IR Emitter-receiver path are below

Chassis height readings - chassis/coupling height. "Base" reading means nothing blocking the beam Near Sensor means item is near the sensor, "Near Emitter" means item is just in front of emitter Emitter - Receiver gap = 10cm Item blocking beam Base Near Sensor %Change Nr Emitter %change Coach – max 414 103 -75 13 -97 Coach – min 414 13 -97 6 -98.5 Small Flat 414 18 -95.5 12 -97 Open Wagon 414 17 -95.5 5 -99 Guards Van 414 18 -95.5 5 -99 Gap Open Wagon+ Guards 414 230 -44 130 -68.5

I'm getting the results I was looking for, and thanks to JRemingtons info I (nearly!) understand why!

The purpose of the exercise is to gather information - current thinking is that I will use the %age drop as a parameter for the Arduino to check, so that an event - or series of events- can be triggered.

I've done a similar experiment using an LDR, where the ambient light is much more important - if I go down that route then constant ambient light monitoring will have to form part of the solution, where with the IR-based solution it will be less important, and impacts can be mitigated by careful location of the sensor and any reflective surfaces opposite. Perhaps!

Many thanks - Dick.