Jump to content
  • 0

Diamond Crossing Protector

Rate this question

Paddy Mac Namara


This item didn't appear to rouse much interest over on the layout forum (Celbridge), but may be of interest to those who prowl this forum.


Anyway please let me know what you think.


Here is a more detailed description of what’s involved.


In the diagram below of crossing, M is mainline B is branch-line. So what we want to do is allow the mainline have priority over branch-line and of course avoid collisions.

The branch-line is isolated between points x and y. There are sensors S1 and S2 on mainline, when S1 or S2 detects a train power is cut on branch-line.

X Crossing Isolated section.jpg

The next diagram shows how the isolated section can be controlled with on/off switch and then replacing the on/off switch with a relay. Also a diagram with relay pin-outs shown.


What the electronic circuit does is allow the sensor to switch on/off the coil on the relay which in turn turns on/off power to the track

Isolated section.jpg

Below is the detailed circuit diagram.

Circuit Diagram 9V Rev B.jpg

What does it do?


With S1 or S2 = 0 (no train detected) Transistor T1 and T2 are on because current goes to base (b) of transistor and turns “on” the collector-emitter (c-e) circuit thus the relay coil gets 9v. The relay is wired to either side of isolated section on branch-line through the common (CM) and normally open (NO), which is an open circuit, but because the coil on the relay is active the relay switches and the CM-NO circuit closes so we have power to the isolated section.


So this is the normal operating state of the circuit, relay coil active and thus power to isolated section.


Now when a train passes over S1 or S2 (S1, S2 =1) the infrared light from the diode on the left of S1 (the triangle thingy) is reflected back to the right hand side and this activates the transistor circuit in the sensor to “on” so now current is diverted from the base of transistors T1, T2 to ground. This switches off the c-e circuit so no current passes thru the relay coil, which is now in its off state so the CM-NO circuit is now open and no current flows to isolated section.


I have a video of a test track for the circuit over on Celbridge thread on layout forum.



There are some problems with this in practice, the photo-sensor doesn’t work so well on the black undercarriage of our models…so I had to paint them white.

The sensor is only active when it detects something over it, so one needs a long train to ensure that one or both sensors is covered as a train is going thru the crossing.


Also what happens if branch-line loco is already on the crossing as a mainline loco triggers the sensor.Power is cut to branch-line so it stops in the middle of the crossing….crash…bang…oops !!!!!


This is really just the start of trying to design something more comprehensive, it will work fine if the timings of branch and mainline are lagged correctly and you keep an eye on things.


I’m not going to install it on the layout just yet I want to think things thru a bit more.

Am I going to need more sensors on branch-line, could a latching circuit be better.

Would reed switches be better…etc. etc?

Do I go the whole hog and use an Arduino microprocessor…..why didn’t I go DCC in the first place….?????....i know, I know.

Link to comment
Share on other sites

25 answers to this question

Recommended Posts

  • 0

My first thought, and the same thought occurred when I read the original post under Celbridge, is, what happens if a branch train is already in the isolated section when a mainline train hits S1. As I see it, the branch train stops, straddling the crossing, and gets T-boned by the mainline train.

A safer option would be to have a 'first come, first through' system, where the first train to reach the crossing, regardless of which line it is on, prevents the other train from reaching the crossing until it is clear.

Alternatively, a modification to the isolated section so that if a branch train is already in the isolated section when S1 is activated, the track power stays on until the branch train is clear of the crossing.

Moving the isolated section to be totally on the approach side of the crossing, leaving the crossing live for the branch train to keep going in the event of an approaching main line train, is another option.

Link to comment
Share on other sites

  • 0

As promised some detail on the circuit used in the most recent video on “Celbridge”

As before my test track is not actually an X crossing but the two parallel tracks simulate what I want to do.

Track 1 is the main-line thru the junction and the reed switches are here. Track 2 is the “suburban” line and is required to wait for the main-line to pass thru the X crossing, this track is isolated either side of the X crossing.


