Adding Signals to the Test Loop

Tomar Signals

Tomar Signals

With block occupancy detection running on the test loop, it was time  to start experimenting with signals. Automated signaling is an important part of the plan for the L&NC.

Signaling potentially involves a great deal of wiring. It isn’t particularly difficult when done the Arduino way, but it does force you to deal with common capacity issues that come into play whenever you want to control a lot of lights or other kinds of devices.

I think of signals as the simplest form of animation a layout can and should have. Creating a signaling system is a good starting point for developing more complex automation and animation for the layout.

Initially, I bought a couple of Tomar Industries n scale signals to try out something off-the-shelf. These particular ones are nicely made and fully wired with red and green LEDS. A three aspect (red, yellow, green) version is also available.

With two outputs required to power each signal, it became clear that directly powering an entire signal system from a microcontroller would be impractical because there aren’t enough pins to work with. Further, The Tomar signals turned out be wired in the common anode configuration, which had additional implications. Common anode wiring is not unusual in off-the-shelf accessories.

Current Limitations

Arduino boards have design limitations when it comes to powering and controlling external devices. The amount of current an Arduino can source or sink on any one pin is limited to 40 mA, enough to light a couple of LEDS. The ground pins can sink a maximum of 400 mA. Accordingly, an UNO could power a maximum of 10 pins with no more than two 20 mA LEDS on each. The I/O pins cannot handle enough current to run most solenoids, relays or motors.

Common Anode Devices

Common anode devices present further problems because Arduinos are common ground devices. Even through the IO pins can sink current, you can’t switch them into a ground state the way you can switch them into a high voltage state.

Most of us are used to common ground — or common cathode — wiring style to control multiple lights or other electronic objects with a minimum number of wires. There, the positive feeds are isolated from each other so individual devices can be controlled, but they all connect to a common ground.

Common anode wiring is the reverse, where multiple devices share a power feed, but their ground sides are isolated from each other for control. Where resistors are needed to control current, as with LEDS, they are put on the cathode side instead of the anode side.

Extending the Pins

Running signals and other animation to any significant extent requires a strategy to multiply the outputs an Arduino can control in a way that is broadly compatible with available devices. Fortunately, there are readily available components that can significantly extend the I/O and current handling capabilities of an Arduino Board and allow control of common anode devices.

Shift Registers

HC595 Shift Registers (I use the 74HC595 variant) are logic ICs offering a basic way to multiply the digital output pins the Arduino can control. Using just three digital pins, an Arduino can control 8 output pins on the shift register.  Better still multiple shift registers can be serially connected, without any additional connections to the microcontroller, to extend the number of outputs under control to span many shift registers. I’ve previously written about shift registers in the Roundhouse rebuild.

To control a shift register, a byte of memory is needed to represent and manage the state of the register’s 8 pins. Accordingly, the maximum number of outputs you can control in a single chain of shift registers is primarily limited by the amount of memory available for managing them.

Consider, though, that a 100 bytes of memory allows you to control 800 digital outputs using just three Arduino pins. Let that sink in for a minute.

Shift registers are serial input, parallel output devices; the Arduino writes the bits serially, then all connected registers output on all data pins at the same time when the write is finished. Shift register outputs maintain their state–on or off–indefinitely until changed.

Darlington Drivers

Another basic tool is a ULN2803APG Darlington Driver, an IC that can switch higher voltages and higher current than an Arduino or shift register can handle. These are current sinking transistor devices, using NPN Darlington pairs; the addition of internal clamping diodes allow them to handle inductive loads such as relays, solenoids and motor driver applications like running unipolar stepper motors. LEDS and incandescent lights work well in common anode configuration controlled through a darlington driver.

Darlingtons allow a logic system (the microcontroller and attached Shift Registers) to control a set of outputs that are powered independently. So, for example, a 5 volt logic system can switch a 12 volt load (up to 50 volt max).  Very useful, yes? For current up to 500 mA per channel, Darlington Drivers can be a viable alternative to expensive relays.

The Good

An HC595 Shift Register plus a Darlington Driver extends the number of digital outputs a single Arduino board can control, using a common anode wiring solution that can handle virtually any kind of layout animation or control device. Using using Shift Register/Darlington Driver pairs and going to common anode wiring as my standard makes all connection and access methods uniform across a variety of devices.

The Bad and the Ugly

In theory, you just connect the output of the shift register to the corresponding inputs of the darlington driver, connect the darlington outputs to your devices, and you are good to go. Trouble is, the chip designers didn’t get the memo on that! The chips are a little difficult to interconnect: you can’t place the chips side by side and have respective outputs and inputs facing each other in the correct order. In fact, the HC595 connections are arranged a little oddly, requiring at least some connections between it and the darlington to cross over each other no matter what.

