Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

problems with optical occupancy detection

6097 views
16 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
problems with optical occupancy detection
Posted by gregc on Saturday, November 25, 2017 8:40 AM

I'm looking at optical occupancy detectors.  The detectors would be in the track using room lighting and located near the ends of the blocks.   Doing it this way means the detector is no longer active after the train crosses over it.  A similar problem occurs with electrical detectors without cars that draw current.

one approach to handling this is to recognize that the block has been entered and latch it's state, occupied, until  either detector is crossed again and clearing the block.

Knowing direction would disambiguate whether a train is entering or backing out of a block.  Monitoring the timing as a train crosses a pair of detectors can determine direction.  This may not require any extra detectors if there is one on each of the three legs of a turnout.  Direction can similarly be determined using electrical detectors.

assume these issues aren't novel.  Would appreciate comments

 

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Saturday, November 25, 2017 9:43 AM

I recall we had this discussion a while back,. SOmeone came up with a circuit that does the latching check, I think it had 3 sensors - block entrance, middle of block, and block exit. That way it could handle a train starting to enter a block but then reversing back out instead of continuing through - which given the relatively short distances on a model railroad would be a very common occurence.

Frankly I still feel that if you want to know that there is a train or rolling stock SOMEWHERE in a block, current sense with resistor wheelsets is by far the simplest and nmost reliable option. If you want to know when a train is at a certain spot - like a grade crossing, or past the clearance point to automatically operate a reverse loop, then optical detection is the best option. Some of the downsides of optical detection can be overcome with some clever programming - like the changing light levels on the layout. As long as you are using an emitter/detector pair, between a properly modulated source (and detecting that modulation, not just the level of light falling on the sensor), you can have the thing self-calibrate on each power up (or periodically - so if you run a daytime into night time session, the sensors can adjust as needed) where the controller can adjust the detection threshold so that it should work for all but the most extreme case of someone beaming an IR emitter right into the sensor (replaces the old "drop a coin on th tracks back in the corner" prank). Since I'm planning on making my own grade crossing controllers along with all the other stuff, I plan to incorporate code like this in mine, to automatically calibrate. 

                         --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Saturday, November 25, 2017 10:02 AM

rrinker
As long as you are using an emitter/detector pair, between a properly modulated source (and detecting that modulation, not just the level of light falling on the sensor), you can have the thing self-calibrate on each power up

thanks

can you explain this more?   I'm assuming a photo-transistor/diode pulling down a voltage on a digital input.

greg - Philadelphia & Reading / Reading

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Saturday, November 25, 2017 10:06 AM

I went with hybrid LED/IR optical beam detection. Normal LED optical detection where it can’t be seen and IR where it can be seen.
 
Optical occupancy detection isn’t an easy task!  It requires a lot of patience for perfect operation.  Design and installation is time consuming but once installed it works flawlessly.
 
Straight track is a piece of cake but curving track is a bummer.  I have a pair S curves (double mainline) that took 4 beams each to detect occupancy.
 
My primary tools are a digital camera viewfinder (to see the IR beam) and a 60” steel rod (in my case a vehicular low band two-way radio antenna rod), both to make the beam alignment easier.
 
The biggest problem is hiding the receivers and transmitters.  I found it quite challenging as well enjoyable hiding the detectors.  I have them in trees, bushes, structures, rocks and track side signal cabinets.  I have two long beams over 12’ long covering a hidden mainline and siding.
 
 
 
 
Another slick use of optical detection is across the track positioning for uncoupling over hidden uncoupling magnets or precision stopping a locomotive on a hidden track.
 
Optical detection isn’t for everyone!  I have 14 blocks using optical beam detection on over 110’ of track.  It took me months of alignment, mounting and remounting the detectors so the beams would work with perfection.  It’s been in and working for almost a year without a single problem.  It took lot of time and hair pulling but for me it was worth everythinng it took and it works great!
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
  
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 
  • Member since
    July 2006
  • From: North Dakota
  • 9,592 posts
Posted by BroadwayLion on Saturday, November 25, 2017 11:34 AM

Route of LION has working block detectors. Him uses reed switches in the gauge and magnets on the train, but whatever.

 

Relays of LION are in the RELAY ROOM:

You can see that the relays are in pears. : )

Trip relay 1 and it is latched by the little realy on No. 2.

