Steve_Massikker
Published © CC BY

Automation of Railway Models Part 1 - Sensors (Updated)

The first part of the instructions on automation. Sensors on rails and bundle cylinder neodymium magnets on locomotives.

EasyFull instructions provided3,939
Automation of Railway Models Part 1 - Sensors (Updated)

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Hall sensor
×2
Breadboard (generic)
Breadboard (generic)
×1
Cylinder neodymium magnets
×10
Jumper wires (generic)
Jumper wires (generic)
×1
Railroad signal
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

hall_simple_sheme_ctUnMPIGXr.png

Hall simple sheme 3p6ab6xpuc

Code

Simple interlocking

Arduino
// ARDUINORAILMAKET.RU
// SimpleHall.ino
// 15.09.2017
// Author: Steve Massikker

//// GPIO PINS ////

#define HALL_1 2 
#define HALL_2 3
#define RED_SIGNAL 10
#define GREEN_SIGNAL 11

//// VARIABLES ////
boolean interlocking_state;

void setup() {

// Initialize GPIO
  pinMode(HALL_1, INPUT); 
  pinMode(HALL_2, INPUT); 
  pinMode(RED_SIGNAL, OUTPUT); 
  pinMode(GREEN_SIGNAL, OUTPUT);  

// On start or reset
  interlocking_state = true; // Line free
  digitalWrite(RED_SIGNAL, LOW);
  digitalWrite(GREEN_SIGNAL, HIGH); 
  
}

void loop() {

  if (digitalRead(HALL_1) == LOW || digitalRead(HALL_2) == LOW) {
    interlocking_state = !interlocking_state;
    delay(200);
  }
  
  if (interlocking_state) {  //true
     digitalWrite(RED_SIGNAL, LOW);
     digitalWrite(GREEN_SIGNAL, HIGH);     
  } 
  else {
     digitalWrite(RED_SIGNAL, HIGH);
     digitalWrite(GREEN_SIGNAL, LOW);    
  }
}  

Credits

Steve_Massikker

Steve_Massikker

7 projects • 44 followers
Contact

Comments