I have toyed with the idea of a self made barcode stuck to the underside of each wagon to identify it and reading this with an IR LED and detector, but don't know how to detect the start of the read cycle and how to control the timing of reading each bar. Although the speed will be quite slow, it may not be constant.
RFID tag on each train and a reader at the track?
Ir LED on each blinking at different rates.
Assuming you've rigged up your IR reflectance sensor right (and that's a big assumption), it should trigger low when the white label of the barcode starts as hopefully the barcodes are the only reflective thing passing over the sensor.
A little mirror with bits of evenly spaced black tape.
I don't know these guys but it looks like a ready hardware part of the solution:http://www.phidgets.com/products.php?product_id=1102_0OTOH, knowing that black and white reflect differently you can try making your own sensor and yes, tape a bar code under each car.Consider using white stripes (more reflective) for data and black stripes as reference widths. A zero would be a narrow white stripe and a one would be 3x as wide a white strip. The black stripes would all be narrow. You would be reading perhaps 10,000x a second, keep count of how many reads the last black stripe was and if the next white strip is less than 1.5x as many then it's a zero bit but if 2.5x or more then it's a one bit.Then start your data sector with an attention section of 8 narrow b/w stripes followed by a wide black stripe, the next white stripe begins your data.The boffo setup would read the same no matter which direction the train is going, attention section at both ends and each car's ID being symmetric. You could get away with 2 number / 4 white stripe codes that would read 0000 0000, 0001 1000, 0010 0100, etc.
Adafruit has a bunch of RFID tags and several readers.The tags are programmable. Each also have a 4-byte unique ID that is not changeable.http://www.adafruit.com/category/55
I was thinking of making my own detector by mounting the IR LED and IR detector in 5mm ID brass tubes with the tops of the tubes level with the track bed and the LED and detector some way down the tubes (think optical rangefinder). That way, I can make the detector more sensitive and focused on a narrow area.