Geoff Bunza geoffb

Every so often one needs an absolute position detector, rather than a block detector. The best I’ve used employ their own light source, but older designs use Cadmium Sulphide (CdS) photocells and depend on ambient light in the room. Both have driven me crazy with their limitations. This article describes a new design, using ambient light “seen” by the detector in two places – typically between the rails and just to the side of the track. When it notices the track light level fall below the level of the second sensor, it “indicates” the presence of an obstruction (car or loco). The beauty of this “differential” measurement is that it operates over a very wide range of light levels, does not require “aiming” to a target, needs no adjustments, and can be virtually buried in ground covering materials. Oh, …and it works! (I’m always amazed at that!)

4L_3780.JPG   ing_3766.JPG 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 1
Geoff Bunza geoffb

General Criteria

For purposes of both signaling and animation, it is often desirable to know when a moving locomotive, car, or even vehicle has reached a particular point or location. For train/car detection this can take the form of a block detector, which will send a signal (usually electrical) when a loco or car has entered an electrically isolated block of track. This block length can vary to accommodate the largest anticipated train length on a layout. More accurate position detection is sometimes needed, where the absolute position is most important, rather than coarser block detection. This might occur when positioning a train at the end of a hidden staging track, or spotting a car on a loading track inside a building.

Absolute position detectors are often optical detectors, detecting the absence or presence of a light source. Mechanical and magnetic contacts have been used too. Mechanical contacts tend to become unreliable over time, and magnetic sensors require cars to be equipped with small magnets strategically places on the cars and/or locos. Thus, my preference has always leaned to optical detection.

