May I suggest more than one magnet per train to differentiate them.<p>Simplest way: number of magnets corresponds to train ID. Small space between magnets (calculated from Hall sensor refresh rate and max train speed). Count number of Hall sensor trips (maybe with debounce) within some time period (calculated from the minimum train speed during crossing and the magnet spacing).
Disadvantage: Train minimum speed must be reasonable. Requires n(n+1)/2 magnets, or 36 for 8 trains.<p>More reliable way: two columns of magnets, slightly offset, spaced as above. Two Hall sensors in a row under the track. Col 1 is clock. Col 2 is data. Whenever Hall 1 (clock) goes high, read Hall 2 (data) (maybe for a short period for debounce). To keep things simple and stay away from speed assumptions, put the same number of clock magnets on all trains: log2(train count), rounded up, for example 4 for 16 trains.
Disadvantage: Requires twice as many Hall sensors. Requires about log2(N)<i>1.5 magnets per train, so 96 magnets for 16 trains, as opposed to 16 for the original method. Those tiny neodymium magnet bars are cheap, though.
BONUS: Train speed measurement. Speed is the clock magnet spacing divided by time between clock Hall trips. Now you can run a Pi algorithm (e.g. PID) to move trains at a target speed regardless of load, at least in the regions with Hall sensors.<p>If you are willing to assume the train speed is constant while passing the sensors and do more complex signal analysis on the Pi, the intermediate clock magnets can be removed, reducing the magnet count to N(2 + log2(N)</i>0.5)=64.
If anyone curious about railway modelling, I think, the game "Rolling Line" is an interesting simulation of it, including VR support, it is available in Steam.<p><a href="https://youtu.be/UjfsRfxOtU8" rel="nofollow">https://youtu.be/UjfsRfxOtU8</a>
There was a model railway show in London in the mid 70s that my grandfather took me to.<p>The least decorated layout there was the most interesting, as it was computer controlled. Even better, a small child could program it by writing instructions on paper and handing them to the controller who then put them into the computer<p>For a 10 year old, this was magical! This may have triggered my interest in computers
Bit off-topic but my friend uni’s RTOS course was all about train scheduling, which seems like a fun way to teach it (not sure if it was Hornby 00 Gauge like this)
There seems to be a nexus between model trains and computing [1].<p>I get that one can be seen as a simplified model of the other, but can anyone expand further on the attraction?<p>[1] <a href="https://en.m.wikipedia.org/wiki/Tech_Model_Railroad_Club" rel="nofollow">https://en.m.wikipedia.org/wiki/Tech_Model_Railroad_Club</a>
Some of the trains you can buy now are amazing.<p>I pass the physical presence of this place frequently <a href="https://railsofsheffield.com/" rel="nofollow">https://railsofsheffield.com/</a> & their window displays make me drool.<p>I guess my loft is going to be repurposed when I retire :)
I regret, though should be grateful, that I live in a space too small to fit my own model railroad setup.<p>Been thinking about building an El onto the crowning for a while, though.