Detecting Individual Cars

Wondering if anyone has found a reliable way to detect individual cars passing a fixed location on a layout (so I can count them with an Arduino as an example)? I’ve tinkered for quite some time with a variety of IR devices, some home-brewed and some MR products such as Azatrax. Continually run into problems with the variety of shapes to detect as well as colors (IR doesn’t get along accurately with black for instance) as well as geometry challenges (cross track, reflective, between the rails, etc.) “Occupancy detection” is not what I’m looking for. Perhaps someone that is also a robotics hobbyist has some guidance what with all of the type of sensors available nowdays that I am totally unfamiliar with. Thanks, Geoff

Have you tried RFID tags like the prototype uses?

someone described a block occupany approach that counted wheels. An IR emitter and detector were mounted just above the rails.

this approach might work for you if you made some assumptions above wheels per car or the time between wheel detections.

have you tried a emitter mounted between the rails with an detecter on a pole just off the track that won’t be blocked by a coupler?

If you are using an IR detector that “bounces” light off the cars, then the color matters. If you use an IR detector “gate” then that’s not a problem. You put the IR emitter on one side of the tracks/car and the IR receiver on the other. The physical object blocks the IR beam.

You probably won’t be able to use commercial circuits because most of them are designed for occupancy, so the detection is “on” for a few seconds, rather than just when the beam is blocked.

several years back i had a car counting system that used dark on ldr that turned a transistor on that was wired to a relay type counter. worken ok as long as the train was going slow , was going to try upgrade it to a electronic counter , but that got lost in the other projects that were more important.

I would go with an over head to between the rails IR beam break detector. Off set the beam so it misses the couplers. It could even be angular from the middle of the track to the side, enough so that it would catch the bottom of each car.

I’m going to be using the Arduino FC-51 IR Obstacle Detectors (reflective) for my signal system. I only have one block installed and the detectors would count cars. All of my rolling stock and locomotives are black on the bottom and so far it’s working great. I have the modules pointed up an inch below the ties through the ties reflecting off the bottom of the cars. I spaced them at 16” for higher detector resolution, I’m using one second delay on each Arduino detector input. The FC-51 has no delay so it’s very fast. So far so good.

I have a few detectors mounted vertically with the LEDs bent 90° pointed across the track reflecting off the cars 2” from track center at coupler level, they work great that way in hidden areas where they can’t be seen . . . much easier too.

I use a three pin female Arduino type connector so that they just plug in. I mount the hidden sockets in an elongated ⅛" hole in the layout plywood base.

Thanks, jr, for your reply. Had considered RFID a couple of years ago and it got a bit pricy and complex. A quick look around today shows a lot of additional variety in micro-chips, and readers as well, which could be worth another look. Main drawback is applying chips throughout my roster and needed benchwork mods for mounting readers. Also concerned about proximity of other chips in cars on adjacent tracks being read. Doesn’t appear to be an ap for near field reads.

Thanks, too, Mel for your update on the FC-51 based IR detection with Arduino. Looks like tricky geometry as well. Trying to avoid cross-track methods in visible scenery areas to have to hide. Like your under track reflective mode for car under surfaces. Concern would be tricky sensitivity to sense cars overhead but ignore the coupler as it goes by. How could I get somethingto “see” just the trip pins? Maybe paint the tips silver or grey (somewhat prototypical) and look for color capable detector?

The FC-51 module has a sensitivity pot and the specs say up to 30cm but for my use max is about 3” between the ties. I tweak the pot sensitivity to a bit more than tripping on an Athearn passenger car. The two LED/Emitter are centered between the rails and at that setting it doesn’t see the couplers. The modules don’t have a built in delay so they’re very fast, easily count cars.

