LEGO 9v Train Axle Sensor

Questions on lugnet.trains and lugnet.robotics had me thinking about how to use the Mindstorms light sensor to read barcodes. While I was working on that project, it occured to me that the work I'd done on seeing dark and light stripes passing at variable speeds could be applied to train axles.

The following sensor sits one plate height above the sleeper (and 1 stud back, to avoid hitting passing trains). It uses a 1x2 technic beam as a guide to aim the sensor directly across the track. This puts the sensor just above the rails, but low enough that it can see underneath lowered car bodies (like the Club Car). The only things that block it are wheels and the entire motorized bogie. As a light source there is an IR LED inside another 1x2 beam mounted at the same place on the opposite side of the track. This IR LED is fairly directional already. When it's on, and there is no car, the light sensor reads 70+. When a wheel is in the way the sensor reads about 30. I think it would be possible to substitute a standard 9v light here.

Using this sensor, the RCX can identify:

From that, it can identify:

NQC Source for RCX

You can download the source and play with this yourself. The source describes the three functions which are called for the various types of cars and names several cars from various sets which satisfy the requirements.

This program can adapt to various train speeds and even accelerating and decelerating trains. This program can keep up with a train (one engine, several cars) going up to speed 3 (on the control knob). At speed 4 its recognition is down to about 80%, sometimes mistaking standard bogies for engines because the RCX can't distinguish the small gap in the middle. If you need to work at that speed you could fold the engine and double-bogie car detection together and still count cars with 100% accuracy. I haven't tested much at 5 and 6, but it seems to be about the same as 4.

Future Plans

I'm still intrigued by the idea of adding barcodes to the bottoms of cars and using the RCX to scan them and identify individual cars. The stock firmware is not going to be fast enough to do this.

Other Designs

Another train detection device was described and rendered by Ted Michon. It uses a touch sensor to detect the existance of a train.
[Ben Jackson's Home] [LEGO Raytracing Home] [Mindstorm]