IR Tripwire setup

OK I'm working on some automation for my model railroad. It's pretty simple really I have a tram that needs to stop at a couple stations and then return to the main station, rinse and repeat. sounds pretty simple. I have the motor control down, I can get the tram to move both directions easily. My problem is the stops. I need the tram to stop at a station and I need the sensors to be IR as my layout will be operated in many lighting conditions including darkness. My plan was to have an IR sensor and IR LED hidden in the scenery and when the tram breaks the beam the Arduino stops the train for several seconds before letting it move to the next station.

So I bought some IR Receivers from ebay, and some IR LEDs too. I set the arduino up to read the IR receiver through the serial monitor using the potentiometer sketch in the included examples. Supply the LED with 3.3V and a 1K resistor (solid 3.3V fried a LED in a few minutes, with the resistor it didn't even get warm) I used my iphone camera to see the LED was on. When the receiver is supplied with 5V the serial monitor is supplied with an output of 1023/255 on that sketch but when I put the sensor in front of the LED it only changes state for a split second and then goes back to 1023/255. Breaking the beam again only created a quick change in the state (too fast to see the actual numbers).

I need a steady and constant change in the numbers to hold the tram at the station. I need there to be 3-5 stations and eventually I was wanting a readout on the location of the tram on a 16x2 LCD, but I will worry about that later. What am i doing wrong? Anyone have any idea if it is the code I was testing with or am I asking for something to do what it cant?

My Receiver is very similar to the KY-022 (no metal shroud on my sensor) and my LEDs are 850nm.

Thank you in advance for any guidance.

3-pin (KY-022) sensors expect (38kHz) modulated IR.
They reject constant (IR and ambient) light.
They have digital outputs.
Most 3-pin sensors are not made for beam-break.

Not sure if you can use constant IR light (IR LED and 330ohm CL resistor) and a photo diode/transistor (2 pins) across a track. It will be sensitive to ambient light (sensor needs shielding).
Leo..

You could try a reflective sensor mounted in the track facing the underside of the engine with reflective strip.
A magnet on the bottom of the engine and reed switch on a sleeper might be an easy route too.
For optics the previous post is good - just look for a change in signal ?

Thanks for the replies. Well the 38Khz issue explains a lot. I looked into using a photo resistor but unless it is tuned to the IR light only it wont work for my needs. So basically If I have a 38kHz oscillator attached to the LED then the sensor I have will work for a beam break. Since ambient light in the train room gets sunlight as well as operating in minimal light at night using IR seemed to solve the lighting issues. I also don't want to see the "beam" I was planning on hiding the sensors in scenery so you don't even know it's there.

Hammy, this sensor is to stop the tram at a station. It will be on it's own track and signaling will not be needed. As for the magnet and reed switches I thought about that too. Once I got the tram I realized even a tiny magnet is going to be too much for the little tram. First off this is N scale (1:160) and the tram is absolutely tiny. So the best solution I came up with is IR beam break. Photo sensor doesn't allow for night operations. Thanks for the options though I really appreciate it.

Oh and this is my first time using IR sensors that are not prepackaged like for a robot. I'm not great at writing my own sketches but I can adapt existing ones to suit my needs. I'm learning more every time I start a new project.