N-scale model railway, using Hornby Zero 1 DCC system controlled via Arduino and single-board computer built from component ICs. Starting from an arbitrary configuration of cars on the sidings, the system reads car positions and then sorts them into two trains based on the color of the mirror attached to each car. Track occupancy is detected by a single IR beam-break sensor; once cars have been placed, the 3D-printed structure clears the sensor by pushing the cars out of the way.