Trip Relay 2 and little relay 2 unlatches relay 1. Little relay 3 holds relay 2.

Simple so far, yes?

 

Signal 1 shows a RED indication when relay 1 is tripped.

Signal 1 shows a YELLOW indication because relay one is open but relay 2 is tripped.

Signal 1 shows a GREEN indication when both blocks 1 and 2 are clear.

So you can see why I put all of these relays in one place.

 

There is of course a third realy for each block, but that is located on the wayside. It controls power to the PREVIOUS BLOCK, shutting it down when Block 1 in this case is red.

 

There are five conductors to each block from the relay room.

1.   TRIP signal from the reed switch

2.   Display RED Signal

3.   Display YELLOW signal

4.   Display GREEN signal

5.   Closes Track Relay 0 WHEN TIME CLOCK ALLOWS.

The time clock has six (6) ten second intervals, and one of these is assigned to each station. The signal must be NOT RED, and the time clock must inticate GO for a train to leave the station.

 

Railroad of LION can run ten subway trains at once with no living motorman on any train. Layout must have LIVE LION in the 242nd Street tower to keep running, otherwise trains will just run into red signals and the whole thing will come to a stop. Well almost, express trains are on a loop and never come into 242nd street, they will keep on running forever.

 

ROAR

The Route of the Broadway Lion The Largest Subway Layout in North Dakota.

Here there be cats.                                LIONS with CAMERAS

  • Member since
    May 2004
  • 7,500 posts
Posted by 7j43k on Saturday, November 25, 2017 11:35 AM

I am using MSS for signaling.

It uses a straightforward and simple method of block detection.  It works in either direction.

It uses IR optical detectors at each block boundary and a current sensor for each block.  There are no latching relays, or the like.  At least, I surely don't see any.  And I'm using it.

Resistors on wheelsets are not needed.  

 

Assuming an empty block:

When a train enters a block, the train will trigger an optical sensor.  As long as the train covers the sensor, it will say "occupied".

As soon as a locomotive enters the block (right away, in the current description), the current sensor will say "occupied".  This is especially useful if you are running a short train, like a gas-electric.  Or even a light loco.

When the train leaves the block, the train will trigger an optical sensor.  As long as the train covers the sensor, it will say "occupied".

 

Thus any part of a train is always sensed when in a block.  And when no part of a train is in the block, it is clear.

 

Ed

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Saturday, November 25, 2017 1:41 PM

RR_Mel
Optical occupancy detection isn’t an easy task!  It requires a lot of patience for perfect operation.  Design and installation is time consuming but once installed it works flawlessly.

What makes it difficult?

I bought some photo transistors and was disappointed that they didn't source enough current to work with an Aduino input with a (~10k) pullup.  I eventually realized that the photo transistor i bought were most sensitive to IR at 980 nm.  The range of visible light is 400-700 nm.  The photo transistors were about 75% sensitive at 700 nm and 50% at 600.   Not a huge difference.

I found that a 470k pull-up seemed to work ok.   But because of Randy's suggestion for auto-cal of the detectors (eager to hear more) I used the analog inputs and found a threshold of 600 to work ok.

I also found the thread discussing Robert Frey's detector circuit from MR october 2009 (http://cs.trains.com/mrr/f/744/t/160848.aspx).   I also tried adding a transistor to the photo detector but feel the larger value pullup is all you need.

while current sense and resistor wheels may be the most reliable, it seems to require more effort and more expensive circuits.   While I've built current sense detectors, I think multiple photo detectors and the right software may be simpler.  And keeping things simple is important to me.

still interested in comments re: pitfalls

thanks

greg - Philadelphia & Reading / Reading

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Saturday, November 25, 2017 2:15 PM

gregc

 

 
RR_Mel
Optical occupancy detection isn’t an easy task!  It requires a lot of patience for perfect operation.  Design and installation is time consuming but once installed it works flawlessly.

 

What makes it difficult?

 

 

My problems were with alignment not the detector circuitry.  My mainline is dual track at 2¼” center to center spacing.
 
My problems were crosstalk between beams because of the close tracks.  The actual detection was straight forward.
 
Using the emitters at the end of a 4” x 3/16” ID tube helped condense the beams to avoid crosstalk.  With a super thin beam alignment becomes critical.  Hiding them made it even more difficult.
  
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
  
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 
  • Member since
    August 2006
  • From: Greendale, WI
  • 108 posts