My first try was the roundhouse controller board. My problem then was trying to run some low voltage incandescent bulbs from 3.3 volt power. The darlington driver allowed me to do that with the 5 volt shift register.

Roundhouse Controller with an Uno

Roundhouse Controller with an Uno

See all those green jumper wires? That was my first solution to the interconnect problem on a single layer board; it works but it is awkward, bulky and hard to replicate. The additional interface for the addressable LEDS further complicates the board.

For signals on the test loop, I decided to try to shrink the board size, incorporate the necessary resistors (they are on a separate board in the roundhouse) and take a two sided approach using my favorite two sided prototyping boards.

Node Prototype 2

Node Prototype 2

As I was planning to record the block occupancy demo, I decided I needed more signals on the test loop to show the block occupancy system in action. I still had four available outputs on the board running the two Tomar signals– except those could not help me with a signal on the other side of the layout [the signals all have short lengths of thin magnet wire].

The HC595 can connect to another shift register serially, but I had not provisioned that on the boards built so far. It takes three connections to link to the next shift register: the two shared timing lines and the data output from the shift register.

Time to build board #3.

Node Prototype 3

Node Prototype 3

The board works fine. But creating these boards with prototyping materials is painful because of the number of jumpers to route and connections to make. As useful as these were going to be, it was going to take a long time to churn out a lot of them accurately. On the L&NC I expect to be controlling hundreds of lights and other devices around the layout. There had to be a better way.

Duino Nodes, Type A, Version 1

I was using fritzing, my favorite circuit design tool, to work on the circuit design for the next board and it became obvious that what I really needed to do was have a printed circuit board produced to my specs. Since I would need several boards for the test loop alone, and I was only just getting going, a small trial run of boards made sense.

I’m glad I did.  Here is the first version of what I call a Type A Duino Node.

Duino Node Type A

Duino Node Type A

These are double sided pc boards, pre-drilled and ready for components, with copper ground fill on both sides for emf control. It takes about 10 minutes to assemble a board for use. The prototypes took over an hour each to build, so the practical time savings for the dozens I’ll need on the L&NC is substantial.

They are 88 mm x 52mm; about 30% bigger than the smallest prototype I built. There are a couple of reasons for that: first, the board has Arduino-style mounting holes arranged to facilitate board stacking. Second, since these boards will run lights and other devices with varying current limits. generous space is available to mount an appropriate resistor for each cathode. A jumper can be used if a resistor is not needed, as might be the case when running a relay, motor or solenoid through a position.

On the right side are three control connectors: power, serial in and and serial out. When stacked, only short three wire jumpers are needed to chain from one board to the next. A terminal block is mounted on the opposite, output side of the board. There are nine positions: the common anode (power) plus eight switchable cathodes.


There are four boards deployed on the test loop. One is dedicated to the two Tomar signals above.

Another board runs the dual signals below. The top searchlight is three aspect (red, yellow, green) and the bottom is two aspect (red, green), requiring a total of 5 outputs.

Dual Searchlight Signals, Scratch Made with BLMA Signal Heads.

Dual Searchlight Signals, Scratch Made with BLMA Signal Heads.

The last two Duino Nodes are used together for the station / signal complex.

The Station, and Signal #5

The Station, and Signal #5

The signal is three aspect (red, green, yellow). The station has a total of 8 individually switchable LEDS for internal lighting.  You may notice that the two sections of the depot have distinctly different lighting: the passenger station side has warmer, incandescent lighting (achieved with a mix of led colors); and the freight side has a cooler fluorescent lighting style (cool white LEDS).

One node is for the station signal that connects via four strands of magnet wire.

Duino Node controlling Station Signal

Duino Node controlling Station Signal

The second node mounts on top of the first, and it controls the Station internal lighting. The bottom node receives the incoming serial connection from elsewhere; then a cable connects the bottom serial out with the top serial in. There is no limit to the number of boards that can be chained and/or stacked together.

The Duino node for station lighting is stacked on top another node that runs the signal.

The Duino node for station lighting is stacked on top another node that runs the signal.

Here is a view of the test loop from below with all the Duino nodes in place.

Test loop from below.

Test loop from below.

It may be hard to tell, but the overall effect of using the Duino nodes is to simplify and compartmentalize wiring.

Using the Nodes

The real advantage of this system comes from adopting a uniform addressing system that makes it easy to randomly access and change any element on any node at any time.  I’ll go into that in the next post.


Rebuilding & Lighting a Roundhouse

