No Duck Mo V2.1

In August 2021 I posted my plans for a Free-mo lift gate that I called No Duck Mo V2.0.

In the fall of 2024 a dedicated model railroader in Chilliwack, British Columbia began building two of these using my 2021 plans. He has made very good progress. There were a couple of small errors in my plans for V2.0 that he pointed out to me so I have updated the plans and named them No Duck Mo V2.1.

Here is a link to download the plans:

No Duck Mo V2.1

A New Site to Check Out

I was contacted by a young man named Lucas who has earned his Railroading merit badge in Boy Scouts. I understand that he used my Blog to help him in this achievement.

Congratulations, Lucas. I am very pleased that I was able to be of some assistance.

Lucas also suggested that people in the hobby might want to check out another website that contains a lot of useful information, including links. Check it out here: Model Railroads & Freight Cars

Switching Layout - Part 5 - Components of Layout Top

As my woodworking workshop is located at my main home in Regina, SK but the switching layout is to be built for the den in my two-bedroom condo in West Kelowna, BC, my design must allow me to make components in my workshop and assemble them to make sure that the design works. I will then dismantle and carefully label all components and then take them with me to BC where I will assemble everything.

In Part 4 I shared drawings of the components of the end guides that will be attached to the walls at each end of the layout, using components that are easy to assemble, disassemble and then travel with. The layout top which is to be 11 feet long and 28 inches wide is a bit more complicated - because of its size. I shall cut all the wood at home but will wait and purchase the rigid foam insulating board in Kelowna to cut down on the quantity of materials I will need to transport. The foam board can be easily cut with an Olfa knife or box cutter.

These drawings show my intended design:




Switching Layout - Part 4 - Design of End Guides

Following are additional details regarding the design of the end guides in which the 2 inch nylon garage door rollers will travel:




Switching Layout - Part 3 - Storage Mechanism

In Part 1 I said that one of my criteria for this switching layout is that, when stored, it must not occupy a lot of floor space. I have come up with a plan that will occupy an area along one of the 11 foot walls in the den and, when stored, will protrude into the room a distance of no further than 15 inches.

