For a model train, I would suggest either a hall effect sensor or a phototransitor.. -Rolan