Make a donation

Donators get access to the extended part of the site + bonus: Arduino Train DNT application.
For experiments and regular updating of the site, I need funds. I also have another project that you will like. If you are interested it, support me via donations.

About Line Apps

Designed by a modeler for modelers

My railway layout controlled via URB

Much more than the Android Apps Line

My applications are not just the remote control of locomotives and junctions on the layout. This is an attempt to change the paradigm of control by model railways, that is, to introduce automation elements and script algorithms into management. The ultimate goal of the project – give the modelers people, in reality, the same incredible opportunities as in modern computer simulations, such as MSTS, Train Simulator, Trainz and others.

There are two unique possibilities in Apps Junior and DUO (DNT) - the AWS modes and SCRIPT buttons. In the future, using to URB, I will gradually add new features to the project itself and to the Applications.

Applications are made with the most concise and user-friendly interface. Using protocol version 2 and changing sketches to URB units, you can reconfigure almost all the elements of the application interface to your other individual layout devices, for example to use the buttons of junctions control that are not used in your layout to execute other commands.

The DEMO application is made to demonstrate the capabilities of the project and is basic in the section for beginners (you can also use Junior and DUO (DNT) applications, since their command system is also based on Protocol 2). The application Arduino Train for Kids 2, made to involve your children in the fascinating world of model railway. You can see how it use on the site Instructables. I have some more interesting ideas, and in the future I will add new gaming applications for the URB project.
All applications are made in such a way that it is possible to control a railway under the control of URB by any of them without sketches changed, only the possibilities to control the layout will be different.

  Arduino Train Demo Arduino Train for Kids 2 Arduino Train Junior Lite Arduino Train Junior PRO Arduino Train DUO Arduino Train DNT
  Arduino Train DEMO Arduino Train for Kids 2 Arduino Train Junior Lite Arduino Train Junior PRO Arduino Train DUO Arduino Train DNT
Two players mode or independed control 2 different routes      
The special button for extended automate and interlocking moving trains       Soon the Tablet version App
Dependent behavior of the loco's states control elements
Smooth thrust (11 speeds)        
Slider Algorithm™ (improved Slider Control)
Set default turnouts position button      
Whistle sound button  
Feedback mode (AWS)      
Speed indicate    
Online indicate turnout positions        
Number of controlled junctions 0 0 2 4 15 25
Number channels of Lights 0 1 1 1 9 + random 4 + random
Number channels of Gears 0 0 0 0/1 3 2
Multi-window Interface          
Scripts buttons         Soon the Tablet version App
Sensors toggle (disable/enable layout sensors)          
Save settings          
URB ready
Android version 5.0 > 5.0 > 5.0 > 5.0 > 5.0 > 5.0 >
URB freeware

Freeware App

All previous versions of applications that support the Protocol version 1 are obsolete and you can freely share them. The users of versions of Arduino Train Junior, ArduinoTrain BtControl Pro and Arduino Train PRO still can use the documentation using the old version my site.

Now available Demo application supporting the new protocol and the application Train for Kids for children with protocol support 1. These applications support the changing direction of the train, five locomotive speeds and have an emergency stop button. In the application for children, there is also a horn and a button for turning on the locomotive's spotlight. Instructions and sketches for the Demo application can be downloaded from the section for beginners. Description of my amusing project for your children using the Arduino Train for Kids application is available on the website

Train  for Kids App features

Arduino Train for Kids 2

Own and managed the "adult" railway model is certainly good. But if you have children, their enthusiasm for your "toy" will cost you dearly! So I came up with an Application that unites you. It is enough to take any children's railway, the main thing is that the locomotive had a motor and a place for batteries. You can even buy a few simple sets with plastic rails, and manage several trains at the same times. Lego Trains, Big Thomas Coal Steam and so on is good example.

Despite the fact that the application interface is made for children, the application itself supports the version of Protocol 2 of the URB project. And this means that the same application can be controlled also the railway layout, though not all, but only trains under control driver A. Also the application supports the installation of Arduino sensors, which makes the train behave a bit like a robot.

The necessary details of Arduino for installation in the locomotive are the same as in the example for beginners. I just changed the motor driver to a more compact L9110. Also you will need several battery boxes and the batteries themselves. Instructions for installation you can see in my article on the site Instructables or on the video on my Youtube channel. The full text of the sketch is shown below.

