Henry, I'm very interested in this, also for model trains. I'm guessing your barcodes are intended to identify the trains.
How are you planning to organize the logic of the Arduino that will do the reading? For example will it react to interrupts or do you plan to do polling? How many sensor locations are you thinking of? How many trains will be moving on your layout at the same time?
I had been toying with a sort-of similar idea recently (I never got round to testing anything) and I had more-or-less given up the idea of reading the IDs from trains in favour of detecting position with LDRs and inferring the train IDs from a knowledge of which train ought to be at that location.
I'm thinking of building an automated hump shunting yard, so the barcodes will be used to identify individual wagons and there will only be one sensor location. There's not much space, even in OO, under a wagon. The barcodes will, hopefully, consist of a white (reflective) bar 4mm wide, a black (non-reflective) bar 4mm wide, another 4mm of white followed by a 2 mm black bar as the 'start' signal. The code will be 5 * 2mm bars of either black or white. As I don't know the speed of the wagons over the hump (it will obviously be dead slow, but exactly
how fast is that?) the reading of each of the first three start bars will be timed and then averaged to calculate the correct time to read the following code bars. The fourth, black, start bar is there merely to indicte the end of the third, timed, white start bar.
I can laser print the barcodes from photoshop, so they will be fairly accurate. My problem, as above, is reflectivity.
I've written a draft sketch (and it compiles
) but obviously not yet tested it.
There's no reason why this method, if it works, couldn't be used to identify whole trains. In fact, carriages have a larger area underneath for the bar codes.
Have you thought about using magnetic reed switches to detect trains? They can also be used to differenciate between a small number of trains by arranging them as AND logic switches.