R1 is the reed switch that detects the loco as it approaches the “X crossing”

R2 is the reed switch as it leaves the “X crossing” junction.

The isolated section on track 2 (the one I want to shut down) is connected to the relay thru the common (cm) and normally closed (nc) pins. So the isolated section is live at the beginning of the sequence.

When R1 is activated by magnet on loco it closes and delivers power to coil 1 on the relay, this causes relay to open the cm/nc circuit and so power is cut off to the isolated section on track 2. Because this is a latching relay we only need one pulse to coil 1 and the cm/nc remains open. (it doesn’t matter that R1 opens again once the loco moves away, once “latched” it stays latched).

Coil 2 un-latches the relay. So once the loco passes over R2 it activates coil 2 which unlatches the relay so the cm/nc circuit reverts to it original state and power is returned to isolated section on track 2.

As noted before this is a WIP and a learning curve, I am working on solutions to problems such as what if the loco on the suburban line is in the middle of X crossing as loco on mainline approaches….watch this space.


Link to comment
Share on other sites

  • 0

Just a bit of detail on the video posted on “Celbridge” thread.

Here is a photo of the track showing the position of the reed switches and a photo of the circuit board. The reed switches are triggered by a magnet underneath the loco.

FCFS circuit board.JPG

FCFS track.JPG

The circuit diagram is shown below, at top of diagram, a schematic of the track with sensors and a diagram of how the pin contacts on the relays work


Relay K1 has power to the track connected thru contacts NC (normally closed) and CM (common). The default for the relay is called the “reset” condition. Thus current flows thru NC-CM. So the Branchline (BL) has power “on”.

If loco on ML triggers reed switch R1 current flows thru coil 1 of relay K1 and “sets” the relay, this will then switch the contacts from NC-CM to NO-CM so BL is now power “off”. (NO is the normally open contact on the relay). When the loco on ML triggers R2 current flows thru coil 2 of relay K1 and “resets” it back to default, so BL has power “on”

Relay K2 operates in the same way and switches power on/off to Mainline (ML).

The circuit operates on a first come first served basis, whichever loco reaches the junction first switches off power to the other loco. At the moment the circuit can only work in one direction, I think I can get it to work “both ways”, but I’m having some difficulty at the moment

When and if, I ever get around to actually wiring this up on the layout, I will be switching power on/off on isolated sections, so I won’t have locos suddenly stopping dead on the tracks far away from the diamond junction.

This project is still evolving and I’m in no major hurry as I have control of the diamond crossing with simple on off buttons. I have two tracks going across the junction, so double the wiring.

I have done some coding with Arduino microcontroller and reed switches with some success, but it’s debatable if using software will simplify things as I still need relays to switch on/off current.

For those of you unfamiliar with Arduino, it is, I suppose a hobby version of a PLC (used in more industrial applications), very cheap about €30 , very popular for student projects and hobbyists

Link to comment
Share on other sites

  • 0

As you can see not the most reliable, i think if i change the orientation of the reed switch, lenghtwise it should work better, see photo below of smaller magnet attached to loco


Loco with magnets.jpg

here's the ciruit diagram, very scruffy sorry i normally do them on graph paper...


Reed switch with arduino.pdf

and finally here is code for the arduino, i take no credit for it, i found it after a lot and i mean a lot iof searching, its simple and i like it for that

bool junctionclear;

