Jump to content

Recommended Posts

Posted

Hi all,

I was wondering if there are any best practices in automating set 7866, the electric 2 track crossing.

My idea was to look into 4 sensors, 2 for each track, a bit before and a bit after the crossing. And depending on the current state, send a 12v signal to the switch boxes that control them. But that might become complex when you also have the manual switch on your transformer, states going out of sync etc.

Any ideas? I'm by no means an electrical expert, just wondering how I could approach it and what I would need for it.

Posted
3 minutes ago, cozzie4d said:

what I would need for it.

Some intelligence ;-)

Let's look for one track: " a bit after" depends on length of train ....
What if trains comes from the other direction?

And what might happen if two trains meet there, one closing and a second later the other one opening?

In short: it is pretty complex, as you wrote

 

Posted

Some kind of controller, like an Arduino or an ESP8266, a distance (e.g. SR04) or hall effect sensor to detect the train, and a relay to translate the 3.3 or 5v controller signal to 12v to drive the Lego parts.  You can probably rig up a purist solution with a PUP hub and pybricks if you skip the 12v stuff, although honestly this is more expensive.

As Lok24 pointed out there's a lot of edge cases, changes in speed, varying train lengths, what happens if a train reverses in the middle of the crossing, etc.  But these are entirely solvable with software.  (The simplest thing to do would be to set a timeout to raise the gates, and any time a sensor is triggered, extend the timeout, which would cover most cases.)

This is a fairly doable first project, you can probably put it together in a couple of weeks and for less than $25.  There's a lot of good Arduino tutorials out there.

Posted (edited)

I automated this one a while back (10 years I see now, time flies!). You need one sensor per track that you place a meter or so in front of the crossing, minding the direction of the track (if the train can come from either side on the same track, you'll need two sensors for that track). If a sensor detects a train, beams go down, when the train has cleared the sensor a timer is started to make sure the beams remain closed until the train has passed the crossing. After the timer has elapsed, beams go up.
For sensors I always use this one: https://www.pololu.com/product/1132 , 10cm variant will do too but needs to be placed further away from the track (or it will detect the train on the adjacent track). Don't try the cheap Ali Express IR sensors: they don't work very well, generate a lot of false positives and so on. For moving the beams you need a motor driver, easiest way to do so is an L293D driver. Google on "L293D" and you'll find a module or Arduino shield that you can use. Read the datasheet of the 293D to understand how to connect the thing. Lights can be directly connected to the controller. As mentioned before, you need a micro controller to control the whole thing. An Arduino Uno will be the most easy thing to use, lot's of tutorials for that online.

Bonus 1:
Here's a video with the thing in action:
Automated 7866 crossing

Bonus 2:
The Arduino code that I've used:

#include <TimerOne.h>

int LampsA=8;
int LampsB=9;
int MotA=6;
int MotB=7;
int Sensor0=2;
int Sensor1=3;

volatile int downtime=2000;

volatile long StartTime=0,EndTime=0,CurrentTime=0;

volatile bool Sensor0Activated=false, Sensor1Activated=false;

void setup()
{
   Serial.begin(9600);

   pinMode (MotA, OUTPUT);
   pinMode (MotB, OUTPUT);
   pinMode (LampsA, OUTPUT);
   pinMode (LampsB, OUTPUT);   
   pinMode (Sensor0, INPUT);
   pinMode (Sensor1, INPUT);   
   
  pinMode(13, OUTPUT);       

  attachInterrupt(0, Sensor0ISR, FALLING); //Sensor 0, pin 2 on Micro
  attachInterrupt(1, Sensor1ISR, FALLING); //Sensor 1, pin 3 on Micro 
  
  barsUp();
  LampsOff();
}

void loop()
{
  do
  {
    delay(1);
  }
  while (!Sensor0Activated && !Sensor1Activated);
  
  LampsOn();
  barsDown();
   do
   {
     CurrentTime=millis();
   }
   while (CurrentTime < EndTime);
   
   barsUp();
   LampsOff();
   //attachInterrupt(0, Sensor0ISR, FALLING); //Sensor 0, pin 2 on Micro
   //attachInterrupt(1, Sensor1ISR, FALLING); //Sensor 1, pin 3 on Micro    
   Sensor0Activated=false; 
   Sensor1Activated=false;     
   CurrentTime=0;
  


}

void LampsOn()
{
   digitalWrite (LampsA, LOW);
   digitalWrite (LampsB, HIGH);  
}

void LampsOff()
{
   digitalWrite (LampsA, LOW);
   digitalWrite (LampsB, LOW);  
}

void barsUp()
{
   digitalWrite (MotA, LOW);
   digitalWrite (MotB, HIGH);
   delay (1000);
   digitalWrite (MotA, LOW);
   digitalWrite (MotB, LOW);
}

void barsDown()
{
  digitalWrite (MotA, HIGH);
  digitalWrite (MotB, LOW);
  delay(1000);
  digitalWrite (MotA, LOW);
   digitalWrite (MotB, LOW);
} 

void Sensor0ISR()

{
  //detachInterrupt (0);  
  Sensor0Activated=true;
  StartTime=millis();
  EndTime=StartTime+downtime;
}  

void Sensor1ISR()

{
  //detachInterrupt (1);  
  Sensor1Activated=true;
  StartTime=millis();  
  EndTime=StartTime+downtime;  
} 

 

Edited by AlmightyArjen

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...