All aboard!

I really like Arduino. This simple thing allows you to create amazing designs. By combining several microcontrollers in a single system, the weak capabilities of one Arduino, in comparison with computers, allow to obtain absolute software flexibility and power in real world.

The illustration below shows the possibilities and general rules of the project in railway layouts. But you can apply these principles in your other developments.

As you can see, this project provides all the needs for yours layout. And this is only an example of the possibilities of URB, programming a chain of blocks yourself you can add their functions as you need. You will also benefit from the simple command protocol.

The bus uses only four wires, two of which are used to supply 5 volts to Arduinos and railway peripheries. By the rest of the wires are transmitted data, since it is the I2C bus.

You can connect any peripheral devices to the nearest URB, this saves you from a lot of wires, allows you to keep the simple and understandable logic of the circuit layout. Also, such a solution makes it easy to change connections while modernize the layout. You can even install empty URBs by combining them into a bus, and then install Arduino Nano in them when you need to connect a new peripheral. You can cut the wires of the bus and insert another URB into the gap.

Separating the railway lines into segments, and connecting motor-drivers to them or blocking them using a relay, it is possible to achieve separate control of the trains. And yes, this is the simplest principle of DC, but you can use all the possibilities of Arduino to build interlockings and other automatics of motion.

Universal solution

I repeat :), all URB boards are the same, their specialization is provided by sketches and the details that you install in to connectors. Also, starting with the URB version 2.6, reconfiguration is provided by jumpers on the board (see URB Branch).
Examples for automate layout, prototyping and sketces are regularly added to Arduino Central.

Direct plug sensors for automation

To automate the movement of trains you need sensors. I used Hall sensors as train detector triggers on the line. In comparison with other sensors, it has the advantage of a trigger "dot". The second element – the magnet – is attached to any metal part underside of a car or a locomotive (for example, to the fastening screw, etc.). I recommend small cylinder neodymium rare earth magnets. By changing their number, you can adjust the distance between the magnet on the car and the sensor on the rails. I have reliable operation at distances of 1-5 mm. This allows you to correctly and accurately set the pickup location relative to the train and relative to the location on the layout, as well as easily adjust it by moving the magnets.

You can place a magnet on any car or locomotive, at the beginning, middle or end of the train, thus adjusting the stopping place to within a centimeter. Hall sensors are small, if they are neatly put between the rails, then they are like real AWS inductor.

To Arduino NANO it is possible to connect up to 18 Hall sensors. But this is a standalone solution, you can not transfer data to other layout's devices . URB solves this problem elegantly. You can connect the sensors to any URB and then transmit their signals to the communication station via the I2C bus. Starting with the URB version 2.6 there is a possibility of direct, together with power, three-wire sensors connection (see URB Branch).

Connecting servos, relayes and so one

Not only for railway layouts. Place the URB wherever you need and connect the servos and relays to it. Plus are 5 outputs controlled from the Arduino contacts with a current of up to 0.5 amperes per each (ULN2003 installed). The peculiarity of the URB is the switching-off of power from the servo by the command of Arduino, which eliminates the heating and prolongs the life of the servodrives.

The standard serial bus or bluetooth allows remote monitoring. In the mode without ULN2003 it is possible to connect classical Arduino sensors of temperature, humidity and alarm, for example, for a wireless weather station.

Software solution and design of the switch-mashines see to the Arduino Central. Also, if you want to make a junction-motor at servo yourself, then there is a detailed video instruction on my YouTube channel.

Smart railway signals

Complex semaphore systems with URB are not a problem. You can connect up to 8 two-lens semaphores to one unit. The logic of their behavior is completely dependent on your idea. For example, if you connect sensors, you can make an autonomous Control Box. If you connect blocks to each other via I2C bus, you will receive a branched signal system throughout the layout. Also, you can add or remove signals at any time, change the behavior of the signals simply by updating the sketches of a particular URB. It is very easy to understand the principle of building a sensor-arduino system at the example of a speedometer.

More voltage devices

Starting from version the board 2.7, you can connect devices with a voltage of up to 50 volts. In this case, you can connect directly the LED 12-volt stripes, and manage them on six channels.

For example, if you install the bluetooth module, it's easy to remotely control three dimming LED-types without additional details (see also spec ULN 2003A). If you have an even more powerful load, that is, a two-channel relay.

URB to PC connection
station control panel
Control panel
lights on  layout
Lighting layout
railway crossing barrier gear
Railway crossing
Light signals

Wireless communication

An interesting point, there are a lot of good materials on the Internet about the design on the basis of Arduino. Much smaller programs for Android using Bluetooth for control. And, apart from simple examples, there are practically no posts how to tie together Android and Arduino.
The problem in the rules of data transmission. For this purpose, a number of good protocols have been invented, for example the FIRMATA, which is included in the Arduino IDE collection of examples, but it is for this project that it is possible to make the protocol simpler and more flexible.