And of course you can come up with your own version of using this system from the application and details of Arduino, for example make control your child using a child tablet with his favorite toy (only you will need to work a little).

  • #define SENSOR_IR 2
    #define L9110S_AIA 3
    #define L9110S_AIB 5
    #define GND1 8
    #define LED1 9
    #define LED2 10
    #define FLOODLIGHT 11
    #define GND2 12
    static unsigned long preMillis;
    String inputString = "";
    boolean stringComplete = false;
    int locoSpeed, counter = 0;
    bool tick, directionForward, directionBackward;
    bool sensorActive = false, alarm_allRed = false;
    void setup() {
      // Initialize serial
      // Pins
      pinMode(GND1, OUTPUT);
      pinMode(GND2, OUTPUT);
      pinMode(LED1, OUTPUT);
      pinMode(LED2, OUTPUT);
      pinMode(FLOODLIGHT, OUTPUT);
      pinMode(L9110S_AIA, OUTPUT);
      pinMode(L9110S_AIB, OUTPUT);
      pinMode(SENSOR_IR, INPUT);
      digitalWrite(GND1, LOW);
      digitalWrite(GND2, LOW);
      digitalWrite(FLOODLIGHT, HIGH);
      digitalWrite(FLOODLIGHT, LOW);
    void loop() {
      if (stringComplete) {
        // TRAIN CONTROL
        if (inputString.charAt(0) =='a') {
          // TROTTLE
          if (inputString.charAt(1) =='0') {
            if (inputString.charAt(2) =='0') locoSpeed = 0; // Stop
            if (inputString.charAt(2) =='2') locoSpeed = 80;
            if (inputString.charAt(2) =='4') locoSpeed = 110;
            if (inputString.charAt(2) =='6') locoSpeed = 140;
            if (inputString.charAt(2) =='8') locoSpeed = 170;
          if (inputString.charAt(1) =='1') locoSpeed = 200;
          // MOVE DIRECTION
          if (inputString.charAt(1) =='d') {
            if (inputString.charAt(2) =='f') {
              directionForward = true;
              directionBackward = false;
            if (inputString.charAt(2) =='b') {
              directionForward = false;
              directionBackward = true;
            if (inputString.charAt(2) =='s') {
              locoSpeed = 0;
              directionForward = false;
              directionBackward = false;
              // DC motor conflict prevention
              digitalWrite(L9110S_AIA, LOW);
              digitalWrite(L9110S_AIB, LOW);
        // LIGHT
        if (inputString.charAt(0) =='l') {
        	if (inputString.charAt(2) =='0') digitalWrite(FLOODLIGHT, LOW);
          if (inputString.charAt(2) =='1') digitalWrite(FLOODLIGHT, HIGH);
        // SENSOR ON/OFF
        if (inputString.charAt(0) =='s') {
          if (inputString.charAt(2) =='0') sensorActive = false;
          if (inputString.charAt(2) =='1') sensorActive = true;
        inputString = "";
        stringComplete = false;
      if (digitalRead(SENSOR_IR) == HIGH || !sensorActive) {
        if (directionBackward) {
          digitalWrite(L9110S_AIB, LOW);    	
          analogWrite(L9110S_AIA, locoSpeed);
        if (directionForward) {
          digitalWrite(L9110S_AIA, LOW);
          analogWrite(L9110S_AIB, locoSpeed);
        alarm_allRed = false;
      else { // STOP at IR sensor
        digitalWrite(L9110S_AIA, LOW);
        digitalWrite(L9110S_AIB, LOW);
        alarm_allRed = true;
      if (locoSpeed > 0 && !alarm_allRed) {
        static unsigned long blinkMillis;
        if (millis() > (blinkMillis + 300)) {
          tick = !tick;
          blinkMillis = millis();
        digitalWrite(LED1, tick);
        digitalWrite(LED2, !tick);
      else if (alarm_allRed) {
        digitalWrite(LED1, HIGH);
        digitalWrite(LED2, HIGH);
      else {
        digitalWrite(LED1, LOW);
        digitalWrite(LED2, LOW);
    void serialEvent() {
      while (Serial.available()) {
        char inChar = (char);
        inputString += inChar;
        if (inChar == 'z') {
        stringComplete = true;
Junior Train App features

Arduino Train Junior

This application perfectly fits under the Starter Sets for Model Railroading. It not only replaces the wired remote from the kit, but also adds many new features, making the game more fun. This application controls four turnouts and reset them to their original position and have the sound of horn. And you can use any sensors for Arduino, since in the application there is a AWS mode.

This application uses most of the capabilities of URB units. You can use several locomotives and add railway signals to your game. Feedback between the application and your layout will allow you to implement the mechanism of automatic train stop before the deadlock. Also, by changing sketches you can add your own control algorithms.

App has two universal buttons to control your device and state tracks on the layout. Changing their functions in the sketch can include lighting houses on your railway or move the drawbridge. You can even assign a script to this button to run your trains automatically (see Interlocking example and video).
A basic example of a layout and sketches for this application.

  • Loco control: Speed 0 — "a00z", Speed 1 — "a02z", Speed 2 — "a04z", Speed 3 — "a06z", Speed 4 — "a08z", Speed 5 — "a10z", Speed 6 — "a11z", Forward — "adfz", Backward — "adbz", Stop — "adsz", Release — "adrz" and deactivate lighting the button.

    Junctions positions (Turnouts): Switch A Throw — "ja1z", Switch A Branch — "ja0z", Switch B Throw — "jb1z", Switch B Branch — "jb0z", Switch C Throw — "jc1z", Switch C Branch — "jc0z", Switch D Throw — "jd1z", Switch D Branch — "jd0z", Reset all junctions to default positions — "999z".

    Lights Button: ON — "la1z", OFF — "la0z".
    Custom Button: ON — "ca1z", OFF — "ca0z".

    Feedback from the Communicate URB unit: "aws" – an external Release command activate yellow lighting the Release button and playing a typical AWS sound signal; "awd" – an external Release command activate same processes and set a position thrust slider to zero.

DUO Train App all screens

Arduino Train DUO

The multi windows Application with advanced settings and features. The foremost program from the Line Apps Arduino Train. It implements all the functions of the URB, and in the future, new ones will be added to this program. You can use several Android devices for controls your trains and layout. Also, the buyer of this application is given Gerber-file for produce last version PCB URB unit – link and password is shown in Settings panel App.

The Arduino code snippet system, which allows you to collect a sketch from specialized modules, has been developed for this application and the DNT application. Methods and examples of collecting sketches and their structure, together with sample snippets for layout elements, are given in the section PRO sketches library. Also, all developments published in the closed part of the site for donators are supported only by the DUO and DNT applications.

Protocol V.2.1

Open system of commands for interaction between the management console and all the devices of your layout

Device Type or Player commands channel ID or the function First symbol Second symbol Third symbol
Speed slider under control Player A Speed 0 a 0 0
  Speed 1 a 0 1
  Speed 2 a 0 2
  Speed 3 a 0 3
  Speed 4 a 0 4
  Speed 5 a 0 5
  Speed 6 a 0 6
  Speed 7 a 0 7
  Speed 8 a 0 8
  Speed 9 a 0 9
  Speed 10 a 1 0
  Speed 11 a 1 1
Сontrolled by Player A Button "Direction Forward" a d f
  Button "Direction Backward" a d b
  Button "Stop" a d s
  Button "Release" a d r
Speed slider under control Player B Speed 0 b 0 0
  ¦ ¦ ¦ ¦
  Speed 11 b 1 1
Сontrolled by Player B Button "Direction Forward" b d f
  Button "Direction Backward" b d b
  Button "Stop" b d s
  Button "Release" b d r
New toggle "Custom" (Protocol V 2.1) ON/OFF a custom railtrack Player A c a 0 - OFF / 1 - ON
  ON/OFF a custom railtrack Player B c b 0 - OFF / 1 - ON
Toggles of Junctions (1-25) Switch A j a 0 - branch / 1 - throw
  Switch B j b 0 - branch / 1 - throw
  ¦ ¦ ¦ ¦
  Switch Y j y 0 - branch / 1 - throw
Lights Toggle "Channel 1" l a 0 - OFF / 1 - ON
  ¦ ¦ ¦ ¦
  Toggle "Channel 9" l i 0 - OFF / 1 - ON
  Button "All Lights ON" l - 1
  Button "All Lights OFF" l - 0
  Random mode lighting a layout l r 0 - OFF / 1 - ON
Gears Toggle "Gear 1" g a 0 - OFF / 1 - ON
  ¦ ¦ ¦ ¦
  Toggle "Gear 3" g c 0 - OFF / 1 - ON
  Button "All Gears OFF" g - 0
Run scripts (Automate) Button "Autorun 1" s 0 1
  Button "Autorun 2" s 0 2
Feedback signals from Communicate URB
Junction Feedback commands Junction A a 0 - branch / 1 - throw  
  ¦ ¦ ¦  
  Junction Y y 0 - branch / 1 - throw  
New Feedback commands (Protocol V 2.1) AWS signals to Player A
Playing AWS sound and yellow illumination the button "Release"
a w s
  Same reactions and automated moving the Player A throttle slider to zero a w d
  AWS signals to Player B
Playing AWS sound and yellow illumination the button "Release"
b w s
  Same reactions and automated moving the Player B throttle slider to zero b w d
Send App settings to Layout
The unique function to switching turnouts — Deblock Mode Toggle "ARM Mode ON" s j 0 - OFF / 1 - ON
The command to disable/enable all sensors on the layout Toggle "Sensors ON" s s 0 - OFF / 1 - ON

My Apps sends Protocol 2 commands consist of only four characters, the last character is always "z". The first symbol is the device type, the second symbol is the device identifier (number), the third symbol is the device status. A few examples: the command to set the speed of the locomotive is equal to 11 for player A has the form — "a11z", switching of the junction D to the position straight — "jd1z".

In version 2.1 of the Protocol 2, the command of general reset (Button "Default") of the state of junctions and whole layout is changed to "999z".

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. In railway model, there is not a lot of data flow and the speed of passing the team is also not very important. Therefore, you can use a very simpliest URB protocol. And you can change this protocol and expand it yourself. If you have a turntable on the layout, then adding a set of commands starting with the "t" (Turntable) symbol, you can control the railtable position in degrees multiple of ten — "t34z" (rotate the railtable to the position of 340 degrees). I will also gradually add new commands to this protocol.

This type of command is parsing by a sketch, which is based on the example of Serial Event from Arduino IDE. For testing and adjusting your layout devices you can type these commands directly into the terminal of Arduino IDE.

Full description of Protocol 2 you will read on Orange Book.


A unique opportunity this project

Currently, two feedback options are supported: automatic train stop before deadlock and displaying in the application the real position of junctions on the layout. The first possibility is called AWS and will expand in the future.

Feedback possible to extend the use of layout sensors to control trains. Add line state information to the application interface. And gradually will be new features to the project. URB was originally designed for this possibility and the re-equipment of the layout hardware for the use of feedback is not required.

Next possibility – indicate turnouts positions

The motor switching of the junction in railway modeling gives a lot of unobvious opportunities and gives rise to several problems. For example, the position of the junction can be uniquely associated with traffic light signals and, as a result, get a ready signal system. But at the same time, most of the modellers make bulky and complex panels, and their upgrade will very complicity. This problem is further aggravated by the fact that the position of the arrows is not always known after the layout is turned on.

All this was taken into account in the development of this project by changing the sketches of a particular URB, you can program any logic of the behavior of the signals. Also in the application there is a button DEFAULT, which sets junction to the position assigned user, the same happens when the layout is initialized when the power is turned on. Since there may be more than one player in the project, this button also helps to synchronize the position of the lines during the game. Without using feedback, the DEFAULT button is very useful.

This situation changes when the feedback mode is activated. The command unit URB always notifies the application about changing the positions of junctions. Thus, even if two Android phones are used, the position of all junctions will be online displayed on each of them.

How it works

To use feedback, simply add the following code to the block parsing of the sketch the URB communicate unit.

if (inputString.charAt(0) =='j') {
  if (inputString.charAt(1) =='a') {
    if (inputString.charAt(1) =='1') {
      // code for set junction A to straight position
      Bluetooth.print("a1z"); // feedback command
    if (inputString.charAt(1) =='0') {
      // code for set junction A to branch position
      Bluetooth.print("a0z"); // feedback command


Interactive Release button

The interactive button "Release" with functions similar to a real device in the driver's cab. It can be used in a variety of modes of automation of train movement. Upon receipt of a signal from the Communication URB, two reactions are possible:

  • button illumination and the signal like a sound real AWS system,
  • the same, plus setting the speed slider to zero position.

The reset of the button is carried out by your pressing, when this happens the reverse command is send to the Communication URB unit. This feature works independently for players A and B.
For an example of use, see the video with automatic stopping of the train before a dead end.

Wireless communications

Brief description of wireless technologies

Bluetooth Serial connection

Since in the project, as a management console are used Android, the choice consists of Wi-Fi and Bluetooth. Many people argue that Wi-Fi is the best way to wirelessly transfer data compared to Bluetooth. Wi-Fi is client-server tech. Since this immediately gives IP addressing, a high-speed duplex communication channels with broadcasting and long range. Also it is reliable and well-developed network software solutions, and a large selection of equipment for building networks.

But there is a very big problem in order to use Wi-Fi, you either need to rent cloud-based Internet IOT-technologies on the Internet (that is, the internet is essential for the work of your layout), or install and configure a local server for routing. I think this is too complicated and unjustified.
With the advent of the ESP-32 chip with a specialized fast Wi-Fi CPU (compared to slowed ESP8266), it appeared possible to experiment with its integrate in the project. I have another clone URB project on Wi-Fi, and in the future, perhaps I will publish it on this site. This chip is also good for Bluetoth, as can work both in Wi-Fi mode and Bluetooth. On the progress of this project-clone you can read out in the section for donators.

Bluetooth was originally conceived by developers to connect type point-to-point, and this technology works very poorly when building routing. But in our case, this one is much more convenient and simplest than Wi-Fi, 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.

As result, in any of my applications, just click on the blue icon of Bluetooth and in the opened list select your bluetooth module by the MAC-address. It's simple and convenient. Of course, you must first pair your Android with yours Bluetooth-module in the standard way: Settings > Bluetooth > Find device.
I made the choice by MAC-address (like 30:18:E4:00:09:E2) so that you could explicitly separate two identical by the name of bluetooth modules. The MAC-address of any device is always unique.

URB unit

Universal Railway Bus unit is first and foremost a convenient and reliable connector, replacing the breadbord and a bunch of wires. A more important feature of URB is the integration of several blocks into a chain, and on this basis the construction of any electronics for layout and control. In other words, it is a universal controller for railway modeling electronics.

PCB Universal Railway controller Block


It's just the way of the world, that without hardware, any program on Smart Phones and Tablets can not influence the reality. As you have already read about my applications, you know those it use the Arduino platform to control train models and layout devices. To connect details of Arduino with each other using a Breadboard and wires it is possible, but it is very inconvenient and unreliable. And to avoid this, I came up with a USB board.

This board uses Arduino NANO. Therefore, the dimensions of URBs are only 60x70 mm, which makes it possible to hide it even inside model building. This solution provides excellent flexibility, maintainability, simple mass production and low cost. The board is designed to avoid incorrect connection of Bluetooth modules and Arduino NANO.
To the functions of Arduino, the board (URB unit) adds the following capability:

  • Connectors for two Bluetooth HC-05 (HC-06) modules
  • Direct plug 3 servos or direct plug 3 any Arduino sensors
  • Direct plug relay block
  • Direct plug motor-driver aka L298 or similar
  • Convenient screw connections
  • 6 (7) High-Current outputs (Up to 0.5A per channel)
  • High-Voltage Outputs up to 50 V
  • Reliable data exchange between the MCU (like Raspberry Pi) using 3.3 volt logic and Arduino
  • Built-in I2C bus
  • Optional: install I2C pull-up resistors and smoothing capacitor for power supply
The I2C bus needs resistors pulling the data line to a high potential. You can install resistors of any type on the board. I recommend 10K resistors. I also recommend the use of a smoothing capasitor 1000mf x 25V, when a URB connected to relay or servos, to avoid voltage drop when they turn on.
I2C pullup resistors
PCB URB details set

URB unit details

  1. PBS-15 (HO27): 2.54mm pitch PCB female single row 15 pin – 4 pieces (or 15 pin – 2, 6 pin – 2, 4 pin – 2).
  2. PLS-40: 2.54mm 40 pin male single row pin header connector  – 1 piece.
  3. DIP IC Sockets 16P – 1 piece.
  4. 2 Pin screw PCB terminal block connector 5.08mm pitch – 6 pieces.
  5. 3 Pin screw PCB terminal block connector 5.08mm pitch – 4 pieces.
  6. ULN2003A (DIP16 package): High-Voltage, High-Current Darlington transistor arrays – 1 piece.

URB unit accessories

Arduino NANO and optional 3.3 to 5V level converter and 2 bluetooth modules HC-06(05).

HC-05 and HC-06, in fact it, is absolutely identical bluetooth modules with identical chips. One of the chips of these modules is a microcontroller. On the HC-05 there are two additional pins for its programming. There are no such pins on HC-06 and its module is easier to use for my project.
Mini URB

How get URB board

Documentation for the DIY-production of URB2.7 is free and available without restrictions.

You can order the production of this PСB or download the GERBER file at this link:

All people who make the donation get access to a restricted part of the site, where there are detailed instructions and a file of the GERBER format for ordering the URB version 2.8 DE board from manufacturers PCB or DIY-making. As a gift, these people receive a GERBER file for the manufacture or ordering of the URB Mini.

All versions of URB units are absolutely compatible. Versions 2.8 DE are slightly more convenient to use.

If you are related to the production of electronic components, and are interested in making a profit from the sale of units of URB, then I have a last URB 2.9 that is ready for production. If you interested it then send me message.

Assembling URB

Sketches Arduino and Protocol 2

As the experience with the first version of the protocol showed, you do not like the big examples code. And with the new version of the protocol it was possible to achieve modularity of the code.

URB arduino sketch diagram

The basic principles remain unchanged, only a simple, understandable code, no more complex than examples Arduino IDE. Now, the parsing commands (from the application or the real console or several consoles) moved to functions. In void loop () block code, you specify only the desired logic.

In Arduino IDE a unique system of combining a common sketch from several individual files. As you have already noticed, the Arduino IDE software always creates a folder in which the sketch file of the same name is contained. This is done because all the files in this folder, when you upload sketch (firmware) to the Arduino board, are combined into a single. Thus, you can break the sketch into functions in separate files. The project now uses this method of combining files.

A bit about the starting conditions

Your layout is quite complex in terms of wakeup control. The position of junctions, the order and logic of the switching on of the lines, the state of the global settings at the power-up of the mock-up must be uniquely determined.
In this project, this problem is resolved in two ways. The first, obvious, in the void setup () block, you describe not only the purpose of the I/O pin, but also their meaning. Then you, in accordance with them, bring the layout elements to the initial state. The second way is to use the RESET function. This function resets each URB by a common command. Then the same thing happens as in the first method. The reset command in the Protocol has the syntax "999z", and is executed every time the application is successfully connected via Bluetooth.
You can also force the layout lines at any time by pressing the DEFAULT button in the Application (however, like everything else, you can override the features of this function yourself).

Now, if a motor-driver is connected to a specific URB, you simply fill the PWM array with values, like a tables. Those, here you set the dynamics of trains on a particular connected with motor-driver lines. This new feature gives you one more unique opportunity available only in this project – you can limit the maximum speed in the sketch to the section connected to the URB. For example, for Yard lines, you can set a maximum level of only 200, and for Mainlines, leave 255.

Communication station

The new sketch principle for the project, which I represent on the code of the Communication Station, because it is the largest and complex compared to local URBs. The general principle remains unchanged: upon the arrival of an external command defined by the protocol according to the rules set by you, the communication station either changes the state of its conclusions, or translates this command to the local URB. The local URB is programming according to the same principles.
So, the first block of code collects the control command, the status of all sensors and device positions on the layout. I divided it into several functions by devices names. I repeat, the Arduino file system of the sketches is very simple, if you need the above function, just add the fi le with this function to the folder with the main sketch. You can change the code in functions, directly translating the input command to other URBs, or, what seems to me more correct, to perform operations with input commands in the logic block.

After this introduction I propose to look at a working example of a sketch.