Posted by Robert Frey on Monday, December 4, 2017 9:07 PM

Hi Greg,

 

 

 

Yes, I have problems with room light with the incondesdent lights or day light.  ( They also work in the 940 IR range.)

 

 

 

The EMITTER IR 940NM 50MA RADIAL is rated for 50 ma. Max. I now push it to 100 ma, using ½ a sine wave of 6.3 volts ac rated transformer, and using a RES 75 OHM 1/2W  This produces very strong 940 IR pulses.   The senility resistors on the TRANS NPN DARL is greatly reduced, which really helps eliminate this problem.  The covering and a small 1/16” dia  hole near the PHOTOTRAN face, also  helps.  Your IR beam must reflect at the proper angle, to enter the 1/16” dia. hole.

 

 

 

My file; IR for G gage

 

https://1drv.ms/b/s!AojWr5mOt5h3sC1ktJEAXEW8R5UF

 

 

 

 

 

Bob  Frey

 

Website: http://bobfrey.auclair.com

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Tuesday, December 5, 2017 5:10 AM

while i've been successful developing Arduino SW to determine which block a train is leaving and which is entered, i've found that my infrared detectors don't work very well and I have to illuminate them with a desk lamp.

i'm considering adding a track mounted infrared emitter, idealy only one between the pair of detectors, but don't think the angles would work very well.  Obviously, pairing each photo transistor with an emitter should (?) work (albeit with Robert's comments)(maybe some self-calibrating since I'm using analog inputs).

however, since i use an LED ceiling light in my train room and i wonder if the 980 nm detectors would work better if I put back the incandescent bulb.   The graphic below illustrates that incandescent bulb output much more infrared than visible light and I don't believe white light LEDs emit much infrared at all.

using white light LEDs in train rooms would also minimize interference with pair infrared emitter/detectors that Robert uses.

 

btw, i found Ed's mention of the MSS system very interesting

greg - Philadelphia & Reading / Reading

  • Member since
    February 2001
  • From: Wyoming, where men are men, and sheep are nervous!
  • 3,392 posts
Posted by Pruitt on Tuesday, December 5, 2017 5:56 AM

I used IRDots (infra-red optical detectors) for my hidden staging yards on my old layout. I don't remember the specific brand, but I got them from MicroMark (they don't carry them anymore, it seems).

They were easy to install, and pretty foolproof in that, once adjusted properly, they were very reliable. You might give them some consideration. They were a bit pricey, though - as I recall, about $22 each back in 2005.

They were designed to mount under the table, with the source and sensor side by side, sticking up through a slotted hole between the ties. When rolling stock passes over the detector, the IR beam is reflected back to the sensor, triggering the indicator. There was a small, adjustable delay in the reset (half a second or so works great) so that the indicator wouldn't flicker between cars.

The only issue I had was a false occupied indication after I put the first sheet of foam down for scenery above the staging yards. The foam was about six inches above the tracks, and it reflected enough of the beam back that the sensor could see it! Easy fix - I glued a small square of sandpaper to the bottom of the foam above each detector. The sand scattered the beam so there was no reflection back to the sensor. Never had any other problem.

I'd provide manufacturer info and such, but the detectors are 650 miles away for the next few months.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Tuesday, December 5, 2017 7:45 AM

 I'd stick with the LED lights for the room and fix the problem by using some IR emitters. At the bare minimum, modulate the emitters and detect that same modulation - the driver can be a simple 555 circuit, or a PWM output fromt he same micro that is doing the detecting. That helps out with blocking interference as interference would be either unmodulated or at 60hz if coming from a light fixture, so long as your IR modulation frequency is not harmonic of 60Hz. 

 I still like the addition of auto calibration. I need to fool around with code for doing that. 

                             --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Tuesday, December 5, 2017 8:56 AM

Brunton

I used IRDots (infra-red optical detectors) for my hidden staging yards on my old layout. I don't remember the specific brand, but I got them from MicroMark (they don't carry them anymore, it seems).

They were easy to install, and pretty foolproof in that, once adjusted properly, they were very reliable. You might give them some consideration. They were a bit pricey, though - as I recall, about $22 each back in 2005.

 