One of the casualties of 15+ years of moving box storage was a Walthers (Heljan) Union City Roundhouse with 6 bays. No longer in the catalog, this was a really nice brick structure with a little extra decorative masonry, as might have been built in a prosperous town in the early 20th century. The “modern” roundhouse models widely available today are more shed-like and (to my mind, anyway) less elegant.

Roundhouse in pieces

Roundhouse in pieces

The damage could have been a lot worse; mostly it came apart at glue joints. A little breakage, but not much. I originally built this twenty years ago as an exterior model; no interior lighting or details. It was nicely enough colored that it worked well unpainted (though I intended to get to that…. some day). No anti-crazing glue was available in those days, so the windows which look fine on the outside look atrocious on the inside.

Decisions, Decisions

The model did not have the common decency to completely disassemble itself, which would have made this much easier, so I had some choices to make. In contrast to the glue joints that failed, the rest were showing no signs of giving up easily.

First and most obvious was whether to rebuild the 6th bay, since most major pieces were intact. For the sake of the space available on the L&NC, cutting back to 5 bays makes sense without diminishing the impact of this model. I could have gone to 4, but the broken frame for the 5th bay door presented a nice weathering opportunity, which we’ll see later.

Secondly, what kind of lighting and how? I was thinking incandescent, and hanging lights would be authentic, so some sort of hanging lamp with an industrial style shade seemed like a good idea. I found both led and incandescent options; I decided to try the incandescent type.

Getting Started

Removing the floor turned out to be the easiest way to open up the model, so I decided to reconstruct the model with a solid top structure that is removable from a separate base. Putting aside the floor, I reassembled the top structure, leaving one roof section off where I planned to route wiring.

Main structure, partly reassembled

Main structure, partly reassembled

That decision, along with the intended orientation on the L&NC, spawned a few other choices.  Now, when in operation, the interior will be viewable primarily through the doors and secondarily through the windows and skylights. Since the most open sight line will be through the doors toward the back, I decided to attempt some improvement of interior finish along the back wall.

Painted Window Castings

Painted Interior Window Castings

I pried off the clear styrene, which was as difficult as I would have expected, requiring some grinding and sanding to get rid of stubborn bits holding on to the green window part.  Then I painted the window part brick, leaving muntins and a thin window frame green. Having done the back wall I re-evaluated the other sight lines and concluded that removing the glazing elsewhere was probably not worth the trouble (I’ll keep that option open for later).

Light coming through simulated glass.

Light coming through simulated glass.

Since the glazing was gone, I decided to try using Testors Clear Parts Cement & Window Maker to make ‘glass’ in one pair of rear windows. It was easy enough to do if you follow the instructions, and the effect is interesting.  I probably used a little too much, but the material seems to have a lens effect in windows this small. This simulates older glass nicely, but does not create a “see-through” window (for purposes of viewing the interior). The way the Roundhouse will be oriented on the L&NC, the back window will face a blocked (by the furnace) area, so you will not be able to directly look through these windows in any case. So I think I will do the rest of the rear windows the same way.

Paint Cheapskate

Model paint is notoriously expensive (over $5 per oz, discounted) and, frankly, nothing special beyond formulating specific colors that duplicate prototype colors. In this respect I’m lucky there is no convenient hobby shop here; that has forced me to look to other solutions which, to my delight, are vastly cheaper.

Liquitex BASIC Acrylic Paint (available at all major art/craft store and on Amazon), at $5 per 4 oz tube (cheaper in even larger quantities, or sets) is a good deal.  It is available in a wide range of standard artists colors that are easily mixed to create any color you want (just keep track of the formula!). These are formulated for general artist use so they are thicker than standard model paints. I mix small amounts of paint with acrylic thinners to get whatever consistency I want.

My brick color is a simple mix of 50%Red Oxide and 50% Burnt Umber. My color for light colored mortar, masonry, stone and concrete is Titanium White with 5% Yellow and 5% Grey (a 50% Grey) – basically a dab of each into a larger amount of white.

Installing Lights, Round 1

I found some Miniatronics parts, counter-intuitively called “Lamp Shade with Bulb,” that I thought would make good hanging lamps for the interior, so I bought 10 of them from Hobbylink.

Miniatronics 'Lamp Shade with Bulb"

Miniatronics ‘Lamp Shade with Bulb”

Here two are mounted in 1/8″ Styrene u-channel that has been painted Floquil Weathered Black (from my limited collection of old paints) to match the interior girders. To size them, I studied the interior clearances relative to locomotives and realized that clearance was limited in the tall section, and non-existent in the shorter fore and aft bay sections.

Hanging Lamps in Bay 1