Recently, I have been using IR proximity detectors (seen here in Scale Model Animation 14: Grade (or Level) Crossing Control  https://forum.mrhmag.com/post/scale-model-animation-14-grade-or-level-crossing-control-12198577  )

Detector.jpg 

IR Detector Module

While I’ve tried to be imaginative hiding these in scenery, buildings, behind rocks, dead trees, piles of rubbish, boulders, and “creative burms,” they are a general pain. The obvious solution is to remove the emitter and detector from the board and then rewire them so as to relocate them away from the detector board. This quickly becomes a strain on my already limited amount of patience.

The New Detector

The new Differential Absolute Position Detector (DAPD) uses 6 components, and is relatively easy to build.  It can be used with both DCC and DC train control, and for any scale. There are 2 different versions of the DAPD. The first is designed for very small size, and uses surface mount devices (SMD’s). The board layout is such that it could substitute for a portion of an HO scale track tie, and be disguised (covered) in place. This design is for a single detector.

chematic.jpg 

PD4L Schematic

%20Board.jpg 

PD4L Board

_3780(1).JPG 

PD4L Board

The second version is designed for easier construction, and uses through-hole devices. The board layout is such that it is separate from the sensor that can be placed between the rails, and then wired to the detector board some inches away, nearby.  This detector can support two independent sensors between the rails, to provide two independent detector circuits.

chematic.jpg 

PD6L Board (PT19 Here and PT204 Are Interchangeable; Track PT204's Connect to SENxE &SENxC - Emitter and Collector Respectively)

%20Board.jpg 

PD6L Board

rds_3774.JPG 

_Labeled.jpg 

PD6L Board with Components

The PC Board can be ordered from this board fabricator:   oshpark.com 

The boards are 2 layer boards. OSHPark offers a public service fabricating very high quality, low cost PC boards in low quantities. Download the (Eagle PCB layout) board files (.brd) from here:  

http://www.scalemodelanimation.com/Articles/DAPDetector/DAPDetector.zip

Set up an account at OSHPark (really easy) and upload the board file(s) you want to fabricate and specify the quantity (always in multiples of 3—their rules) either of these will cost $ 3.80 for 3 ($1.27 per board). They accept Paypal and will ship international. I have no vested interest in OSHPark – I’m just a satisfied customer. Please feel free to use whatever fabricator you know. I know of no source for fully built boards. That could change in the future.

The bare boards are shipped “panel-ized” so break or cut them apart. Follow the component diagrams and pictures, to solder the components to the board. Use a low temperature soldering iron or a low wattage soldering iron for these.

How it Works

The detector uses two small ambient light sensors based on a photo-transistor (a PT19 SMD device or a PT204 through-hole part). The ambient light hitting each sensor is compared. When the light level of the sensor between the rails falls below the light level of the nearby sensor, the output of the detector goes low (to ground). The detector can be powered over a wide range of voltage. I have tested mine successfully from about 4.6 to 14 volts. The output normally has a 10K pull up resistor on board, that can be omitted or adjusted to your needs. It is not critical. In fact, I have used 8 different phototransistors (including some surplus ones for which I have no specs) and they all work better than most other optical detectors I have used. Some adjustment may be needed for the two emitter resistors, depending on how different your choice might be. Note well that the emitter resistors are different, to force the sensor “off” under clear ambient conditions. The detector output can drive a LED directly for occupancy detection (the cathode- negative side – connects to the detector output; the anode – positive side – to the same positive voltage powering the detector through a current limiting resistor, which is chosen for LED brightness and supply voltage).

The light sensitivity of this detector is mostly in the same range visible to the human eye. This means the light in your layout room that the modeler sees is what is relevant. I have found that I can lower the light level to be darker than what I would consider to be a “normal” comfort level for operation, and still have the detector working. Likewise, very bright light internal lighting works well too. However, absolutely no light does mean no detection. If you want to place the detector in a lightless tunnel or building, simply add a lighted LED or incandescent lamp nearby and you should enable correct operation. Remember both sensors need to see about the same unobstructed “ambient” light levels. If the sensor not between the rails sees a much lower light level, the sensor may never turn on. If the sensor not between the rails sees a much higher light level, the sensor may always be on. I hope this point is obvious.

Bill of Materials    (with digikey.com representative parts)

PD4L Board:

2 - PT19-21C/L41/TR8     Digikey #1080-1384-1-ND      PHOTOTRANSIST FLAT CLR MINI SMD    0.47
1 - TL331IDBVR   Digikey #296-10168-1-ND        IC DIFFCOMPARATOR SINGLE SOT-23-5     0.59
2 - Digikey #P10KACT-ND            RES SMD 10K OHM 5% 1/8W 0805   0.75 / 50
1 - Digikey #311-5.1KARCT-ND  RES SMD 5.1K OHM 5% 1/8W 0805   0.32 / 25
 
PD6L Board:
4 - ALS-PT204-6C/L177   Digikey  #1080-1019-ND         LIGHT SENSOR AMBIENT 3MM ROUND    0.63
1 – LM2903N    Digikey#LM2903NFS-ND   COMPARATOR DL -40-85 C 8-DIP 10168-1-ND        0.39
4 - Digikey  #CF14JT10K0CT-ND         RES 10K OHM 1/4W 5% CARBON FILM      0.40 / 10
2 - Digikey  #CF14JT5K60CT-ND         RES 5.6K OHM 1/4W 5% CARBON FILM     0.40 / 10
 
The following are used for pull up resistors on the Sensor Outputs typically to +5 Volts or the sensor supply voltage:
2 - Digikey  #CF14JT1K00CT-ND         RES 1K OHM 1/4W 5% CARBON FILM        0.40 / 10

I have found this detector to be more useful and reliable than any other I have used. I hope you find it useful for your modeling too.

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
RossA

Very Interesting

Geoff,

What a novel approach! Do you think the electronics could be mounted under the table and some fiber optic used to send the light to the detectors? It would then be a simple matter to drill a couple tiny holes though the scenery and use some shrink tube to attach the other end of the fiber optic to the detector.

Thanks for all your generous efforts.

Ross A

Reply 0
Geoff Bunza geoffb

@Ross re: Whooley Sensors Ross!

Hi Ross,

Do you realize that the 2 track sensors (tiny (1/8") as they are) for the through hole model can be placed the way you describe. The "visible side sensors" might be able to have a hole drilled in the top and a fiber glued into them-- I have not tried that -- but the through-hole board itself is quite small and you could easily place it a foot away in many if not most cases.

Still -- the fiber is another interesting idea!

Thanks for your kind words too! Have fun! 

Best regards,

Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Eugene Griffin EGRX

Ok...Excuse this question

if it is obvious....

In the PD4L version, would I use R1 and R2 to adjust for different light levels?

Also, am I correct that in a tunnel application, IR LEDs could be used as a light source, maintaining tunnel darkness.

Thanks another great circuit.

Obviously I have spent to many years writing code and missed out on all the fun stuff.

Reply 0
Geoff Bunza geoffb

No Adjustments!

Hi griffine (name?),

Quote:

In the PD4L version, would I use R1 and R2 to adjust for different light levels?

No, no adjustments are needed. Because both light sensors "see" the same ambient light level, they balance each other! This allows it to operate over a wide range of light levels - quite dim to quite bright. The integrated circuit is a "comparator" literally comparing the ouput of the 2 sensors. They are purposely slightly skewed so no oscillations would occur at the normal comparision levels, and to make sure the "normal" reading does not turn the detector on. When the track sensor goes dimmer at any ambient light level, the detector indicates the presence of a car or loco. The detector looks for the difference in light levels, not any specific level. That gives it a robustness in operation unlike other optical detectors.

Quote:

Also, am I correct that in a tunnel application, IR LEDs could be used as a light source, maintaining tunnel darkness.

I will have to go back and check the specs. These phototransistors have a small overlapping range into either infrared or ultraviolet, but I don't remember which or how much. I actually went out of my way not to use IR or UV specifically, because my IR & UV detector experiences were not satisfying because I always needed a device to find out where the emitters and sensors were pointing! Nonetheless, you could intentionally pick out an IR sensitive phototransistor and use it in this detector. Devices also exist that overlap from the visible range into either IR and into UV.

'Hope this helps. Have fun! 

Best regards,

Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
wcrails

Wow, so does model

Wow, so does model railroading have to be this complicated?

No thanks.

Mike

Reply 0
Prof_Klyzlr

Opt-in, not Opt-out

Dear Mike,

No, it (Model Railroading in general) does not _have_ to be,
(not all layout designs, operational schemes, or modellers need electronic detection systems),

but if a given layout design or operation does require optical detection
then one had better be ready to "do the required math"...
(...or have the wallet to buy off-the-shelf commercially-available equivalents at significantly more $$$).

Happy Modelling,
Aim to Improve,
Prof Klyzlr

 

Reply 0
DBodnar

PIC version?

Geoff - great idea!  Thanks for posting.

Since I am something of a microcontroller kind of guy I may try using an 8 pin PIC 12F683 with two light sensors - that would give some additional options via software.

Thanks again!

dave

Reply 0
Geoff Bunza geoffb

@DBodnar Re: PIC

Hi Dave,

Yes, any processor with 2 analog to digital converter capable pins should easily handle this. It would simply have to look for the two 2 light levels to be out of balance -- that is the very essence of the detector. The absolute levels are not really relevant. The imbalance is the key, and why it is really an adaptive detector.

Have fun! 

Best regards,

Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Dave

Hi Dave,

That's great! and mighty quick on the draw!  You can roll the entire grade crossing control with detectors on a single small module! I think I'll have to update my old Grade crossing article! Neat!

Have fun! 

Best regards,

Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
DBodnar

Code revision

Geoff - One of the reasons that I love working with such projects in software rather than hardware is the ease of revision should you run into an issue.

For example, I noted that the code I posted earlier worked well in medium to bright light but not so well in a nearly dark room - I did the revision below and now it is equally sensitive in a nearly dark room.

The changes are highlighted.  Basically I created a variable that was more sensitive as the light level drops.

dave

TOP:
adcin PhotoT2, PTRead2
adcin PhotoT1, PTRead1
serout serialout,n9600,["PTR2= ",#PTRead2," PTR1= ",#PTRead1," tr= ",#trigger, " diff ",#abs(PTRead2-PTRead1), 10,13]
' change variable based on max reading
Trigger = (PTread2+PTRead1 )/2
Trigger = Trigger / 5
if abs(PTRead2 - PTRead1 )> Trigger then
high darkdetect
pause 500
else
low darkdetect
endif
'pause 100
goto top:
Reply 0
PilotinControl

PIC/Code

Hello Dave,

I do not use PIC...how hard would this be to use with an Arduino? and the components needed to accomplish this? Thanks - Scott

Reply 0
DBodnar

Arduino

Scott - I am in the midst of putting together programs for both the PICAXE and Arduino - stay tuned

dave

Reply 0
cstalsworth

Another approach

In Free-mo we set up in a lot of different venues and the light is never the same. I have been using infrared detectors successfully by controlling the LED with the Arduino.With the LED off I read the detector and save the value, then I turn on the LED and read it again. You now have two values that can be used to adjust for ambient light.

Chad Stalsworth

Reply 0
MikeM

The genetics of cross-breeding?

Could this device be used in connection with the SMA22 project to address the potential block-spanning issues discussed regarding use of ESTOP to protect open bridges/gates?

MikeM

Reply 0
DBodnar

Arduino Version

Scott- I just finished bread boarding an Arduino version of the sensor - see

http://trainelectronics.com/Crossing_Signal_sensor/DifferentialDetector/

Please let me know if you have any questions.

dave

Reply 0
PilotinControl

Arduino Version

Hello Dave,

This looks very simple to use and should be very reliable than just using 1 photocell....I used one photo cell on my christmas demo layout this past year and a passing train did set off the wrong signal....so comparing two cells should be more reliable correct? - Scott

Reply 0
DBodnar

Comparing two light readings

Scott- I agree that the unit with two sensors should be more reliable - Time will tell if that is the case!

dave

Reply 0
Jim at BSME

Makes sense

Comparing the light under the train to the light beside the train seems to make perfect sense, and a why wasn't that thought about before kind of thing.

A question I have about this, does the second sensor need to be far enough away from the track to not be in the shadow cast by the train if the ambient light is at a angle?  In other words is the shadow under under the train darker than the shadow cast by a train enough to get a comparison difference?

I have heard of the approach Chad mentioned, read the value of the IR receiver with the IR LED off to get the base ambient IR level.

- Jim B.
Baltimore Society of Model Engineers, Estd. 1932
O & HO Scale model railroading
Check out BSME on: FacebookInstagram
Reply 0
DBodnar

Shadows

Jim - so long as the darkness hits the between-the-ties sensor before the shadow hits it doesn't matter - if the shadow hits first it might not work - that would depend on the trigger value you set in the program.  You could also put both sensors between-the-ties, that way either shadow or full train should trip it.

You will note that the software I posted doesn't care which sensor gets dark first.  As long as the differential between them is sufficient the LED lights.

dave

Reply 0
Geoff Bunza geoffb

Re: Many Comments

Hi,

@Chad -- I don't prefer either IR or UV detectors for the precise fact that you can't see them and they need aiming. Hence, this approach.

@MikeM -- Yes, when I responded to comments in the SMA22 project concerning the block spanning issue I had this sensor in mind-- it would need to be positioned well into the block where the locos would be.

@Jim B. -- If you have sharp shadows you need to only have the reference (second sensor) be placed in a location that is brighter than the area under the car being detected. If the car shadows both the same, you will not get a detection -- and I would consider this a detector failure.

@Dave B -- I would definitely consider a detector indication by darkening the off rail sensor a detector failure. The entire idea is to detect a car over a specific, defined spot -- period. That's simply my definition. You, can define it anyway you'd like. Now on the other hand, putting both sensors between the rails, with intelligent processing behind it opens up the very interesting possiibliity of a car sensor detecting train movement & direction. There would need to be some timing specification for delays and holding the detection state, but it might prove to be a very useful variation. 

Have fun! 

Best regards,

Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
cstalsworth

Infrared sensor

The Jeff,

I agree with you on  the aiming issue I use an Optek OPB704 that has the two elements in fixed positions. They both point up at an angle and if the is a car above it the Infrared  bounces back down to the detector The long sides can be filed down to about the width of an HO tie  There is also a WPB704WZ  with wires attached. Prawndesignns.com  makes a laser cut mount so that you can just drill a 3/4 inch hole (preferably before you lay the track) and the sensor ends up at tie height.If you need infrared this is the way to go.

 

img.png 

 

Reply 0
Geoff Bunza geoffb

@The Chad

Hi Chad,

Yup! I completely understand, but this particular sensor requires a specific distance range to the target, which is normally quite close, hence more difficult to hide. When placed looking up (vertically) they can get confused by indoor lighting. I have used them looking down quite successfully in tunnels. Once upon a time i had high hopes using them to literally count axles, but I found they do not respond universally well to different paints, colors and textures of wheels and undercarriages.

Have fun! 

Best regards,

Geoff Bunza

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
galtz99

Arduino Version

Dave,Could you show a schematic and code for the arduino that uses the Pd6l board for two separate circuits.?

Reply 0
Reply