I used a 9/64” bit to drill four holes between the ties (code 83) then wobbled it to elongate the hole (¾" plywood). I then used a Dremel 194 bit to enlarge the bottom of the hole to except the LED/Emitter.

Installation is very easy, paint the inside of the hole black (I use black ballast) a 1” angle bracket from a big box store, a single screw and some double sided tape and it’s in and working.

You could buy a 1

Great stuff, Mel. Thanks. Perhaps there is still an opportunty to use IR. I’ll sure experiment with one of these. Did you have to bend the emitter / receiver toward each other at all or do they both point straight up? I see the beam width is 35 degrees. Also, why couldn’t I run the output lead right over to an adjacent Digitrax DS64 input for detection since the output goes low and skip the Arduino?

Depends on how fast the DS64 reacts - there will be only a very short time between cars that the IR sensor will be clear. That’s also goign to generate a lot of Loconet messages, possibly causing bus issues - like when using repeated on/off packets to make a signal indication flash. It’s fine if you are monitoring a spot to see if a car is set out there, but for counting - I would keep that off the Loconet. We had to run a second Loconet just for signals ont he club layout, because of all the flashing aspects (guy who runs the signal department on a local regional set it all up, following current NORAC rules) and with old Loconet signal boards, the hardware was mostly dumb and did little more than listen for Loconet messages in a given address range, so to make a signal indication flash, JMRI literally had to send on-off-on-off continuously until the signal went dark or changed to a different aspect. 4 or 5 places of this happening caused noticeable delays in throttle response, so the signal system was split out to a dedicated Loconet. Modern interfaces has built in flashing aspects, so you just tell the board “flashing yellow over red” and the board does it, without a constant stream of Loconet commands.

–Randy

The FC-51 module is pretty flexible. Out of the package it looks like the picture above but it’s easy to bend both the sensor and emitter 90°. If one wants break beam type detection the emitter is easily remoted with two wires but remember the output will be inverted.

I went with 1N914 diodes (price) so that I can use the detectors for other things as well as my signals. They work very good as a parking indicator for my hidden sidings and a clearance indicator for hidden turnouts.

The thing I like the best about the FC-51 module is their simplicity, essentially they are plug and play. I power them of a +5 volt bus and bring the switched output back to my controller. Add in that they just plug in to a standard three pin Arduino type socket they’re great, and they only cost 50¢ each or even less in quantity.

Mel

Hey Randy - good to hear from you - you solved a problem for me several years ago. Meanwhile, I have pretty good results now using the Azatrax devices which I had them modify for me for zero (0) time delay. Given the interrupt driven software I use (TrainController) I’ve never had a problem with the DCC/Loconet side of the detection equation. On the IR detection reliability / accuracy side, not so much. I have my present IR devices trackside in reflective mode and hightly tuned and aimed and usually flawles until - you guessed it - I’m demoing automated coupling / uncoupling operations for others. Usually its a previously untested car in the consist, a pair of too closely coupled box cars (unwanted reflections of IR off of the car ends), a depressed center flat car with no load passes by, etc. You get the idea. I had tried under the track IR before but couldn’t hide the coupler. I think the ability to adjust detection sensitivity with the FC-51 in Mel’s solution may be a breakthrough. The Azatrax and home built devices I’m using now do not have that capability and the obstacle detectors available today weren’t available when I built my layout for sure. I have generally dismissed ‘across the track’ sensing for a number of the same problems described above plus the fact the arrangement of emitters / detectors intefere with prototypical yard scenery. You can only pile up so much foliage and busted up pallets to hide them. Stay tuned – I’ll report my findings to this thread as I go.

Well, still no joy. I picked up an FC-51 and set it up breadboard style using the track on my workbench and have, so far, not found it to be any more effective than the Azatraz and home brew detectors I’m using now. Using the under-track mounting arrangement Mel describes I found it to be extremely sensitive to positioning and sensitivity adjustment to detect just rolling stock vs. a coupler passing by. Same trouble with box cars - lots or beam scatter bouncing off of car ends causes false indications. No sooner than I get it adjusted to work in that situation then I run a hopper car by and it fails because of all of the under car geometric shapes reflect the IR beam everywhere except back at the reciever. Next, after more adjustments to compensate for that, I run a totally black tank car by and it never senses it at all. I’m sure the FC-51 holds promise for some applications but the precise mounting required for my needs in difficult to reach layout areas doesn’t seem practical at the moment. Surely there is a better solution. The brewery up the road sure doesn’t have a problem counting bottles of product streaming past the capper at thousands per hour.

The FC-1 will work as a break beam by remoting the emitter. That will invert the output. I have successfully hidden the emitters with the sensor between the ties and the emitter in a tree.

The break beam will work for quite a distance. You could put the sensor at ground level pointed up at a 45° to 60° angle with the emitter a couple of feet away. At 24” the alignment is very broad.

Early on I used IR beam break across the track detection at coupler level for my crossing gates. I angled the beam across the track because I didn’t want it to drop between cars. I got quite good at hiding them.

There are several pictures on this blog post of the way I hid them.

https://melvineperry.blogspot.com/2014/06/june-4-2014-logic-rail-gcp.html

I used all kinds of things to hid them, but once installed they haven’t required any realignment. My great grandkids think I’m a magician, I won’t tell them wh

Thanks again Mel for your additional input. Out of town for a couple of days but I’ll get back to experimenting with more geometry next week. You indicated in your 02/09 reply that the FC-51 was aimed straight up so I’ll try the angled approach. Still troubled about how to handle lack of reflectiveness of all black cars and locomotive underbodys. Appreciate more details for across the track sensing but tough to do in desert scenery. Else I need to add taller cactus. LOL Also, the FC-51 uses 5mm LEDs while the ones I use now are 1.5mm and much easier to camouflage.

I have substituted 2mm emitters and sensors on the FC-51 and I can’t tell any difference, both work OK.

Actually they are pointed up, I’m not very agile and working under my layout isn’t easy. I use a creeper and my layout is at 33”, working at arms length. Looking closely they vary from straight to about 15°. Like I said they see everything but my log cars. I don’t have many cars, less than 50 total not counting my log cars. I have several Athearn tank cars and a Walthers twelve car work set. Eight Athearn cabooses and about a dozen miscellaneous freight cars. As part of my old timers I have MDC 28’ shorty coaches, long and short log cars and six MDC 22’ shorty hoppers. They work great on twenty Athearn passenger cars. All eight detectors mounted through the ties catch everything but the log cars. None see the couplers.

Using my hand above the detectors they trip at about 3”.

I have 8 mounted vertically in hidden areas with the emitter and sensors bent at a 90° angle pointed across the track at coupler height and I had to crank them down so that they wouldn’t see the parallel track at 2” centers.

I spent about an ho

have you tried an IR emitter/detector above/across the rails just above coupler height to detect the gap between cars, as well as the coupler assuming it’s with the gaps?

i read that putting heat shrink tubing around detectors to minimize their aperature is sometimes required.

You might try the FC-51 with 3mm IRs, I replaced the 5mm with 3mm in one and it increased the range from 4” to over 12” on my workbench. My bone to bone knee isn’t doing good so I’ll have to wait until I can get my grandson to swap it out for me.

Mel

My Model Railroad
http://melvineperry.blogspot.com/

Bakersfield, California

I’m beginning to realize that aging is not for wimps.

I have to apologize to everyone following this topic! This morning I was running a night test on my layout and the FC-51 detectors didn’t work. After about an hour I finally figured out that my LED room lighting was effecting the operation of the modules. I cutover to LED lighting in our house last summer and they must putout a substantial amount of Infrared effecting the modules.

With the LED room lighting off the detectors do not reflect off black, they work great with anything other color than black with my overhead LED lighting off.

My night running mode is Moonlight from two 19 Watt 4100°K LED Floods and the IR sensors don’t see them at all.

The LED room lighting really affects the sensitivity of the modules.

Rather strange, I’ve been using IR detection on my layout for years without any problems. When I cutover to LED room lighting it didn’t have any effect on my existing IR detectors. Most are frequency modulated but I also have a few non modulated IRs and they work OK under the LED room lighting.

Sorry&n

UPDATE

I have a FC-51 module working on my workbench with the LED room lighting off. I use a 36” section of Flextrack on a 1” x 2” board to test my wheeled goodies at my workbench. I had made an opening for the IR module for testing and by bending the emitter and sensor to have a better focal point at the bottom of the cars it reflects off black and trips the detector, good enough for a block occupancy detector but not a car counter.

This weekend I’ll have my grandson tweak the modules under my layout and report back.

Again, Sorry about that guys.

Mel

My Model Railroad