Steve_Massikker
Published © CC BY

Automation of Railway Models Part 2 - Interlocking

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

EasyFull instructions provided1,910
Automation of Railway Models Part 2 - Interlocking

Things used in this project

Story

Read more

Schematics

hall_simple_interlocking_TWCtlLOta0.png

Hall simple interlocking u6kx4pr1mf

Code

2 Hall sensors points

Arduino
// 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 //
  if (digitalRead(HALL_1) == LOW) {
    latch_hall_1 = true;
  }
  if (digitalRead(HALL_2) == LOW) {
    latch_hall_2 = true;
  } 
  if (digitalRead(HALL_3) == LOW) {
    latch_hall_3 = true;
  }
  if (digitalRead(HALL_4) == LOW) {
    latch_hall_4 = true;
  }
  if (digitalRead(HALL_5) == LOW) {
    latch_hall_5 = true;
  }
  if (digitalRead(HALL_6) == LOW) {
    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; 
  }
}  

Credits

Steve_Massikker

Steve_Massikker

7 projects • 44 followers
Contact

Comments