void setup() {

  pinMode(2, OUTPUT);

  pinMode(9, INPUT);

  pinMode(10, INPUT);

  pinMode(11, INPUT);

  junctionclear = true;

  digitalWrite(2, LOW);


void loop() {

 if (digitalRead(9) == HIGH || digitalRead(11) == HIGH)

  {junctionclear = !junctionclear;}


 if (junctionclear)

  {digitalWrite(2, LOW);}

  else {digitalWrite(2, HIGH);}


Link to comment
Share on other sites

  • 0

As shown above the circuit using the Arduino allows for control of the junction with a loco going both ways.

In my post of 10th march 2019 i could only get control in one direction using relays only and i have been trying to solve this for a year...Despite my best efforts i could not devise my own solution, however  i came across the solution below recently and it is very satisfactory.


more detail on how the circuit works:

The initial state for this circuit is relay in Reset State. Thus the relay armatures are connected to cm-nc. The led is lit up, the led represents power to track you wish to isolate.

Capacitor C2 charges up to +9V via 2.2k resistor R2 while capacitor C1 remains discharged as it is not connected to the 9V supply. If reed switch R1 or R2 is activated,C2 discharges via the relay’s “set” coil 2 and diode D2.This switches the relay into its set position, thus relay armature are connected to cm-no, the LED will switch off. C1 then begins to charge via R1. While R1 or R2 are activated the relay does not return to the reset position because the current supplied via R1 is insufficient for the coil to latch the armature.

Once the relay has switched and C1 has finished charging, activating R1 or R2 again causes the relay to switch back to the reset state via coil 1 and the LED comes on again.

The relay is a two coil 5v latching relay: Hongfa HFD2 005 M L2 D Bi-stable Latching Relay DPDT 5v, 2 coil, 2A. Purchased on ebay around €2.50/3.00

Capacitors are : Rubycon Electrolytic Capacitor, Miniature, 22 µF, 25 V, ZLG Series, ± 20%, Radial Leaded, 5 mm. These were purchased from Farnell and cost 10cent each

Diodes I had in my electronics box, these only cost a few cent.

Resistors I got an assortment pack on ebay of 300 with a range of different resistance values, cost was €5.

The website I found this circuit on is: https://www.eeweb.com/extreme-circuits/momentary-switch-teamed-with-latching-relay


  • Like 2
Link to comment
Share on other sites

  • 0

Thanks for sharing this clever thing Paddy.

Just a thought on this now that I understand your circuitry. What if one of one of the reed switches misses a contact. Say that the entry switch doesn't register the magnet when a loco comes in? Then when the train passes the second reed-switch it will turn off power at this point. Then you are out-of-sync and when the next train comes over the entry reed-switch it turns on power on the crossing track.

I do hope your modern magnets are more reliable than the ones I used in the past so you don't get into this situation.

  • Like 1
Link to comment
Share on other sites

  • 0

hi sven, thanks for your comments and interest. I don't think that will be a problem, my previous experiments, see vid from 10th march 2019,  show that the magnet does engage reed switch when attached to loco, in fact the magnet is very close to the switch as it passes over.

What i was more concerned with is the double contact of reed switch as the magnet passes over it as shown in the video below.  When using the Arduino and coding this was a problem and that is why there is a time delay  in the code, so that the code ignores the second contact. With this circuit as long as the magnet passes over the reed switch reasonably quickly, the charging and discharging of the capacitor takes time so the second contact does not cause a problem. According to this site it takes 0.25 sec to full charge.https://www.allaboutcircuits.com/tools/capacitor-Charge-and-time-constant-calculator/


  • Like 1
Link to comment
Share on other sites

  • 0

I recently built a detection circuit using reed switches and Neo magnets. I found, the same as you, that when the reed switches were installed parallel to the direction of motion of the magnet, as in your demo, the reed switch pulsed twice as the magnet passed. However, by installing the reed switch at 90 degrees to the direction of motion of the magnet (ie across the track), the double pulse did not happen, just a single one.  

Link to comment
Share on other sites

  • 0

The detection circuit was built to automatically detect and unload a narrow gauge train of 4 side tipping hoppers loaded with fine ballast.  It was for a Club layout, and because of that, the circuit had to be as simple as possible, hence the use of relays and no electronics. However, despite rigorous testing and operating flawlessly, on it's first outing it failed miserably with spectacular smoke effects. I am told that, because I was unable to attend that exhibition. The post mortem revealed that the builder of the layout had decided to tidy up the wiring under the layout, and had got his wires mixed up with the wiring supplying the unloader. Once the fault was found and rectified, the unloader worked fine once again.

Below is a description of how the circuit works, and also the circuit diagram for it.  

All four hoppers are fitted with magnets. There are two reed switches at the unloader, the first positioned such that each hopper will stop in the correct position for unloading.

The second is activated by hopper 1, so that the track power is reversed ready for the return to the loader once hopper 4 has been emptied.

The unloader has an arm attached to a crank fitted to a motor. When activated, the arm extends and pushes the side hopper body over, thus tipping out the load. On reversing back into the quarry for reloading, a fixed trackside arm returns the hopper bodies into the horizontal position ready for loading. Loading is done manually.

A push button held down till the loaded train clears the loader completely, starts the journey to the unloader.


  1. Hopper 1 arrives at RS1 and activates the unloader. Relay 1 switches on and is held on by the hopper magnet holding RS1 closed. Relay 2 switches on, powered by the unloader motor supply, and switches off power to the track. It also completes the circuit to Relay 4, which only activates when hopper 1 reaches RS2.
  2. When the unloader reaches the top, switch T switches off the unloader relay which reverses the unloader direction. Switch T also momentarily supplies power to Relay 3 which switches on and latches on via relay 1. When on, Relay 3 inhibits RS1 from activating the unloader circuit.
  3. When the unloader reaches the bottom, Switch B cuts power to the motor thus stopping the unloader, and releasing Relay 2, which restores track power.
  4. Hopper 1 moves away from RS1 thus releasing Relay 1 which unlatches Relay 3 restoring the RS1 function.
  5. Hopper 2 arrives at RS1 and the cycle repeats itself, as it also does for hoppers 3 & 4.
  6. As hopper 4 arrives at RS1, hopper 1 arrives at RS2. Relay 4 switches on via Relay 2 and latches on, reversing track power. It also latches on Relay 3 to inhibit RS1. The complete cycle repeats for hopper 4, except that Relay 3 stays latched on.
  7. On completion of the cycle, track power is restored, but in the reverse direction. The hopper leaves RS2 and passes RS1 without anything activating except Relay 1, which does nothing, as Relay 3 is already latched on via relay 4.

On arrival at the loader, the hopper activates RS3 switching on Relay 5, which unlatches Relay 4 thus reversing the track power, and releasing Relay 3 ready for the next journey. With Relay 3 unlatched, RS3 does not activate Relay 5.


Well, you asked for it, I hope that it all makes sense. The amazing thing is that it actually works. 

  • Like 1
Link to comment
Share on other sites

  • 0

Great to see Paddy.

Have you decided which sensor to use? Have you tried them on real track to see how they work? 

I had the same problem as you describe with black under sides that didn't reflect the IR beam. A problem with the photo transistor is that you may want to adjust the threshold in case you have extreme brightness in your room or if the room is dark.

Link to comment
Share on other sites

  • 0

hi sven, i went with the reed switch, i posted video on "Celbridge" thread on layout forum. Yep you are right, Photo transistor is sensitive to ambient conditions but you can adjust sensitivity with resistor, with limitations, i have done quite a bit on this and if you check out my youtube channel you can see for your self. Name of channel is Patrick Mac Namara.

Here's a longer (winded) version with maybe clearer explanation on real track with the reed switches.


  • Like 1
  • Informative 1
Link to comment
Share on other sites

  • 0

Thanks noel for your words of encouragement. Not sure if i understand the question,  i am detecting the loco on the "mainline", but there are loads of operation issues, its a solution, not a complete one.

For example if a "branchline" loco is already in the junction.  the "mainline" loco will switch of power to the branchline loco and its stuck there so we have a crash.

Because the layout is continuous and i have an identical junction on the other side, once both junctions are protected, the branchline locos will always lag the mainline loco, so collisions should be avoided. a fail-safe solution, whilst possible, just gets way too complicated i'd spend my life under the layout wiring it all up.

I may come back to it in the future, but for the moment i have loads of scenic modelling to do



Link to comment
Share on other sites

Join the conversation

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

Answer this question...

×   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.

  • Create New...

Important Information

Terms of Use