The following is a method to allow day and night detection using Infrared or Visible light sensitive phototransistors and a simple LM339 voltage comparator circuit.
A phototransistor is mounted between the rails so that it is covered by the train as it passes. A system widely used in model railroading.
For daytime operation the room lights would be on and when the train blocks this light the train is detected. However when the room lights are dimmed or turned off for night operation, under normal conditions the phototransistor would go dark and act as if it was covered by a train and give a false detection.
To prevent the phototransistor from going dark when the lights are dimmed, mounted above the detector at ceiling height is one or more infrared light emitting diodes.
With the room darkened the phototransistor will see the infrared light and remain in an ‘ON’ or conducting state. As far as the phototransistor is concerned it is always illuminated by visible or infrared light.
Visit Here for more.