In the following drawing, the various colours depict:

  • yellow - hinged countertop
  • blue - front edge of cabinetry (affixed to the front will be standard kitchen cabinet doors)
  • pink - the layout top (to be made of solid pink foam insulation board, 1 1/2 inches thick
  • light brown - the wood supporting structure underneath the pink foam insulation board
  • dark brown disks - 2 inch nylon garage door rollers that will be mounted in 2 inch x 3 inch (nominal) dimensional lumber
  • blue disk (barely visible in the top-right vicinity of the structure) - wheels that will be mounted in several locations along the top front of the front edge of the cabinetry; the layout will rest on these wheels when deployed to prevent sagging of the 11 foot long layout top.
  • orange-brown - 2 inch x 2 inch (nominal) dimensional lumber to be mounted on 3/4 inch plywood fastened to the walls on each end of the room. This will serve as guides within which the nylon garage door rollers will travel when raising and lowering the layout.
  • scale model buildings are depicted in various colours.


The following drawing shows the layout in its operational position:


This is a short video showing how the layout will be raised and lowered:



 

Switching Layout - Part 2 - Track Plan

 I have devised the following track plan for my switching layout:

Length = 10 ft. 11 3/4 in.

Width = 28 in.

HO Scale.

Turnouts (hand made):

  • 11 x left-hand #5 Fast Tracks turnouts
  • 4 x right-hand #5 Fast Tracks turnouts
  • 1 x curved 36-24 #6 Fast Tracks turnouts
Crossings (hand made):
  • Fast Tracks 30-degree crossing
Turnout control:
  • 16 x Bullfrog (by Fast Tracks) manual turnouts
Buildings to be all scratch-built.

This is a larger image, turned on its side:





Switching Layout - Part 1 - Concept

On November 11, 2021 I wrote about my prostate issue and the need to have 33 radiation treatments. Those treatments ended on December 20, 2021 so Christmas 2021 was extra special for me. Roughly 2/3 of the way through my treatments I became quite fatigued and had very little motivation to do much in the way of model railroading, or anything else for that matter.

In the second week of January my wife and I drove to West Kelowna, British Columbia, to spend a couple of months in the two-bedroom condominium that we purchased in autumn 2021. As I have been preoccupied with obtaining and assembling furniture and going on a lot of long walks to enjoy the scenery and the (relatively) mild winter weather I decided to take a break from the blog.

The fatigue from my radiation treatments resolved itself by the end of January and I feel great. We return home to Saskatchewan in mid-March at which time I must have a PSA test and then a consultation with the radiation oncologist. This will be the "moment of truth" as to whether the radiation treatments were successful.

Our condo in West Kelowna has two bedrooms plus a den. The den is just over 3.4 by 2.1 metres (11 by 7 feet) in size and has no window.

After being away from my model railroading hobby for some time I put my mind to how I could build a model railroad in the den, while at the same time not permanently occupying much of the room and rendering it useless for any other purpose. I concluded that a shelf-style switching layout would be fun to try. I have never before built a switching layout.

Following are my criteria for this switching layout:

  • HO scale.
  • must be able to be stored in a space-saving way when not in use, taking up minimal floor space.
  • manually operated turnouts, hand-made using #5 Fast Tracks jigs.
  • Digital Command Control (DCC) electronics.
  • All buildings will be scratch-built.
  • Layout dimensions will be approximately 3.4 by 0.7 metres (11 feet by 28 inches).
In upcoming postings I shall share a proposed track plan and my plans for being able to store the layout in such a way that minimal floor space is occupied.


Here are three photos from the balcony of our West Kelowna condo:

The above photo, taken in October 2021, is facing north-west showing Shannon Lake and, on the right, the Shannon Lake Golf Course.



The above photo, taken in January 2022, is of the same view.


Night, taken in January 2022.


Animation - Part 2 - Design

I decided to take on the challenge of creating my own track system to create animation. You will note that this uses the concepts used by the Magnorail system referred to in Part 1 but is not an attempt to replicate the Magnorail system. As I don't have access to any Magnorail parts I designed my own parts, several of which appear to be quite different. I also don't know the dimensions of any of the Magnorail parts so I came up with my own dimensions.

I ordered a high-torque 12 volt DC motor from Amazon. The output shaft turns at 5 RPM. I then designed and 3D printed a drive mechanism to sit on top of the motor. Here are pictures of the drive mechanism:

motor mounted to underside of drive mechanism

top side view

with drive gears mounted (note hole the closest gear fits over the "D" gear shaft so it doesn't slip)

same as above but with retainers pressed into holes

Next I created 3D printed chain components which connect to each other and which have holes to fit round rare-earth magnets in a couple of places to move boats:


The track components look like this - each track piece is screwed to a sub-floor which which will reside underneath the styrene sheet "pond":



Here is a picture of the completed track, with the drive mechanism in place:


Here is a picture of the subfloor mounted underneath the pond cutout in the Free-mo module:

The subfloor is mounted with wingnuts to make it easy to remove the subfloor with the track in case adjustments or repairs are ever needed in the future. The motor is wired to a bridge rectifier which takes DCC current from the accessory buss running under the Free-mo module.

Here is a top-side view of the styrene sheet. The beaver dam will be built to disguise the front edge:


Here is a short video showing the boat moving (the rough brown circle painted on the surface is where the beaver lodge will be built):



I will not be sharing the design details or the STL 3D printer files, either for no cost or for a price

Next up......doing the scenery.

Animation - Part 1 - Concept

I am fascinated with animation on a model railroad, whether it be building interior lighting that occasionally turns on and off or motion. Done well, animation brings the model railroad to life and enhances the animation already provided by the movement of rolling stock.

I have a complete Free-mo module built but the scenery has not been completed, aside from the track being ballasted. My vision for this two-part module is as follows:

  • there will be a pond which is cutaway at one edge of the module;
  • the pond was created by a beaver family that dammed a small stream that flows from a culvert under the railway tracks;
  • the beaver dam will be depicted near the edge of the module and a beaver lodge will be somewhere in the centre of the pond;
  • there will be a stately residence beside the pond and a dock where the residents can dock their boat;
  • the boat will sail around the pond without the use of any sort of visible track.

This shows what I have in mind (because of the perspective from which the photo was taken the distance that the boat travels appears much shorter than it will actually be):


I am aware of a commercial product that I could use for this animation.  It is made by Magnorail. They use a plastic chain system that sits beneath a road or lake surface. Magnets can be placed in the chain which cause objects, also with magnets, to travel along the surface. These could include vehicles, boats or one of my favourites, bicycles:


There appears to be only one retailer in North America that handles this product, Reynaulds Euro Imports in Illinois. Their price for a starter set is US$219.95. Once I pay for shipping in US dollars, convert these costs to Canadian dollars and add the import broker fee and Canadian taxes the total cost for the starter kit will come in at around C$400.00 plus. I cannot justify this price, to myself or my wife!

There must be another way...... (to be continued)

Movember Wake Up Call

As most of you will know, Movember is a term associated with fundraising activities during the month of November in aid of cancer research focused on cancer specific to men such as prostate and testicular cancer.

In 2009 my cancerous prostate was surgically removed when. I was 52 at the time. I was fortunate that the cancer was caught when it was because there was no evidence of spread outside my prostate. Following treatment for prostate cancer it is strongly advised to have an annual PSA (Prostate Specific Antigen) test. I have followed this regimen annually since 2010 and, until early 2020, my PSA was so low that it was not recordable. However, in January 2020 my PSA registered as 0.1 which my doctor was not concerned about. In February 2021 my PSA doubled to 0.2. The doctor advised that 0.2 is the threshold above which they become concerned. He prescribed a follow up PSA test two months later and it came back as 0.3. This means that the cancer is back.

It turns out that in approximately 30% of men who have their prostate removed the cancer will come back. "Removal" of the prostate really means "removing as much as possible without doing collateral damage". The prostate is not like an eyeball - it is intertwined with many nerves as well as your urethra so some prostate material is left behind during surgery. In some cases this can become cancerous. Lucky me - that is my situation.

I next had a bone scan to see whether any cancer had spread to my bones as this is where prostate cancer will often migrate. The scan was negative. I also had a CT scan which came back negative. The oncologist was pleased with these results, as I was I! These results suggest that the amount of the cancer is likely to be quite small and is most likely, but not certainly, located in the prostate bed - where my prostate used to live.

The only treatment option is radiation. Chemotherapy is not an option. Last week I began a course of 33 radiation treatments. Today I had my 6th treatment. Treatments are daily except for weekends and statutory holidays. This means I will be finished in mid-December. I haven't longed for Christmas this much since I was 3 years old.

I am told to expect significant fatigue at roughly the half-way point and possibly some bladder or colon irritation after six or seven treatments. So far so good.

Notwithstanding having cancer again, I feel extremely fortunate for three reasons:
- the cancer appears to have been caught early.
- I live 15 minutes away from the Allan Blair Cancer Centre.
- I don't need surgery; if I did, it most certainly would have been bumped indefinitely by all of the socially irresponsible unvaccinated idiots who are tying up our health care system after catching preventable COVID-19 and bumping all sorts of medical treatments, many of which are much more dire than mine.

Preparation for treatments is very easy. Your bladder must be full and your bowel empty for the treatments. This means a daily dose of a very mild laxative which works like a charm with no discomfort at all (Restoralax - I highly recommend it). It also means peeing one hour before the treatment and immediately drinking 500 ml (2 cups) of water. That's it for preparation. Having a full bladder and empty bowel helps to move vital parts as far away from the radiation target as possible. It is also strongly advised to avoid coffee as it is a diuretic and can be hard on your bladder. Also alcohol is to be avoided during the treatment course (the presence of alcohol makes things harder for your body which is having to cope with radiation).

Before treatments can begin you must attend a session called a CT simulation. You lie on a platform that is part of a CT machine and with your clothes and shoes on. With nurses holding a "modesty towel" over your nether regions you pull down your pants and underwear to mid-thigh. They then position your body so that four laser beams shine on your skin - two of them shine on the hips, one in your groin and one beneath your belly button. They then give you tiny freckle-size tattoo dots to mark the position of each laser beam. Next the CT machine runs and scans to tell the radiation oncologist where your innards are so they can determine where the radiation needs to be targeted. The bladder/bowel prep has to be done before this procedure also.

I was given a printed schedule with the times of my treatments for the next 5 days. I show up 5 minutes before my appointment (they won't even let you in the door if you are earlier - probably a COVID-19 rule). I place may printed schedule in a tray at the reception desk and walk down the hall to a waiting room. Very quickly after than a technician comes for me and we walk to the room where the radiation machine is located. It is made by a company called Varian, a US company located in Palo Alto, California. Varian became part of the Siemens organization, the German conglomerate, in April 2021. 

This is what the radiation machine looks like:

Note that there is a cabinet on the left which is sitting on the floor of the room with the words "Varian Medical Systems" printed on it. This is the part of the machine that generates the radiation. There isn't actually any "radioactive" material in the machine (i.e., no cobalt or other radioactive isotope). The machine uses a linear accelerator to create the radiation. Note also that there is a vertical seam between the cabinet on the left and rest of the machine. The entire rest of the machine to the right of that seam can be rotated 360 degrees around your pathetic diseased-ridden body as it lies on the bed. Note that the bed has an accordion structure underneath which allows the technician to fine-tune the position of your body from their control room.

You lie on the bed with your knees and head supported in special foam cradles, with your clothes and shoes on. Similar to the CT simulation, technicians hold a "modesty towel" over you while you pull down your pants and underwear to mid-thigh. They then position your body so the four tattooed dots line up exactly with four laser beams that shine on you (and which hopefully have been properly calibrated to be in the same position as those in the CT simulation room!!!).

The technicians then leave the room and devices emerge on either side of your body. In the above picture these are in the retracted position, folded back against the machine. When extended these devices do a scan of your innards - the entire structure rotates slowly 360 degrees around your body to do the scan. This is to verify that your bladder is sufficiently full and your bowel is sufficiently empty in relation to what they were like when the CT simulation was done. If not within tolerances you either have to drink more water or you have to try to take a dump - fortunately neither has happened to me yet.

After about a minute a horn goes off and a red warning panel flashes on the wall to warn anyone foolish enough to be hanging around that electrons or protons of whatever will start hurling towards the helpless lump of flesh and bones (and more fat than there should be) on the table. Then you can hear the linear accelerator fire up - it makes a fairly high pitched whining sound - all I can think of is the original Star Trek but so far Scotty has not made an appearance and I haven't been beamed anywhere. I just lie there with my mind imagining that my innards are turning into crispy bacon. Then the business end of the machine (the round head that is above the table in the picture above) starts rotating slowly around my body a full 360 degrees. It then stops for two or three seconds and then proceeds to rotate in the other direction a full 360 degrees. It then shuts off, I pull up my underwear and pants and say goodbye. The whole procedure from walking to the treatment room to walking out takes roughly seven or eight minutes. On my way out I pick up my printed schedule on which someone has initialled beside the time of my next appointment and/or has modified some of the future appointment times.

The people at the Allan Blair Cancer Centre are the nicest, kindest, warmest health care people I have encountered anywhere. Everyone I have had contact with, from the oncologist to the nurses to the technicians, are extremely good listeners and equally good communicators. They exude a quiet confidence which gives a patient great confidence.

The beam of radiation is directed at a target inside your body that is lined up with the axis of the machine. As the head of the machine rotates around this axis the target gets radiated for the full treatment period while all other flesh, bones and organs are only radiated momentarily as the machine rotates - ingenious.

This is how the machine rotates.


This shows the beam of radiation being directed from the linear accelerator and through a prism or some similar-acting component and then through a series of metal leaves to regulate its size (I assume much like how the aperture of a camera lens is varied).




This is a picture of the linear accelerator (I have no idea if this is from exactly the same machines I am being treated with but it is probably a reasonably close facsimile).



The morals of this story are:
  1. If you have never had prostate cancer treatment MAKE SURE YOU ARE HAVING REGULAR PSA TESTS AND PHYSICAL EXAMS.

  2. If you have had prostate cancer treatment MAKE SURE YOU KEEP ON HAVING REGULAR PSA TESTS.

  3. Nobody wants to get cancer, of any type. However, if caught and treated early your chances of living a longer and healthier life are greatly improved over someone who can't be bothered to have these simple tests performed. If you are squeamish of doctors, suck it up and get tested.
Please donate to cancer research.

I look forward to the next 27 treatments and then Christmas when I might be able to have a drink or two again! 


Crossing Signals - Part 4 of 4 - The Arduino Code

If you have not experience with the coding of the programming language for Arduino microcomputers this is not the blog entry where you will learn about it. However, if you have been following along and would like to see the code I developed, please feel free to copy the following Arduino sketch and upload it to your own Arduino. However, as your model railroad will almost certainly have a different track configuration you will need to modify the coding as necessary to suit your particular situation. I would be pleased to help anyone who has a question. You can email me at rupertsinsights@gmail.com.

Here is my code:

/*---------------------------------------------------------------------------
  This Arduino sketch and the circuit diagram in Part 3 of 4 is used to control model railroad crossing
  lights that warn vehicular traffic about the danger of an approaching train. This design does not include
  the use of sound as listening to crossing sounds quickly becomes tiresome. However, sound
  could easily be added with the addition of an Arduino sound shield and a small addition to
  the coding. The particular circumstance on the model railroad for which this was designed
  has the highway crossing two tracks, the main line and a branch line, which means there
  are two level crossings in use. Also, at the east side of the level crossing there
  are four possible tracks from which a train can approach the level crossing (the main
  line from the east, a siding that joins the main line immediately to the east of the crossing,
  the branch line from the east and a spur that joins the branch line immediately to the east
  of the crossing).

  The presence of train cars is detected with the use of light sensitive photoresistors. A photoresistor
  is a device allows electrical current to pass through with very little resistance when it
  is exposed to light. When the light source is removed (by the light being extinguished or the
  photoresistor shaded by the presence of an object such as a model train) the photoresistor's
  resistance increases. The amount of resistance is continuously variable (i.e., is analog and not
  digital). This is the same principal used by many devices in our daily lives (smart phones and smart
  TV's use photoresistors to detect how much light is present in order to vary the brightness of the
  screen, street lights use photoresistors to control when they turn on, etc.). In this instance
  an Arduino microcontroller is used to sense the increased resistance caused by the shading of
  photoresistors which, in turn, causes the Arduino to flash pairs of red LEDs which are mounted
  in the crossing signals facing both sides of the highway.
  
  Photoresistors can be wired in series. If two are wired together in series, shading either one
  or both photoresistors will cause the current passing through them to drop.

  In this design, photoresistors are mounted in the centre of the model railway tracks, between
  the ties and with the tops of the photoresistors flush with tops of the ties. There are six
  photoresistors which have been designed as the "OUT" locations - those locations described in the
  first paragraph above that a train will cover is it approaches the crossing from a distance. In
  addition, photoresistors are mounted immediately adjacent to the level crossing roadway on both
  sides of the roadway, again in the centre of the track with the tops of the photoresistors flush
  with the tops of the ties (the "CROSSING" photoresistors).
  
  The shading of any one of the "OUT" photoresistors tells the Arduino that a train is approaching
  the crossing and the Arduino starts flashing the crossing lights. The shading of any one of the
  "CROSSING" photoresistors tells the Arduino that the train has now reached the crossing so the
  Arduino keeps flashing the crossing lights. Once the last car has passed the last "CROSSING"
  photoresistor the lights stop flashing after a predermined amount of time that can be adjusted
  (it is not desirable for the lights to stop flashing while a train is still across the crossing
  but it equally undesirable if the lights continue flashing long after a train has passed).
  
  This program self-calibrates the photosensors based on the amount of light falling on the
  photosensors at the momment the Arduino is first turned on. This means that all photosensors must
  not be covered when the Arduino is first turned on. Also, it helps if the ambient light in the room
  remains fairly constant during the time that the Arduino is operated. If the ambient light reduces 
  the self-calibration will take this into account but is not able to cope with large increases in 
  ambient light. If there is a large increase in ambient light then it is simply matter of removing
  power from the circuit momentarily and then allowing it to reboot.
  
  It would have been possible to wire all six OUT photoresistors in series. However, as they are
  located several feet away from each other it is very likely that the amount of ambient light falling
  on each one is quite different. This would mean that the self-calibration would likely not be as
  sensitive as one would like. For this reason, photoresistors that are located in close proximity are
  wired in series and the Arduino self-calibrates each pair together. One pair is designated OUTWest, another is
  OUTEast1, a third is OUTEast 2 a fourth is CROSSING1 and the last is CROSSING2.
 
For ProMini or UNO September 24, 2021
  -------------------------------------------------------------------------------*/
//Assign the various sensor pairs to Arduino pins:
const int sensorOUTWest = A0;
const int sensorOUTEast1 = A1;
const int sensorOUTEast2 = A2;
const int sensorCROSSING1 = A3;
const int sensorCROSSING2 = A4;

//Designate a counter for how long sensorOUT is covered
//and a limit after which the lights will stop flashing:
int countOUT = 0;
int countOUTLimit = 8;

//Designate a counter that starts at the value of
//countDownStart which determines how long crossing lights
//flash after a train has passed the level crossing.
//The higher the value of countDownStart, the longer
//the crossing lights will flash after the train has passed.
int countCROSSING = 0;
int countDownStart = 1;

//Counter to allow a train to pass over a second OUT sensor
//after it has passed over the level crossing to avoid
//triggering a new flashing light sequence.
int countFALSE = 0;
                                                       
//Following variables adjust how much time passes for
//the Arduino to reset once a train has passed over
//a second OUT sensor (the higher these values the
//longer it takes to reset)
int countFALSELimit = 15;
int delaySensitivity = 200;

//Following values are assigned based on whether a
//photosensor is shaded enough to trigger a crossing
//light sequence (in effect converts the analog
//photoresistor into a digital device, simply to
//make the program logic simpler.
int coveredOUT = 0;
int coveredCROSSING = 0;
int currentSensorState = 0;
int lastSensorState =0;

//The value of inTransit depends on where a train is
//located in its progression towards, over and beyond
//the level crossing. The value of inTransit is what
//causes the crossing lights to either flash or not.
int inTransit = 0;

//The amount by which the light falling on eash sensor
//must drop to start detection logic.
int lightThreshold = 75;                            

//measures amount of light falling on sensor OUT:
int valOUTWest; 
  
//Starting point of variable valOUT (will increase to
//highest reading of val:                                  
int valOUTWestHigh = 0;

//Starting point of variable valOUT (will decrease to
//lowest reading of val):
int valOUTWestLow = 1023;

//A variable that will be equal to the value of
//valOUTWestHigh MINUS the value of lightThreshold:
int valOUTWestTest;                                 

//The following are all similar variables as the above
//for the various other photoresistor pairs
int valOUTEast1;
int valOUTEast1High = 0;
int valOUTEast1Low = 1023;
int valOUTEast1Test;

int valOUTEast2;
int valOUTEast2High = 0;
int valOUTEast2Low = 1023;
int valOUTEast2Test;

int valCROSSING1;
int valCROSSING1High = 0;
int valCROSSING1Low = 1023;
int valCROSSING1Test;

int valCROSSING2;
int valCROSSING2High = 0;
int valCROSSING2Low = 1023;
int valCROSSING2Test;

int LED1 = 2;
int LED2 = 3;

void setup()
{
  pinMode(sensorOUTWest, INPUT);
  pinMode(sensorOUTEast1, INPUT);
  pinMode(sensorOUTEast2, INPUT);
  pinMode(sensorCROSSING1, INPUT);
  pinMode(sensorCROSSING2, INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  checkAllOUTSensors();
  checkAllCROSSINGSensors();

//Outer sensor detects train; train has not reached crossing
  if (coveredOUT == 1 && coveredCROSSING == 0 && inTransit == 0)        
  {
//Add to value of counter as long as outer sensor detects train  
    countOUT = countOUT + 1;  
    
//Train is deemed to be in transit between outer and inner sensors
//and inTransit is assigned value of 1                                          
    inTransit = 1;                                                
  }

//Outer sensor continues to detect train; train has not reached
//crossing; train deemed in transit
  if (coveredOUT == 1 && coveredCROSSING == 0 && inTransit == 1)        
  {
//Counter value stops increasing because train is either continuing
//its travel toward crossing or it has stopped on the OUT sensor    
    countOUT = countOUT;                                                 
  }

//Outer sensor no longer detects train; train has not reached
//crossing; trained deemed in transit
  if (coveredOUT == 0 && coveredCROSSING == 0 && inTransit == 1)
  {
//Add to value of counter as long as train is in transit and is not
//detected by outer or crossing sensors    
    countOUT = countOUT + 1;                                            
  }

//Train doesn't reach crossing in time (as for a train that stops
//on a sensor and then reverses direction)
  if (countOUT > countOUTLimit && countCROSSING == 0)                    
  {
    countOUT = 0;
    inTransit = 0;
  }

//Train reaches crossing
  if (coveredCROSSING == 1 && inTransit == 1)                             
  {
//Value of countDownStart is assigned to countCROSSING    
    countCROSSING = countDownStart; 
    
//inTransit is assigned a value of 2                                      
    inTransit = 2; 
     
//countOUT is reset to 0 because countOUT is no longer
//needed for this train passage                                                      
    countOUT = 0;                                                         
  }


  if (coveredCROSSING == 0 && inTransit == 2 && countCROSSING > 0)
  {
    countCROSSING = countCROSSING - 1;
  }


  if (countCROSSING == 0 && inTransit == 2)
  {
    inTransit = 3;
  }

  if(inTransit == 3 && coveredOUT == 1)
  {
    countFALSE = countFALSELimit;
    inTransit = 4;
  }

  if(inTransit == 4 && coveredOUT == 0 && countFALSE > 0)
  {
    countFALSE = countFALSE - 1;
    delay(delaySensitivity);
  }

  if(inTransit == 4 && coveredOUT == 1 && countFALSE > 0)
  {
    countFALSE = countFALSE;
  }

  if(inTransit == 4 && coveredOUT == 0 && countFALSE == 0)
  {
    inTransit = 0;
  }
  
  if (inTransit == 1 || inTransit == 2)
  {
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    delay(500);
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
    delay(500);
  }

  else if (inTransit == 0 || inTransit == 3 || inTransit == 4)
  {
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
  }

  {
    //    Serial.print(" valOUTWest= ");
    //    Serial.print(valOUTWest);
    //    Serial.print(" valOUTWestHigh= ");
    //    Serial.print(valOUTWestHigh);
    //    Serial.print(" valOUTWestLow= ");
    //    Serial.print(valOUTWestLow);
    //    Serial.print(" valOUTWestTest= ");
    //    Serial.print(valOUTWestTest);
    //    Serial.print(" valOUTEast1= ");
    //    Serial.print(valOUTEast1);
    //    Serial.print(" valOUTEast1High= ");
    //    Serial.print(valOUTEast1High);
    //    Serial.print(" valOUTEast1Low= ");
    //    Serial.print(valOUTEast1Low);
    //    Serial.print(" valOUTEast1Test= ");
    //    Serial.print(valOUTEast1Test);
    //    Serial.print(" valOUTEast2= ");
    //    Serial.print(valOUTEast2);
    //    Serial.print(" valOUTEast2High= ");
    //    Serial.print(valOUTEast2High);
    //    Serial.print(" valOUTEast2Low= ");
    //    Serial.print(valOUTEast2Low);
    //    Serial.print(" valOUTEast2Test= ");
    //    Serial.print(valOUTEast2Test);
    //    Serial.print(" coveredOUTEast= ");                              
    //    Serial.print(coveredOUTEast);
    //    Serial.print(" valCROSSING1= ");
    //    Serial.print(valCROSSING1);
    //    Serial.print(" valCROSSING1High= ");
    //    Serial.print(valCROSSING1High);
    //    Serial.print(" valCROSSING1Low= ");
    //    Serial.print(valCROSSING1Low);
    //    Serial.print(" valCROSSING1Test= ");
    //    Serial.print(valCROSSING1Test);
    //    Serial.print(" valCROSSING2= ");
    //    Serial.print(valCROSSING2);
    //    Serial.print(" valCROSSING2High= ");
    //    Serial.print(valCROSSING2High);
    //    Serial.print(" valCROSSING2Low= ");
    //    Serial.print(valCROSSING2Low);
    //    Serial.print(" valCROSSING2Test= ");
    //    Serial.print(valCROSSING2Test);
    //    Serial.print(" coveredOUT= ");                            
    //    Serial.print(coveredOUT);
    //    Serial.print(" coveredCROSSING= ");                      
    //    Serial.print(coveredCROSSING);
    //    Serial.print(" countOUT= ");
    //    Serial.print(countOUT );
    //    Serial.print(" countCROSSING= ");
    //    Serial.print(countCROSSING );
    //    Serial.print(" countFALSE= ");
    //    Serial.print(countFALSE );
    //    Serial.print(" inTransit= ");
    //    Serial.print(inTransit );
    //    Serial.println();
    //    delay(100);
  }
}

void checkAllOUTSensors()
{
//Following routine reads valOUT from photosensor, sets valOUTHigh and valOUTLow 
//and subtracts the value of lightThreshold from the High measurement to detect the presence of a train
  valOUTWest = analogRead(sensorOUTWest);            
                                                     
  if (valOUTWest > valOUTWestHigh)
  {
    valOUTWestHigh = valOUTWest;
  }                                                 
  if (valOUTWest < valOUTWestLow)
  {
    valOUTWestLow = valOUTWest;
  }                                                   
  valOUTWestTest = valOUTWestHigh - lightThreshold;


//Following routine reads valOUT from photosensor, sets valOUTHigh and valOUTLow
//and subtracts the value of lightThreshold from the High measurement to detect the presence of a train
  valOUTEast1 = analogRead(sensorOUTEast1);          

  if (valOUTEast1 > valOUTEast1High)
  {
    valOUTEast1High = valOUTEast1;
  }                                                 
  if (valOUTEast1 < valOUTEast1Low)
  {
    valOUTEast1Low = valOUTEast1;
  }                                                   
  valOUTEast1Test = valOUTEast1High - lightThreshold;

  
//Following routine reads valOUT from photosensor, sets valOUTHigh and valOUTLow
//and subtracts the value of lightThreshold from the High measurement to detect the presence of a train
  valOUTEast2 = analogRead(sensorOUTEast2);            
                                                     
  if (valOUTEast2 > valOUTEast2High)
  {
    valOUTEast2High = valOUTEast2;
  }                                                 
  if (valOUTEast2 < valOUTEast2Low)
  {
    valOUTEast2Low = valOUTEast2;
  }                                                   
  valOUTEast2Test = valOUTEast2High - lightThreshold;
                                             

//If valOUT is less than valOUTTest then sensor OUT is not covered
//so sensor is given a value of 1
  if (valOUTWest < valOUTWestTest || valOUTEast1 < valOUTEast1Test || valOUTEast2 < valOUTEast2Test)       
  {
    coveredOUT = 1;                                    
  }
//If valOUT is greater than valOUTTest then sensor OUT is covered
  else if (valOUTWest >= valOUTWestTest || valOUTEast1 >= valOUTEast1Test || valOUTEast2 < valOUTEast2Test)                        
  {
    coveredOUT = 0;
  }

}

void checkAllCROSSINGSensors()
{
//Following routine reads valOUT from photosensor, sets valOUTHigh and valOUTLow
//and subtracts the value of lightThreshold from the High measurement to detect the presence of a train 
  valCROSSING1 = analogRead(sensorCROSSING1);          
  if (valCROSSING1 > valCROSSING1High)
  {
    valCROSSING1High = valCROSSING1;
  }                                                 
  if (valCROSSING1 < valCROSSING1Low)
  {
    valCROSSING1Low = valCROSSING1;
  }                                                   
  valCROSSING1Test = valCROSSING1High - lightThreshold;


//Following routine reads valOUT from photosensor, sets valOUTHigh and valOUTLow
//and subtracts the value of lightThreshold from the High measurement to detect the presence of a train
  valCROSSING2 = analogRead(sensorCROSSING2);          
  if (valCROSSING2 > valCROSSING2High)
  {
    valCROSSING2High = valCROSSING2;
  }                                                 
  if (valCROSSING2 < valCROSSING2Low)
  {
    valCROSSING2Low = valCROSSING2;
  }                                                   
  valCROSSING2Test = valCROSSING2High - lightThreshold;
                                       

//If valCROSSING is less than valCROSSINGTest then sensor CROSSING is not covered
//so sensor is given a value of 1
  if (valCROSSING1 < valCROSSING1Test || valCROSSING2 < valCROSSING2Test)                             
  {
    coveredCROSSING = 1;                                    
  }
//If valCROSSING is greater than valCROSSINGTest then sensor CROSSING is covered 
  else if (valCROSSING1 >= valCROSSING1Test || valCROSSING2 >= valCROSSING2Test)                       
  {
    coveredCROSSING = 0;
  }
}

Crossing Signals - Part 3 of 4 - Designing the Circuit

As alluded to in Part 2 of 4 of this series of posts, I used an Arduino Pro Mini to handle the detection of trains and activation of the flashing crossing lights. On September 21, 2021 I discussed a handy tool for drawing wiring diagrams for Arduino circuits. Following is such a wiring diagram showing the wiring of my crossing light circuit on a breadboard. A breadboard is a device into which various electronic components can be plugged without the need to solder the components. This allows for the inevitable tinkering that is required in the design and testing of a circuit. Once one is satisfied with the circuit, a more permanent circuit can be created by soldering the various components together to create the final circuit.


The above diagram shows an Arduino UNO in the circuit. I used an Arduino Pro Mini in my final circuit because it is much smaller (width is about the size of a quarter-dollar coin) and cheaper but it has the same terminals and processing capacity as the UNO.

Note that the photoresistors are wired in series in pairs labelled 1 through 5. Following is a sketch showing which sensors on my model railroad correspond to those in the wiring diagram:


You will note that each pair of photoresistors are those that are physically closest to one another. While the lighting of my layout is fairly uniform, there are likely subtle differences in lighting that are not easily detectable with the naked eye (or even an eye with its clothes on!). As described in Part 2 of 4 in this series, photoresistors are linear devices that vary their amount of resistance to electrical current depending on how much light does or does not fall on them. I wanted the amount of light falling on each pair of photoresistors to be as consistent as possible because the Arduino detects the presence of rolling stock by comparing the amount of current running through each pair of photoresistors when fully lit against the amount of current when shaded by rolling stock.

Please note that I have not always been consistent with my terminology. My use of the words "sensor" and "photoresistor" mean the same thing.

In Part 4 of 4 of this series I will share the Arduino C++ code used to operate this circuit. I used the above breadboard configuration as I tinkered with the logic to make the crossing lights flash as I wanted them to. Once I was satisfied that the circuit behaved as I wanted it to, I recreated the circuit by soldering components to a PC board that is configured the same way as a breadboard. The following are two photos of the final product taken from two sides.


The green, yellow, orange, red and brown wires are those that go to the photoresistor pairs.

The blue, purple, grey, white and black wires all go from the positive side of the circuit to the photoresistor pairs.

The black and red wires (on the left in the first photo and on the right in the second photo) are from the 12 volt DC accessory buss under my layout. The little silver device is an L7805 voltage regulator which converts the 12 volts DC to the 5 volts DC which the Arduino needs to operate. In the first schematic of this blog post, the graphic shows a USB cord that supplies the 5 volts DC coming from the USB port of a computer. This voltage regulator takes the place of the USB cord. Following is a diagram from the Internet showing how to wire such a voltage regulator:





Crossing Signals - Part 2 of 4 - The Methodology for Train Detection

  The following sketch illustrates my track plan (not to scale):


The vertical brown strip depicts the road that passes over two level crossings. The Main Line (also referred to as Track 1) and the Branch Line (also referred to as Track 2) connect via the turnouts located to the East of the roadway. There are 6 possible directions of travel of rolling stock (see yellow arrows in the sketch below):

  • West to east on Main Line
  • West to east on Branch Line
  • East to west on Main Line
  • East to west from Main Line Siding and then on Main Line
  • East to west on Branch Line
  • East to west from Branch Line Spur and then on Branch Line



As my track already has electronic occupancy detection to control the signals (see blog post of December 1, 2020) I decided to use photoresistors to detect the presence of rolling stock. Photoresistors are inexpensive little electronic devices that, when exposed to light, create very little resistance to current flow. However, when the light is turned off (or shaded, as when model railroad passes over it) the level of resistance goes up. Photoresistors are non-polar in that they do not need to be hooked up to positive and negative leads in any particular way. They are analog and not digital meaning that the level of resistance varies depending upon how much light shines or does not shine, on them. Finally, as with regular resistors, photoresistors can be wired in series which means that if two are wired in series, shading one will increase the resistance of the whole circuit and shading both will also increase the resistance of the whole circuit. This is what the photoresistors look like (the head is roughly 4 to 5 mm across, depending on the direction measured - note that two sides are flat):



In order to detect rolling stock travelling from each of the six directions above I mounted photoresistors between the rails, flush to the ties, (called OUT sensors) at the locations marked in green below (sensors are not to scale). The photosensors, along with the crossing lights, will be wired to an Arduino Pro Mini microcontroller. The Arduino programming will be described in detail in Part 4 of 4.



Next, I mounted photoresistors between the rails adjacent to each crossing (called "CROSSING" sensors), as depicted by the blue dots below:




Let's follow a train travelling from West to East along the Main Line.



Position 1 (note the red arrow with the red "1" beside it) - the train shades the first OUT sensor. The Arduino will detect the presence of the train and start the crossing lights flashing. At this point the train could do one of three things:
  1. The train stops at position 1, shading the photoresistor. This means that the crossing lights will keep flashing for as long as the train is parked. This is prototypical. On many occasions I have stopped my vehicle at a level crossing at which the lights are flashing red and look down the track to see that the train is not moving. In this circumstance it is allowable to drive across the level crossing as long as you have come to a complete stop and have checked to make sure that the train is stopped and that it is safe to pass (much light a flashing red traffic light). However, it is not permitted to pass if physical crossing arms are in use at the crossing and the arms are in the lowered position.
  2. The train stops at position 1 and then reverses direction. The crossing lights must stop flashing because there is no longer a need for traffic to be stopped.
  3. The train does not stop but continues on its eastward journey. In this case the crossing lights must keep flashing.
Position 2 - the train has continued its journey and has now reached the level crossing. In this case the crossing lights must keep flashing for the entire time that the train occupies the level crossing.


Position 3 - the train passes over the second CROSSING sensor and, when the last car has passed, the lights must stop flashing.


Position 4 - the train passes over another OUT sensor. As the train has already passed over the level crossing it is important that the crossing lights DO NOT start flashing again. The Arduino needs to be able to differentiate between a train crossing an OUT sensor for the first time and another OUT sensor for a second time. However, once the last car of the train has passed over the second OUT sensor if it were to stop and then reverse direction to pass over the level crossing in reverse the Arduino must start the crossing lights flashing again.



The sequence must operate in exactly the same way no matter the direction of travel or the path followed.

Note that my crossing light design does not incorporate the bell sound. I have seen model railroads with this feature and is nice at first. However, after a while the novelty wears off and ringing bell becomes annoying, at least it does to me. It's my model railroad so I get to decide whether or not the crossings have bells! It would be a simple matter to attach a sound shield to the Arduino and, with some minor programming tweaks, incorporate the bell ringing effect.

In Part 3 of 4,  I'll explain how I wired this contraption.