Thursday, December 6, 2007

Uses for microcontrollers in model railroad electronics

Microcontrollers are fascinating little devices that have multiple uses for model railroads. I've used them several times -- perhaps in future posts I will drill down to specific how-to's, but for now I'd like to just present a few ideas in hopes of stimulating the creative juices.

First, if you've never used a microcontroller, know that they are not nearly as daunting as you might think. A basic grounding in electronic theory is helpful, but even without this you can buy educational packages that include both the devices and learning tools. In fact, the package I would recommend for most beginners is based on a microcontroller system called the BASIC Stamp, and is available at Radio Shack for $80. This package includes a great how-to book, programming software, and lots of extra electronic parts you can use. (A word about the BASIC Stamp system: it rates low in terms of cost-effectiveness, but high in terms of learning and ease of programming.)

On to the applications:

Custom throttles

Microcontrollers excel at timed, switched, or pulsed electrical signals, so they are a natural bridge between a knob and a sophisticated pulsed-modulated drive signal for locomotives. Or, forget about one knob, and use some combination of switches, sensors, or other electronic components to control the movement of trains.

Animated/timed/sequenced lights or LEDs

A flashing "neon" sign, "crawling" light patterns you see around marquees, arc welders, campfires, train signals, traffic signals, etc.

Block detection

Connect some basic block detection circuitry to a microcontroller, and now the position (and, in DC systems, direction) of your train on the tracks can control signals, crossing gates, or ...

Automatic turnouts

This is not for everyone, but the first layout I built used a microcontroller between block detection circuitry and the magnetic coils on remote turnouts. An example: imagine the mainline approach to a turnout is A, the mainline route after the turnout is B, and the diverging route is C. If a train goes from A into the turnout without stopping, the system makes sure it will continue on to B. However, if the train comes to a stop in A but resumes movement in less than 3 seconds, the turnout is thrown and the train will proceed to C.

In DC (not DCC) systems, you can also differentiate based on the train's direction of travel, or use this in tandem with the timing of starts and stops to intelligently control the turnouts.

You can begin to see the possibilities here; the microcontrolled turnouts can replace a big part of a control panel. Of course, there are limitations to this approach depending on the degree of prototypical operation you wish to retain, but it's intriguing to consider the possibilities.

Automatic uncoupling

Similar to the above, but substitute the coil of an electromagnetic uncoupling magnet for the turnout coils, and now your train motion (again, based on train position and/or direction) can be used to trigger uncoupling events.

Automatic nighttime

Use the microcontroller with a photoresistor (or several of them) to turn on the after-dark lights on your layout, based on the ambient level of light in the room (i.e. whether or not the room lights are turned on), or based on a clock.

Complex animation

Combine your microcontroller with a servo motor, and the animated elements on your layout are no longer limited to simple circular or back-and-forth motion. The BASIC Stamp package described earlier includes one servo motor that can turn 180 degrees end to end; there are also motors available that can turn continuously.


ted said...

Thanks Gabriel, I was looking for something besides a traffic signal application to use uCs. Your list is plenty!- ted

LED signs said...

I just read through the entire article of yours and it was quite good. This is a great article thanks for sharing this informative information

Sharon Clark said...

I just found your article and its very informative. This will help my current project on simple open sign for my cousin.

Thank you so much.