Project tutorial
The URB Unit – Making Arduinos Network

The URB Unit – Making Arduinos Network © CC BY

Your personal universal electronics kit. More I/O pins. More devices. More distances. Remote wireless control. No bunch wires.

  • 3,725 views
  • 3 comments
  • 21 respects

Components and supplies

Ard nano
Arduino Nano R3
×2
Seeed URB 2.7 unit
×2
Servo Module (Generic)
×1
Bluetooth module HC-05 or HC-06
×1
Level Shifter Board (3.3V 5V)
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×2
Infrared Module (Generic)
×2

Apps and online services

About this project

The system of several Arduino interconnected by an I2C bus is not new. But many people are not aware of this possibility and the advantages of such a joint connections between several Arduino. There are also difficulties in understanding the interaction of sketches on multiple devices.

My version of such connections – the project of the URB (Universal Railway Bus) was designed for railway modellers. But its capabilities can be applied anywhere. First of all, I will give a simple example that will show you the main advantage of such a system.

This two pictures with doors only shows the concept. When you press corresponding buttons, the DC motor rotate in different directions and, according to commands from the sensors, reduce the speed, and then stop.

In the upper picture, the sketch must process the commands of the buttons and send control signals to the motor driver. When signals are received from the sensors, the sketch should change the rotational speed from maximum to zero over a certain time interval in order to ensure a smooth closing of the door. Also, the sketch must lock the rotation of the motor in the wrong direction, for example, if you press the button to close the door when it is in the closed position. After that, you also need to add a similar algorithm for the second door. Obviously, the code of this sketch will be large.

If you use local Arduino (#2 and #3) controlling each of its motor and receiving commands from its sensors, then the Arduino #1 sketch is reduced to a few lines. Just Now you need three sketches. The sketches of Arduino #2 and #3 are the same, and also simpler than the sketch on first picture. In addition, the number of wires is significantly go down.

Again, this is a fictional example. It will work in reality, but at large distances you need to use another version of the I2C bus - RS485. Nevertheless, you can see on the video how I2C bus works with railway barriers.

Conclusion: Combining multiple Arduino simplifies programming and reduces the number of wires, it also allows you to locally configure your devices and quickly find faults. By dividing the system into functional blocks and checking them separately. Also, the problem of insufficient number of I/O pins is solved – just add one more Arduino! Arduino NANO is very cheap a board!

For railway modellers

Any modeller encountereddifficulties in creating electronics for a railway layout. This is a lot of wires, thecomplexity of connecting devices and their compatibility among themselves, andmost importantly the inability to add or change something in the finishedlayout 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 turnouts, or signals, or sensors, or streetlights on the layout, you just cut the four-wire bus in the nearest place and insert another a URB unit. 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 at your's 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. Another plus is theability to experiment with each URB independently of others, and solve problem to look for possible malfunctions in electrical parts on layout. It isalso 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.

URB system consists of software and hardware. The software is described in detail on my website and is called Protocol 2. The hardware is a universal connectors board and named URB unit. You can program sketches yourself or use examples from my site. In any case, thanks to the standardization of the code under Protocol 2, it will be more convenient for you to use a system of several Arduino. And I do not use complex code in my examples. All Protocol 2 is based on the classical sketches from Arduino IDE.

URB unit

Not necessary to use specialized hardware in the URB project. You can use a breadboard with wires or any shields. But it is very uncomfortable! And to avoid this, I came up with a URB (Universal Railway controller Block) unit.

This board uses Arduino NANO. Therefore, the dimensions of URB's are only 65x75 mm. 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

Also, this board can not be broken, it only connectors. That is, if you accidentally burned the chips - just replace them on the board :)

Unfortunately, you have to independently solder connectors to this PCB.

Simple network (working example)

Here I will give the simplest interaction of two URB units. The code of these two sketches is very simple. In addition, this example demonstrates the different combinations of same I/O pins on the URB unit. Also in this example, you can simultaneously test two serial ports with a connection without routing (point-to-point) and a I2C bus with routing, and the most interesting is their combinations. So yes, it is this scheme that allows you to simultaneously manage from two independent consoles above hundreds of devices on a railway layout or something else.

The system works as follows: after connecting the application to the URB #1 board via Bluetooth, when you press arrow-buttons, the servo will change its position. The same will happen when the infrared sensors triggering.

You can infinitely supplement this system with new devices and change the code, only you will need to use more powerful supply.

Your personal universal kit

Let's go back to the example of doors. If you use two URB units and powerful stepper motors at 12 volts, you will get such a design. As a control, you can use the Android application. If you are interested, I will write such an free application for doors control. And of course, instead of doors, you can use anything :)

Like from Lego cubes! From several URB units you can invent any systems with a minimum of wires and very simple programming and connecting.

I use these units in each of my projects or examples, and above all in the my home layout.

If you have a big robot

One more example. If your robot is very long, for example a crane, then it is easier to install several URB units and connect them with your crane control system than using a lot of wires and programming codes for platform drives, winches and cables.

