Project tutorial

Automation of Railway Models Part 2 - Interlocking © CC BY

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

  • 997 views
  • 0 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

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.

Schematics

hall_simple_interlocking_TWCtlLOta0.png
Hall simple interlocking u6kx4pr1mf

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 //
  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; 
  }
}  

Comments

Similar projects you might like

Alexa Controlled LEDs Through Raspberry Pi

Project tutorial by vincent wong

  • 1,123 views
  • 3 comments
  • 7 respects

Arduino Indoor Garden

Project tutorial by MEGA DAS

  • 13,312 views
  • 7 comments
  • 44 respects

WiFi To Your Website

Project showcase by Projecter

  • 3,428 views
  • 4 comments
  • 4 respects

Challenging Maze Game

Project showcase by gmussi

  • 33 views
  • 0 comments
  • 0 respects

Measuring temperatures with LM35 and DS18B20

Project tutorial by jomar

  • 174 views
  • 0 comments
  • 2 respects
Add projectSign up / Login