Hanging Lamps in Bay 1

My feeling at that point was these lamps were not suitable for the short sections, since they would not be visible mounted up against the ceiling. That feeling increased after mounting and lighting the first pair.

Miniatronix Lamp Shade with Lamp - Lit

Miniatronix Lamp Shade with Lamp – Lit


I guess I should not have expected much from a 1.5 volt 30mA lamp.  Still, I’d hoped it would cast more light than that! As a decorative lamp it works fine at N scale – you get little peaks of them if you look in and they seem right. For casting light on the broader scene, even if I doubled up on them, another solution is needed.

Addressable LEDS

I’d already been working with Addressable RGB LED strips as a solution to bringing light to the layout, and it occurred to me that adding ALEDS as a hidden light source would allow me to more fully light up the interior. So that is what I did.

RGB LEDS for General Lighting

RGB LEDS for General Lighting

The individual pads are cut from a 5 meter strip and wired together with 30 GA wire. As you can see from the picture of the completed interior below, there are 10 of them with addresses 0 to 9.

Soldering Addressable LEDS

Soldering Addressable LEDS

To solder the very thin wire to the pads, I taped the leads down and slipped the pads underneath. That was more than stable enough to make the soldering fairly easy.  This particular LED is #0, so the left hand leads are heavier (22ga) for incoming power and data (for durability and handling), and the right hand leads out to the rest of the strand.

I fabricated the strand in two halves with 5 LEDS each, soldering leads from the two halves together during installation. Each half strand had to be carefully threaded through the girders.  I did break – and repair – a couple of connections the first time I tried.  After I got them threaded successfully, I glued the pads down to the styrene roof with dabs of Liquid Nails for Projects (low VOC, foam safe). You can bet I tested the  lights before gluing them down!

Completed Roundhouse, from below

Completed Roundhouse, from below

The LED wiring is simple and efficient – 1 connection to a digital pin on the Arduino, plus 1 wire each for power and ground.  The incandescent lamps were more complicated since I had no intention of giving over 10 pins on the Arduino. Further, turning them on and off individually was not necessary, so I decided to run them in “bay pairs.” Unfortunately, the 60 mA draw of a pair of these is more than you want on an Arduino pin, so that meant some sort of relay or transistor would be necessary to switch the current.

 A Shift Register and a Darlington Array

Current isn’t the only problem: there aren’t enough digital pins on an UNO to control everything I have planned.  So a pin preservation strategy is called for.

I decided to use a 74HC595 serial-in-parallel-out shift register. One data pin plus two timing pins (total of 3 pins) allow an Arduino to control 8 digital outputs; additional shift registers can be wired in series to extend the total number of outputs available without additional Arduino pins. The parallel output of these chips means that after the Arduino sends instruction bits serially, all the outputs are turned on or off at the same time (parallel output), a useful property for animation and lighting control.

Because of the higher current (and also different voltage) of the lamps, I put a UNL2803 darlington array — a transistor array that can sink high current — between the shift register and the lights. The only downside of a darlington is some current loss.

Both chips are inexpensive, running about $.60 each in small quantities at digikey.  Now that I’ve worked with them I’d say they are very useful basic parts for the Arduino enthusiast.

Power Distribution to Lamps

Power Distribution to Lamps

I fabricated a little circuit board for the roundhouse, to join the “bay pairs” together and provide a 1/8 watt resistor for each lamp to be able to run at 3.3v. The darlington array sinks current rather than sourcing it, so the circuit is a common anode (common power) with the resistors and control on the ground side.  Works fine. The circuit board was cut from a standard Radio Shack pre-etched PC board, and fits into the wiring space in the back of the Roundhouse.

I fabricated another board–version 1 of what will become a standard, chainable shift register board for layout control (but about half the size of this one) —  to be mounted under the roundhouse base, it interconnects the two ICs, taps into layout power, connects to an Arduino and connects to the structure above. The board uses +5v power for logic and LEDs, and +3.3 for distribution to the incandescent lamps.

Roundhouse Controller with an Uno

Roundhouse Controller with an Uno

The roundhouse board has an unused connector that would allow 3 more +3.3v lights to be added. I’ll probably use that capacity for some lighting outside the roundhouse structure when it is mounted on the layout, but I haven’t decided anything yet. That, by  they way, is part of the essential elegance of the Arduino way; so long as a connection pin is available, adding more lights or functionality is as easy plugging things in and modifying your software to use them.

Here is a video tour of the project and demonstration Roundhouse lighting!

The sketch loaded on the Uno is different enough from previous examples, that I will cover it in Roundhouse Rebuild Part 2.