Project tutorial

# Automation of Railway Models Part 2 - Interlocking © CC BY

The second part of the instructions on automation. Interlocking plant.

• 1,573 views
• 12 respects

## Components and supplies

 Arduino Nano R3
×1

## Apps and online services

 Arduino IDE

### Interlocking

Let's complicate our scheme. Now we divide the line into two sections. At the entrance of the each section we'll put the signal and let's go the train in a circle. There is one problem: if the train stops right above the sensor, then our previous sketch will get chaos.

The problem can be solved in many ways, but the most obvious and simple (at the same time get rid of “delay (200);” in the sketch) to put two sensors, instead of one. These modules are very cheap.

Let's change the previous scheme (see part 1). In the sketch on this part the latch code is given.

## Code

##### 2 Hall sensors pointsArduino
```// ARDUINORAILMAKET.RU
// SimpleInterlocking.ino
// 16.09.2017
// Author: Steve Massikker

//// GPIO PINS ////

#define HALL_1 7
#define HALL_2 6
#define HALL_3 5
#define HALL_4 4
#define HALL_5 3
#define HALL_6 2
#define RED_SIGNAL_2 8
#define GREEN_SIGNAL_2 9
#define RED_SIGNAL_1 10
#define GREEN_SIGNAL_1 11

//// VARIABLES ////
boolean latch_hall_1 = false, latch_hall_2 = false;
boolean latch_hall_3 = false, latch_hall_4 = false;
boolean latch_hall_5 = false, latch_hall_6 = false;
boolean point_1, point_2, point_3;

void setup() {

// Initialize GPIO
pinMode(HALL_1, INPUT);
pinMode(HALL_2, INPUT);
pinMode(HALL_3, INPUT);
pinMode(HALL_4, INPUT);
pinMode(HALL_5, INPUT);
pinMode(HALL_6, INPUT);
pinMode(RED_SIGNAL_1, OUTPUT);
pinMode(GREEN_SIGNAL_1, OUTPUT);
pinMode(RED_SIGNAL_2, OUTPUT);
pinMode(GREEN_SIGNAL_2, OUTPUT);

// On start or reset
digitalWrite(RED_SIGNAL_1, LOW);
digitalWrite(GREEN_SIGNAL_1, HIGH);
digitalWrite(RED_SIGNAL_2, LOW);
digitalWrite(GREEN_SIGNAL_2, HIGH);

}

void loop() {

// HALL //
latch_hall_1 = true;
}
latch_hall_2 = true;
}
latch_hall_3 = true;
}
latch_hall_4 = true;
}
latch_hall_5 = true;
}
latch_hall_6 = true;
}

// POINT //
if ((latch_hall_1) && (latch_hall_2)) {
latch_hall_1 = false;
latch_hall_2 = false;
point_1 = false;
}
if ((latch_hall_2) && (latch_hall_3)) {
latch_hall_3 = false;
latch_hall_4 = false;
point_2 = false;
}
if ((latch_hall_4) && (latch_hall_5)) {
latch_hall_4 = false;
latch_hall_5 = false;
point_3 = false;
}

// LOGIC //

if (!point_1) {
digitalWrite(RED_SIGNAL_1, HIGH); // red
digitalWrite(GREEN_SIGNAL_1, LOW);
}
if (!point_2) {
digitalWrite(RED_SIGNAL_1, LOW); // green
digitalWrite(GREEN_SIGNAL_1, HIGH);
digitalWrite(RED_SIGNAL_2, HIGH); // red
digitalWrite(GREEN_SIGNAL_2, LOW);
point_1 = true;
}
if (!point_3) {
digitalWrite(RED_SIGNAL_2, LOW); // green
digitalWrite(GREEN_SIGNAL_2, HIGH);
point_2 = true;
point_3 = true;
}
}
```

## Schematics

• 6 projects
• 32 followers

#### Published on

September 17, 2017

#### Members who respect this project

and 4 others

See similar projects
you might like

#### Gesture Control Robot

Project tutorial by Raunak Oberai

• 1,540 views
• 9 respects

#### Matrix Orbital GTT TFT Thermometer

Project tutorial by MatrixOrbital

• 3,583 views
• 8 respects

#### Pathfinder

Project showcase by Maverick

• 11,604 views
• 77 respects

#### Micro Soldering Station

Project tutorial by Paulo Bruckmann

• 10,631 views
• 34 respects

#### Back Up SD File to Dropbox

Project tutorial by Andrei Florian

• 3,112 views