Bi-Direction Block Signals

Scott Eric Catalano Jul 30, 2017

  1. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Hello Group,

    I have come to a roadblock in my programming and I hope someone here is able to figure this out. I have a loop of track and it is separated by 2 blocks. I have a set of signals at the entrance and exit of each block that are red and green. I am using an arduino uno with 4 reflective optical detectors one at the entrance and exit of the block as my crude diagram shows. If going one direction the signals behave accordingly however when I switch directions mid-block the signals do not behalf accordingly. I have attached my code and I think I am almost there. Another set of eyes and more in depth knowledge of coding together will help solve this issue. Thanks for taking a look.
     

    Attached Files:

  2. acptulsa

    acptulsa TrainBoard Member

    3,373
    6,006
    75
    The problem is the system is programmed to remember if the train is running clockwise or counterclockwise, and react differently in each case. So, when the train changes direction, everything is thrown off.

    Try programming it so if A1 is triggered and then A2 is triggered, or if A0 is triggered then A3 is triggered, east turns red and west turns green. If, on the other hand, A2 is tripped before A1, or A3 before A0, west turns red and east turns green. Eliminate all other criteria for differentiating eastbound and westbound from consideration in its tiny little brain.
     
    Scott Eric Catalano likes this.
  3. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    I set it up to do this....and no I have another problem that has crept up.....when passing in either direction the signals alternate twice before settling down to red/green or green/red which is weird....code is below
     

    Attached Files:

    Last edited: Jul 31, 2017
    poolparty1976 likes this.
  4. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    To do what you want to do reliably and work in both directions, EACH sensor must be able to determine the direction of motion of the train.

    To do that you need 2 sensors at each block boundary that are close enough to determine direction based on the sequence of detection, and have all the logic states defined for any possible train motion, such as reversing multiple times in a block.

    I did just the same thing when I wrote code for a system of block detection using IR sensor that counted things/car wheels moving part the sensor, and keeping track of the number of things in a block. The code is not simple, and uses a state machine for detection at each block boundary.

    Look at my posts, specifically one about a different way to do detection........detection allows signaling. The code and HW are posted.
     
    Scott Eric Catalano likes this.
  5. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    So for starters I have a simple loop of track divided into just 2 isolated blocks. You are saying to use 2 IR detectors at the entrance and exit of each block and that will determine direction? Point me to your sketch so I can take a look. Controlling signals, turnouts etc. I can already do. Thanks.
     
  6. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
  7. Rick Camden

    Rick Camden New Member

    2
    3
    2
    What was described is the same principal used to determine direction with a rotary encoder.
    You have sensor A on the left and sensor B on the right. Monitor sensor A and when it transitions (high to low or low to high) immediately check sensor B. If sensor B is high, you’re moving one direction. If sensor B is low, you’re moving the other direction. Do a search for Arduino rotary encoder examples to see how it’s done. The examples will probably have you increase or decrease a counter but if you’re only looking for direction then you don’t need a counter. Also, look for examples that use a pin interrupt. The code is much simpler and faster. Hope this helps.
     
    Scott Eric Catalano and acptulsa like this.
  8. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    Yes, and it's called Quadrature detection......
     
    Scott Eric Catalano likes this.

Share This Page