LDRs are resistors whose resistance varies with incident light level. They might be in around 1M in absolute darkness or less than 100ohm in full sunlight. Different makes of LDR have different characteristics (different resistances at any given light intensity) and tolerances are fairly poor (meaning that two identical devices in the same light are likely to have significantly different resistance). For example part 58-0134 from Rapid electronics specifies a resistance between 2 and 4K at 100 Lux. So 2:1 variation is within manufacturing tolerances.
The simplest way to use an LDR as a train detecting sensor is to mount it between the tracks, either between the sleepers in larger scales, or replacing a sleeper in the smaller scales. Connect one wire to 5V and the other to both a resistor to ground and also to an input pin. In this way they can connect directly to CTI, MERG, QTU or CMOS inputs. The voltage on the input will vary with light so you need to choose a resistor so that the voltage is low (< 1.5V) when a train is present and high (> 3.5V) otherwise. This system is very sensitive to ambient lighting levels and lighting directions but can be used fairly successfully for fixed layouts in rooms with no natural light. Note that the signal connected to the input pin is 'active low' meaning that a low is seen when a train is present. Using a convention of active low signals is convenient because many devices operate in this way. For example a switch from input pin to ground is the same (low when switched on). Also the output from an IRDOT infra-red detector module is similarly active low.
A more reliable mechanism is shown here. R1 is a reference LDR mounted somewhere that is never obscured by a train. R2 to R5 are LDRs mounted between the tracks to detect trains. The value of R8 to R11 should be chosen to be approximately equal to the LDR resistance in your 'average' lighting levels. R6 and R7 should add up to roughly the same value and R6 should be roughly half that of R7. My LDRs are roughly 1K in artificial light, so I chose 330ohm and 680ohm. We now have a reference voltage from between R6 & R7 that varies with ambient lighting, but is a 30% lower voltage than directly on the LDR.
The voltage from each of the other LDRs is compared with this reference voltage. If an LDR is obscured its resistance should at least double so its output voltage should drop below the reference. When this happens the op-amp20 NBov output will go low. This circuit will function reliably in a very wide range of lighting conditions from near darkness to direct sunlight. The only way to fool it is if your layout is partially in direct light and partially shaded. The components that this uses for four circuits over and above that used by the simple circuit is one IC, one extra LDR and two resistors. If connected to a QTU or MERG RPC SRI4 module it can be powered from the pins of the same connector as our outputs are connected to.
I have recently received an email query from someone who wanted to use lots of LDRs on each track section, about 15cm (6") apart. This seems like an excellent idea because LDRs are so cheap and easy to install and wire up. Having so many means that just about any item of rolling stock would be detected wherever it is.
My response to this query (that I couldn't send because of a '550 Unknown user' error) was to connect several LDRs in series and connect to a single input (whether to an amplifier or to the computer). Normally LDRs are low resistance on a model railway because they are all illuminated by the room lights. When any one is obscured by a wagon for example it's resistance will go much higher, and therefore the resistance of several LDRs in series would get much higher, thus triggering the input.
Just make sure that the resistor that connects the chain of LDRs to ground (or supply) is several times (3-10) higher than the resistance of the whole chain of LDRs when in the lowest normal illumination (sun down, room lights on).
I see no reason why you couldn't have a dozen or more LDRs in series on a single input.
Last updated 20 Nov 2013