Android app Arduino Train Garden

Bluetooth phone app train control
for Garden Railways

  • Any number of controlled locomotives
  • 20-x speed thrust control
  • Extended lights and signals control
  • Unique function – a wireless decoupling system on loco
  • No restrictions! You can modify this system for any construction of locomotives or use it in your control system
  • Universal button for servicing loco devices (for example, cabin lighting, start / stop of the snow removal rotor or steam generator and other things)
  • Simple protocol (API) with extensibility

Any options — from the simple to the complex


   See also very good YouTube Ge Rik channel about narrow gauge railways

Examples of turnkey solutions

  Simple and easy start

  More loco power


To forums critics   

Your project   

Simple and easy start

The simplest system consists of any Arduino board, a Bluetooth module and any Motor-driver with a voltage corresponding to the battery and the current consumed by the DC motor. As an example, I will use the standard parts of the project's URB: Arduino NANO, bluetooth module HC-05 and L298N. All these details together cost less than 10 US dollars.

Your locomotive battery should have a voltage of between 9 and 12 volts. If you take voltage from the rails, then you need to add a step-down DC-DC converter to the Arduino's power supply circuit and a diode with a capacitor of significant capacitance (about 1000 μF).

Train on battery

Small diesel garden railway loco
Simple circuit

The elementary circuit for using Arduino Garden Train App

Sketch for Arduino NANO

The sketch for Arduino is based on the example of Arduino IDE named SerialEvent. A four-character command parsing from the application is a block of code – if (stringComplete) { ... }. After which you can program any reaction of the microcontroller Atmega to these commands. Simple command protocol can be extended according to your requirements. Currently, the application has implemented 10 control commands and 20 commands for setting the motor rotation speed. Upload sketch to Arduino NANO.

After connecting via the Bluetooth, you can view these commands in serial terminal on the Arduino IDE of your computer with the USB cable connected.

Simple sketch for Garden Train

Connect App to different locomotives

Push Bluetooth Icon

Choose the loco by MAC address

Connect established

Push icon again for disconnecting, and reconnect to another loco

You can install this solution on multiple locomotives. The bluetooth connections in this project work as point-to-point without routing. Since each bluetooth module included in this scheme has its own unique MAC address, by switching these addresses in the application you can manage them all. Also, you and your friends can manage simultaneously multiple trains by installing the application on multiple phones.

More features. Start and disconnect commands.

My application, when successfully connected to the locomotive, sends the command «999z» to Arduino, and when it is disconnected, the command «888z» is also sent. Let's add a code to the sketch that will flash the floodlights of locomotive when it is successfully connected and turn off all the lights when it is turned off. Accordingly, you need to add LEDs to the circuit and add the code for manage control them from the application.

Since the main idea of my project is that you can completely rewrite the sketch code and come up with and implement your functions and ideas, these commands can also be used to turn on the engine sound of a locomotive or steam generator at connecting. And switching off them when disconnecting bluetooth from loco. You can also override the purpose of all other commands.

Buttons and features App Garden Train

More loco power

The maximum current from one pin Arduino is less than 40mA. In order for spotlights on a large-sized locomotive to be realistic, powerful LEDs with a current of more than 200 mA are needed, and large currents are also needed to control the servo drive. Therefore, it is logical to add a high current booster to the circuit. It can be done on transistors, but I prefer to use chips like Darlington arrays, etc.

If you are going to use a load with 5 volt voltage (for example, servos), then you also need to add a stepdown DC-DC converter to the circuit. And accordingly, slightly change the power scheme for the Arduino board. It is also very useful if you are going to add sound and many other accessories for Arduino (sensors, actuators, etc.)

In this sketch, added function via pressing a «decoupling» button for the processl of the train uncoupling mechanism. The servo lowers the trailer for 2 seconds and then returns the hitch hook to its original position. Like all the other examples, you can change all the parameters of the mechanism and the code of the sketch for your coupling mechanism. You can also add any blinking or fading effects to the code of the spotlights (see the URB project).

More Power sketch


The Arduino Garden Train app is a wireless remote control. You can use this application with any type of equipment placed on your locomotive. This can be not only a system based on classic Arduino boards. You only need to create a Bluetooth channel between the locomotive and the phone – simple four-character commands sent by the application can be processed by any microcontroller. For example, you can use ESP32, with integrated Bluetooth module and a large amount of memory. Or STM microcontrollers popular series of AVR.

Project MCUs

In my opinion, I provided all the necessary commands, but if you need more, send me a message. The application also implemented feedback. As an example of this type of functionality, you can see the online status of the locomotive accumulator when it is BT connected. Examples of this and other functions are given in this chapter with the code for Arduino as a starting point.

State of loco battery

State of battery

After the connection is established, it is enough to send the battery status from Arduino using a simple code:

byte data;

Where data is a variable with a value from 0 to 100, which can be produced by reading and mapping from any analog input of the microcontroller voltage values when using a bridge resistive circuit.

Voltage measuring

Without this data, the icon remains gray. If the data value is less than 40, then the icon turns yellow, if less than 20, it turns pink.

Setting PWM frequency on 120Hz

By default, the PWM sampling rate for Arduino is about 500 Hz. If you lower it to 120 Hz, the power of the electric motor at low revs increases, the unpleasant high-frequency squeak of the motor armature also decreases.

