A raspberry pi is programmed to control a simple model train loop. The pi detects the train location with a photo-sensor to make the train stop, wait, and run. The photo-sensor is also used to switch the track to make the train go straight or turn into the train station.