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

Development Board for AtTiny MCU

by Vincenzo G.

  • 100 views
  • 0 comments
  • 4 respects

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 164 views
  • 0 comments
  • 2 respects

Version 2.0 Advanced Attendance System (Without Ethernet)

Project tutorial by GadgetProgrammers

  • 2,840 views
  • 5 comments
  • 44 respects

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by IoTBoys

  • 145 views
  • 0 comments
  • 3 respects

Ultrasonic Security System

Project tutorial by Krepak

  • 331 views
  • 0 comments
  • 4 respects
Add projectSign up / Login