In all circuits presented above, the engine is controlled from pin 9 of Arduino (Timer 1). To decrease PWM to 120Hz needs add to the void setup () code block a line:

TCCR1B = TCCR1B & B11111000 | B00000100;

If the circuit includes a servo, then you need to replace the standard Servo.h library with an alternative – for example ServoTimer2.h


The values of all speeds are defined in the sketch, so you can use a popular solution based on DFPlayer Mini MP3 Player Module MP3 For Arduino. Or use ESP32 chip capabilities by adding an amplifier.

See also popular blog: Peckforton Light Railway.

Voltage measuring

To critics:

Unfortunately, these guys are following me from the very beginning of the project. In general, they are not bad, just overly self-confident, not curiosity and very conservative. And now, I wrote a new application and immediately received several negatives feedbacks from them. The problem is not that these comments are project flaws, but that this is an absolutely wrong opinion of these commentators. And there are comprehensive answers to all their questions both on the site and on my YouTube channel and in the many resources of the network dedicated to Arduino, but ...

The only way to dispel this nonsense is to repeat and repeat the correct answers, and maybe then it will come to them that the world is somewhat more than their idea of him :)


The first statement: "This project does not suit me, I need more than 12 volts to motor on my loco."

The counter question is: how does a microcontroller similar to Arduino manage the motor of your washing machine with much more than 12 volts?

That is, the voltage and current for the motor is determined by the type of "amplifier" placed between the microcontroller and the motor. As such an "amplifier" in my project, as in all systems based on Arduino, a motor-driver is used. In the examples above, a motor driver based on the L298 chip is used. You can also use many others drivers in your development, just change the sketch code for them.

So there are no restrictions on voltage and current strength. For example, by connecting two channels of the motor-driver module L298N in parallel, you can control the load with a voltage of up to 50 V and a current of up to 4 A. I have not seen any locomotives for model railways with engines of such power!


Second:"One of the down sides is only 10 steps for control. Do you know if this can be changed later on to a much greater number, like 100?"

Are you serious? It's funny that this is written by a person using a DCC decoder with 14-speed!

And pay attention to the application Arduino Garden Train use 20-speeds Protocol. This means that at a voltage up to 20 V and a linear scale of the velocity distribution, the "step of voltage" change will be equal to 1 V. I understand that the author does not have to know the theory of electric motors, but if he was not too lazy to see the graph of the correspondence between voltage and engine speed under load, he would have learned a lot of new things for himself. For small collector DC motors (respectively, with a small weight of the motor armature) the minimum threshold of change in revolutions under load is about 0.3 V on the linear part of the graph, and about 1 V at low revs. Moreover, the higher the voltage for which the motor is designed, the greater this value.That is, it makes no sense to use 100 or even 50 speeds, it will not affect the feeling of driving the train.

The linearity parameter has a much greater meaning; it is a completely different way to enjoy your locomotive control. And this is exactly what is implemented in the project. You can individually configure each of your locomotives for the application; for this, the project provides a speed table with 255 speed levels. By changing this table, you can rearrange the curvilinear characteristic of your engine to linear (I will tell you a secret that such a table is used in DCC decoders).

And finally the most important thing. It doesn't matter how you control your train – from a wired console, from an analog or digital RC-controller, using a thrust handle or a rotary knob, you immediately feel that the train is lagging on your team. This is a mandatory unpleasant property of any home-made control system, but missing in professional developments. And this is not due to inertia, but with the data stream. When you quickly change the position of the knob on the control console, the amount of data grows exponentially. And if you use 100 speeds, in this case the data flow will become very large and the control system will simply stop responding to your commands. Therefore, professional systems and use the minimum required number of speeds.

Once again, the problem is not that there should be a lot of speeds, but their distribution over the control range.

Motor-driver explanation
DC motor diagramm DC motor diagramm

App vs console

app vs console

Instead of a long and not always successful manufacture of a real console with buttons and throttle rudders, Arduino Train Garden app immediately gives you many advantages:

  • Works right out of the box. You just need to run the program on a smartphone or tablet.
  • Wirelessly. Bluetooth is integrated into any modern Android device.
  • You can use several Android devices for controls sveveral trains, that is, you can play together. Also you can just buy cheap simplest Android-tablets specially for the your model project.
  • Useful app UI specially for railway modellers

No projects is successful if it does not offer a complete and reliable solution. My version offers not only this, but also an almost infinite expansion of your railroad capabilities in building electronics, the lack of restrictions in the implementation of your own ideas. You can update your train and add new features to it by simply updating the firmware of the the Arduino boards, you will not let you lose interest in the future.

Programming a sketch for a project is very simple. Only simple codes and standard Arduino libraries are used. My friend says a great phrase about Arduino: Don’t be afraid of programming, for Arduino programming is like teaching the dog to execute commands.

For the Arduino platform, a very large number of parts are produced: sensors, motor-drivers and etc. Thanks to the competition of the producers, they are very cheap, and you will not have compatibility problems between them and Arduino. The software has been tested by millions of users and is very reliable. And most importantly, thanks to the Arduino community, you will always find the answer to any of your questions. A large number of training materials are also available free.

Your project

You can use this application and equipment not only for the garden railway. You can integrate this system into LEGO trains or any similar.

Share your solutions and I will leave here a link to your website, blog or video.