I went with Vishay TSOP 1738 & 4138 IRDs.    
 
 
The TSOP 4138 is much smaller and easier to hide.
 
 
I bought an Arduino Transmitter Module to modulate the 100ma emitters.  The module is only a 50ma driver so I used it to drive a 33 watt IRF510 MOSFET up to 5 amps. 
 
 
I have 27 emitters most driven at 50ma.  Long beams (10’ to 13’) are running 80ma.  The current is running under 2 amps at 5 volts for all the emitters.
 
 
Once the beams are aligned they work perfect.
 
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
  
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 
  • Member since
    May 2004
  • 7,500 posts
Posted by 7j43k on Tuesday, December 5, 2017 9:49 AM

I have installed this as my between-the-rails optical detector:

 

http://www.iascaled.com/store/ModelRailroad/CKT-IRSENSE

 

It has been 100% reliable in several Free-mo setups.  I know of others who have experienced the same results.

 

 

Ed

  • Member since
    August 2006
  • From: Greendale, WI
  • 108 posts
Posted by Robert Frey on Wednesday, December 6, 2017 3:47 PM

Digi-Key  754-1600-ND        EMITTER IR 940NM 50MA RADIAL            $3.12 per 10

DC Forward Current  50 mA    Peak Forward Current 1.2 A Electrostatic Discharge  (1/100 Duty Cycle, 10μs Pulse Width.)

Now I use a ½ Sine wave of 100 ma,  4 ms on and 12 ms off.  (Now shine this 940NM beam on a 1/16 inch dia. hole above the face of a PHOTOTRAN 160-1030-ND, that is 3 to 6 feet away! )   Sensitivity 56K, then amps = 1 v / 56000 = .000 018 amps to the resistor, is an approximate turn on point.

My reflective target is a round black tank car in HO scale.  The red led appears to be on, (60 pulses per second), when this car is present.

Want more try:  200 ma Pulses ,  1 ms on  and 15 ms off.   Keep going to 38KHZ Pulses and use a 100 ma on and no more problem?   

Digi-Key Part Number  TSOP4138-ND      $6.40 per 5  

Manufacturer Part Number  TSOP4138

Description    PH.MODULE 38KHZ S.VIEW 

 

Bob Frey

Website: http://bobfrey.auclair.com

  • Member since
    February 2002
  • From: Mpls/St.Paul
  • 13,892 posts
Posted by wjstix on Thursday, December 7, 2017 12:06 PM

7j43k

I am using MSS for signaling.

It uses a straightforward and simple method of block detection.  It works in either direction.

It uses IR optical detectors at each block boundary and a current sensor for each block.  There are no latching relays, or the like.  At least, I surely don't see any.  And I'm using it.

Resistors on wheelsets are not needed.  

 

Assuming an empty block:

When a train enters a block, the train will trigger an optical sensor.  As long as the train covers the sensor, it will say "occupied".

As soon as a locomotive enters the block (right away, in the current description), the current sensor will say "occupied".  This is especially useful if you are running a short train, like a gas-electric.  Or even a light loco.

When the train leaves the block, the train will trigger an optical sensor.  As long as the train covers the sensor, it will say "occupied".

 

Thus any part of a train is always sensed when in a block.  And when no part of a train is in the block, it is clear.

 

Ed

 
This 'hybrid' method is extremely clever - kind of the best of two different methods. I never would have thought of combining them like that!
Stix
  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Saturday, December 9, 2017 3:08 PM

i replaced the room light with an incandescent bulb and the paired-detectors and algorithm seems to properly detect a train entering a block when the train starts crossing the detectors and clears the block being left once the end of the train passes the detectors.

this seems to confirm what I said earlier about the spectrum of a incandescent and LED (and CFL) bulb.   It also convinces me that block detection can be done fairly reliably (not bullet-proof) inexpensively with a pair of IR photo-transistors, resistors and software.

the software uses a state machine to determine when a block is being entered and existed.  A table entry identifies the pair of detectors, tracks the paired-detector state and the two adjacent blocks.

a separate table identifies the signals affected by a block being occupied.   No logic is changed to add additional paired detectors and blocks.

 

i'm still interested in using an IR emitter embeded in the track and recognizing a car when the detector senses the IR reflection off the bottom of a car (instead of light being blocked).   I'll replace the incandescent room lamp to minimize interference.

And still thinking about Randy's suggestion for auto-adjusting the detection threshold (using analog inputs).

greg - Philadelphia & Reading / Reading

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!