With Prof. Chaos's layout as inspiration (see his YouTube videos and other posts here,) I am developing an autonomously-controlled layout using several Arduinos.
So far, I can throw turnouts by closing relay contacts briefly, read track occupancy via isolated rail closing relays and seeing those as inputs on the Arduino, read RFID tags of trains as they pass by the reader, and of course send Legacy and TMCC commands to locomotives. Plus lots of other small things that make the project that much more fun, such as a "trigger/event" table that will do things like turn on the bell as a loco pulls out of a siding, and then turn it off when the loco reaches a certain speed. And make appropriate announcements as the train leaves a siding, travels around the layout, and then enters another siding. And control accessories such as turning on a freight station for a minute or so while the train is stopped. And slow down the train as it crosses a curved trestle, and turn off the volume when the train enters a tunnel (and then turn it on again as it emerges.)
My goal is to have the system running up to 7 trains simultaneously on more-or-less random routes. The trains will stop in stations, ring their bell, blow their whistle, make announcements, and move out again.
I've done all kinds of proof-of-concept tests, and have written a lot of the code and algorithms, but I'm still quite a ways off from being able to put all the pieces together and crossing my fingers ;-)
My challenge at the moment is that not all of the Legacy commands seem to work exactly as documented in the Lionel spec. For example, I can increase the RPMs of a diesel loco while it is standing still, but as soon as it's moving if I send it a command to increase the RPMs, it blows the horn. There are a lot of commands that work when the loco is stationary but blow the horn when the engine is moving. I'm going to have to analyze the output of the CAB 2 controller and compare it to the signals that I'm sending via my Arduino.
The strength of the Arduinos is that they are easy to program, there is a TON of hardware that will work with them (sensors, motors, communication, audio, etc.), they have tons of inputs and outputs (digital, PWM, serial, I2C, and SPI) and everything is very inexpensive. The range of sensors that you can buy cheaply is staggering, and most are very easy to use.
Arduino microcontrollers are best suited to control applications where your project interacts with the real world. Many other small systems such as Raspberry Pi have a lot more horsepower for crunching numbers, displaying graphics, etc. -- but tend not to have the I/O strength of Arduino. For my project, I need a lot of inputs and outputs, and although the logic is rather complex, it doesn't really require much horsepower or memory, especially since I'm splitting the load among half a dozen Arduinos (they communicate with each other via an RS485 data bus.)
For a simpler project, you could easily put together an Arduino with a bank of relays and use it to control the turnouts on your layout. I'm using Atlas #57 control boxes, and my Arduino simply monitors all of the boxes until it sees a button pressed, at which time it closes a pair of relay contacts for a fraction of a second to throw the switch machine. I'm using relays that are sold on eBay on boards of 1, 2, 4, 8, and even 16 relays per board. The ones I use only cost around $1/relay, and use a separate power supply for the relay coils -- so the outputs of the Arduino are not overloaded.
Of course you could just let the control button fire the switch machine, but by using an Arduino you can do even more -- such as throw routes with a single button press, or throw switches via your Legacy CAB 2 (the Arduino can decode the commands that the CAB2 spits out, and act upon them such as throw a turnout in this example.) So it's sort of a DIY replacement for a Lionel TMCC switch controller.
Another fun thing would be to watch for an isolated rail section to be tripped, and turn on an accessory and/or play an audio clip and/or blow the locos whistle and have the loco make an announcement.
Those are simple things to get started with, but you can do just about anything you can dream up that performs some task based on some form of input.
If you've read this far, please feel free to share your ideas or ask for help getting started.