-------------

Sorry for my bad English. You can correct this post.

Code

Sketch for URB #1Arduino
Sketch for URB #1 (Master I2C mode)
// WWW.ARDUINORAILWAYCONTROL.COM
// V.1.0  10/18/2018
// URB #1 
// Protocol V.2 & URB unit V.2.7 and higher
// Author: Steve Massikker
// --------------------------------------------

void(* resetFunc) (void) = 0; // RESET FUNCTION

#include <SoftwareSerial.h>
#include <Wire.h>

// I/O PINS

#define SENSOR_J1_PIN    9
#define SENSOR_J3_PIN    11

SoftwareSerial Bluetooth(12, 13); // RX, TX

// VARIABLES

  // SERIAL EVENT
  bool stringComplete = false;
  String inputString = "";

  // I2C
  int addressI2C;  
  byte dataToI2C = 0;


void setup() {

// Initialize Serial & I2C
  Serial.begin(9600);
  Bluetooth.begin(9600);
  Wire.begin();
  inputString.reserve(4);

// Initialize Sensors
  pinMode(SENSOR_J1_PIN, INPUT);
  pinMode(SENSOR_J3_PIN, INPUT);

}

void loop() {

// ----  PARSING INCOMING APP COMMANDS
  if (stringComplete) {

    // CONTROL FUNCTIONS
    if (inputString.charAt(0) =='a') {
      if (inputString.charAt(1) =='d') {
        if (inputString.charAt(2) =='b') {
          dataToI2C = 30;
          addressI2C = 2;
          sendDataViaI2C();
          delay(150); 
        }
        if (inputString.charAt(2) =='f') {
          dataToI2C = 31;
          addressI2C = 2;
          sendDataViaI2C();
          delay(150);           
        } 
      }  
    }  

    inputString = "";
    stringComplete = false;

  }

  // ---- COLLECT SENSORS STATE

  if (digitalRead(SENSOR_J1_PIN) == HIGH) {
    dataToI2C = 30;
    addressI2C = 2;
    sendDataViaI2C();
    delay(150);     
  }

  if (digitalRead(SENSOR_J3_PIN) == HIGH) {
    dataToI2C = 31;
    addressI2C = 2;
    sendDataViaI2C();
    delay(150); 
  }  


  bluetoothEvent();
}

// ----------- FUNCTIONS ----------- //

void serialEvent() {
  if (Serial.available()) {
    char inChar = (char)Serial.read();
    inputString += inChar;
    if (inChar == 'z') {
      stringComplete = true;
    }
  }
}

void bluetoothEvent() {
  if (Bluetooth.available()) {
    char inChar = (char)Bluetooth.read();
    inputString += inChar;
    if (inChar == 'z') {
      stringComplete = true;
    }
  }
}

void sendDataViaI2C() {
  Wire.beginTransmission(addressI2C);
  Wire.write(dataToI2C);
  Wire.endTransmission();
}
Sketch for URB #2Arduino
Sketch for URB #2 (Slave I2C mode)
// WWW.ARDUINORAILWAYCONTROL.COM
// V.1.0  10/18/2018
// URB #2 
// Protocol V.2 & URB unit V.2.7 and higher
// Author: Steve Massikker
// --------------------------------------------

#include <Wire.h>
#include <Servo.h>

// I/O PINS

#define JUNCTION_EN 8
// Servo J1;
// Servo J2;
Servo J3;

// VARIABLES
unsigned long millisJunction;
byte dataFromI2C;

void setup() {

// Initialize I2C
  Wire.begin(2);
  Wire.onReceive(receiveI2C);

// Initialize Servos
  // J1.attach(9);
  // J2.attach(10);
  J3.attach(11); 

}

void loop() {
  // COMMAND PARSING
  if (dataFromI2C != 0) {
    switch (dataFromI2C) {

    // SERVO
    case 30: J3.write(180);
         delay(50);
         digitalWrite(JUNCTION_EN, HIGH);
         millisJunction = millis();
         break;

    case 31: J3.write(0);
         delay(50);
         digitalWrite(JUNCTION_EN, HIGH);
         millisJunction = millis();
         break;
    
    }

  dataFromI2C = 0;
  }
  
  if (millis() > (millisJunction + 800)) digitalWrite(JUNCTION_EN, LOW); // AUTO ON/OFF POWER ON SERVO
}

// ----------- FUNCTIONS ----------- //

void receiveI2C(int howMany) {
  while (Wire.available() > 0) {
    dataFromI2C = Wire.read();
  }
}

Schematics

Network between two and more Arduino's
Urb2 7 hackster fn3z23slhe

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 459,845 views
  • 46 comments
  • 251 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,647 views
  • 95 comments
  • 672 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 239,326 views
  • 42 comments
  • 252 respects

OpenCat

Project in progress by Team Petoi

  • 202,133 views
  • 161 comments
  • 1,418 respects
Add projectSign up / Login