Model Railroading: Occupancy detection via IR, with LCD display

Hi everyone,
Just recently discovered this wonderful world of Arduino. I stumbled into it while working on another project using just straight up electronic components to handle all the logic. I'm hoping that this group can give me some guidance for the appropriate Arduino board to buy - the Uno or Mega...

The scenario:
This project will be for model railroading. We use a Helix to traverse from one level to another. A helix is basically a giant spiral that gradually brings a train up or down with each full turn. Our helix has two tracks circling around. Here's picture below to provide a better visual:

Since the helix will be completely hidden from view after scenery turns it into a giant mountain, we'd like a way to tell us the progress of our train as it progresses - namely, what level/turn it is on. A circuit I found online using just electric components achieves this with an IR emitter/detector on each level. When the beam is broken (ie. the train is blocking the signal as it passes through), it turns on an LED mounted somewhere on the outsdie fascia. Successive LEDs will turn on as the train continues and interupts the next signal along the way. LEDs turn off again as soon as the signal is once again detected. Neat little circuit, that would meet our basic needs. I've prototyped it on a breadboard, and it works fine.

The goal:
After learning about the Arduino and it's ability to communicate with other external devices, I'm thinking that using the Arduino to display on an LCD panel would be pretty cool. Something like "Level 2" would be sufficient, "IN: Level 2" would be cool too, to let me know if it's the inner or outer track that was detected (I can control this by only having the IR beam cross one track, and not both at each point). Advanced features could include the ability to cycle through messages on the LCD if two or more trains are traversing the helix at the same time, on same or different tracks. Also, keeping track of the previous detection spot would let me output the direction (Up/Down) of the train. But first, let's just start with the basics...

The potential solution:
I'm thinking that IR emitter/detector pairs, with resistors, wired to the Arduino pins would work. Digital "IN" is fine - all I need is on/off, not an analog value. A sketch on the Arduino would evaluate which level was signalled, and send the appropriate message to the LCD display. I think I can also manage the logic for alternating messages and direction. With 6 1/2 turns of the helix (yes, I know, the diagram only shows 5 levels...), I'd like to have one detection spot per track, per level, which puts me at 12-14 detection spots, depending on final location.

The Questions:
I have not yet bought an Arduino. I was looking at some of the begginer kits to get started, since it provides the LCD screen I'm after. But, I'm stuck on a couple points - which Arduino is the appropriate size - Uno or Mega? Can I get away with Uno? There are 14 digital I/O pins, but I don't know how many would be needed for the LCD output.

Are there certain LCDs that are more appropriate for this type of output?

What else am I missing?

edit: was to change the subject to include "Model Railroading".

Most LCDs need at least 6-7 pins if you drive them directly, however you can get "serial enabled" displays that only need 1 pin.

A Uno has up to 20 IO pins (you can use the analogue pins as digital if you want).

So I think a Uno will do although I'm not familiar with the beginner kits and what LCDs they have.


Thanks Rob for that info. I did a search for some alternate LCS with 1-pin, and also typically seem a little more advanced/flexible in what they can display. This would certainly be an advantage. They cost a bit more, but not outrageously so. I think I'll dive in and by a Uno, plus a 1-2 pin LCD screen!

Is there anything else I should be considering as I start planning this out?

Is there anything else I should be considering as I start planning this out?

Did you ever ask anyone who has just looked at his watch 'what time is it'? Almost invariable they will look at their watch again before answering. That is because, when they looked the first time, they weren't interested in the specific time but rather 'if is it the time that they expected it to be'.

Similarly when you are dealing with a model railroad helix you are mainly interested in 'is the train moving' and 'is it where I expect it to be'. If you use a vertical row of LEDs, not unlike your diagram, you will get a visual readout of where the train is compared to where you expect it to be. If you place the detectors properly you can get them to turn on while blocked by a car and off in the spaces between cars. Thus the LEDs will flash if the train is moving.

I built something like this close to 40 years ago (with discrete components of course) and it is still running. The microprocessor / LCD approach would make an interesting project but the end result will not be as handy to use as the LED version. You will have to read the words on the display and then interpret them rather than just glancing in the general direction of the LEDs to determine what is happening.


Don - interesting reply. I had similar thoughts of "would the basic LEDs without the Arduino be sufficient?". Of course, the answer is "yes they would be", as you just outlined. And maybe I'll still fallback on that solution still - I have all the discrete components I need for that already.

The lure of the LCD solution comes from the challenge of making it work. I'm a programmer by trade, so stuff like this completely captures my interest. And no project carries more motivation than the one that has a interesting and practical outcome and requires lots of learning. Maybe I'm looking too hard for a project in order to start playing with Arduino and it's capabilites. It might be better for me to get a Uno board and just start playing with it, and let a better model railroad electronics scenario present itself in the future...

I think I have to agree, a LED solution is more appropriate. As to what drives the LEDs, you can still use an Arduino to satisfy the need to learn some new technology and if you do you can easily modify the way the LEDs work. Much easier to change some code then redo wiring/logic.

As to whether an Arduino will still be running in 40 years, I wouldn't put money on it :slight_smile:


and let a better model railroad electronics scenario present itself in the future...

I've been tinkering on and off with a DCC decoder (more like a sniffer). It's in assembly language using a state machine with it's output on an 16x2 LCD.


Online searches for model railroading with an Arduino mostly seem to focus on train contol and/or DCC inter-connection. There aren't too many other projects out there. I'm thinking the Arduino could be a good fit for automation of the non-train things - lights in buildings, stop lights, car animation control, especially if there's a way to use random length delay with Arduino.

For Operating sessions, a random delay Arduino could generate unplanned events - track problems (cuts the power?!?) or hot-box detection messages, that get (maybe!) triggered when a train passes through a IR or photodiode detection point...

This could get fun!

A random delay is no problem for the Arduino, at least in the context you are talking about.

Sounds like a lot of fun, I've been a model railway wannabe for 30 years, I built a couple of trestle bridges and some scenery but never took it any further.


Arduino should be able to open up new things. I have never played a model train but I suppose you may want to know the train speed on the track? Arduino can do that easily. With magnetic sensor, you can easily sense speed by attaching two magnets on your train and passing by the sensor. Lots of Hall magnetic sensors are open collector so you can arrange them in a matrix and save on pins. So 16 sensors can be arranged in a 4*4 matrix and only 8 pins are needed. With your current setup, you can modify your photo transistor hookup so its collector is open, hooked to an Arduino output, instead of a 5V. Then you can use UNO and save 8 pins for other fun stuff, like drive an LED bar and an LCD monitor, who said you can't have both, florets? :wink:

8 pins for 16 sensors
3 pins for a bar graph with a couple of shift registers
2-6 pins for a character display
Still a few pins left for future upgrade