I present you a simple protocol for controlling trains and the layout itself. It is so simple that for I described its principle on the page for beginners, therefore, you will not be difficult to independently modify and expand it. My applications published on Google Play Console use this protocol, passing commands through the serial port to URB, and in this case it's also is the Bluetooth channel. An interesting feature is the layout's control using the protocol via the computer terminal, you can also write your own interface for computer control using the language environment Processing is are common in the Arduino community.

To slightly beat the adherents of the DDC I say next: If you look at the picture carefully, you if will have this project to admit that you have enough the is channels for controls. And this opportunity is realized practically for free, and thus as a bonus you get an exciting opportunity to compete in the management of one locomotive by two players. And such pleasure will not give you any of the existing solutions. It's like going back with a friend to children's games, just try!

Why Bluetooth?

The best technology for managing the layout is Wi –Fi. Since this immediately gives IP addressing, a high-speed duplex communication channels with broadcasting. Also it is reliable and well-developed network software solutions, and a large selection of equipment for building networks. I have another project based on Wi –Fi, and in the future, perhaps I will publish it on this site.

Bluetooth was originally conceived by developers to connect devices as to the point-to-point, and this technology works very poorly when building routing. But it is connection software invisible – it is enough to establish a connection between two devices and you get a virtual wireless analogue of Rx-Tx cable. And this outweighs the shortcomings described above.

Testing from a Computer

Connecting a computer directly to URB is a very important feature. You can debug your sketches on time on the layout, or test the circuits separately by functional blocks.

Any modellers encountered difficulties in creating electronics for a layout. This is a lot of wires, the complexity of connecting devices and their compatibility among themselves, and most importantly the inability to add or change something in the finished layout without dramatic changes in the wiring. These shortcomings are absent in the URB concept. All wiring between the blocks is made up of four wires. For example, if you need to put a few new junctions or sensors or streetlights on the layout, you just cut the four-wire bus in the nearest place and insert another URB. It remains only to upload the sketch, and your newly installed pieces are immediately integrated into the layout. At any time you can reprogram already installed URBs directly on a layout, you just need to leave the opportunity to reach it with a mini-USB cable. This way you can change the control or setting of any layout's devices, and replace it if necessary.


When connecting the cable USB Arduino located on the board receives 5 volt power through the cable directly from the computer (see +5V AUTO SELECTOR on MBR0520 in the Arduino NANO scheme).
If you do not want to broke the USB port of your computer, BEFORE connect the USB cable power up the layout from its power source!

Another plus is the ability to experiment with each URB independently of others, and it's still an easy way to look for possible malfunctions in electrical parts on layout. It is also possible to assemble URBs with peripheral modules separately on the table. You'll tune the prototype and then will transfer it to the layout. This allows you to realize your ideas much faster.

Schemes with low power, for example for testing "on the table" or uploading sketches into a stand-alone URB, you can connect directly to the USB port.

Hardware controllers

Android app ArduinoTrain BtControl is enough to control all trains and the layout itself. But this does not exclude the management of the layout with a real panel consists of familiar buttons and indicators. Moreover, the concept of URB allows you to manage railway devices from both the phone and the hardware console simultaneously.

You can use ready-made push-button kits for Arduino or design them yourself. Examples are given in Arduino Central.

I2C bus and PCF 8574

All URBs can be —Āombined by the I2C bus. The software implementation is provided by the standard library of Arduino named Wire.

There are, many simple and cheap devices for the I2C bus. If you just need to control on / off, for example, individual windows in the house, then it's logical to use them. On chip PCF8574 there is a ready board for display control – 16x2 LCD Backpack Module – I2C expansion for LCD, adding the current amplifier to it, you get an 8-channel controller. Ways of making, snippets sketch for the construct it here.

Power supply

The project principled divided the power into two branches, one for moving locomotives, the second for electronics and devices on the layout. Thus, with short circuits on rails and other troubles with trains, the layout control will not be affected.

When using Arduino NANO obvious choice voltage for electronics is 5 volts. L298 allows you to use for your locomotives the required supply voltage (12 or 18V), and in the sketch you can change the code PWM to adjust the characteristics of the dynamics.

You can use power supplies from old laptops, they are powerful enough and give out about 17V. The ideal solution can be a computer power supply, it immediately gives out voltges both 5 and 12V with protection. Also included in the set of railways are usually 9-12V power supplies.

Also you can apply two standard power supplies, to 5V and 12V, by combining their negative wires together.

The required current can be calculated using Ohm's law. In any case, the output current must be at least 0.5 Ampere. For a power supply from a computer, it does not matter, its output currents are much greater.