Pelsea

There are a lot of reasons why we would want to electronically detect the presence of a train. This series of posts will cover a simple method of doing that using a classic circuit published by Richard Schumacher in the NMRA Gateway division website. There will be at least three sections, covering

  1. Underlying electronic principles (Sorry, this can't be avoided.)
  2. Description of the design.
  3. How to actually build one.

pqe

Reply 0
joef

Excellent

Excellent, looking forward to what should be a very helpful thread!

Joe Fugate​
Publisher, Model Railroad Hobbyist magazine

[siskiyouBtn]

Read my blog

Reply 0
Pelsea

The obligatory dissertation on electronic principles

Readers of these tutorials will be familiar with Ohm's law, the underlying principle of the electronic arts. This is based on the observation of three phenomena:

  • Current is a measurement of the amount of electricity flowing in a wire. It is measured in amperes and represented in formulas by the letter I.
  • Resistance is a property of any material that opposes current. The unit is the ohm and the math symbol is R.
  • Voltage (also known as Electro Motive Force) is the strength of "push" that is causing current to flow. The symbol is V (or E) and the unit is the volt.

The only one of these we can easily measure is current (It produces a magnetic field). The other two are arbitrarily defined and bound to current in the famous formula:

Voltage = Current times Resistance. V=IR, I=V/R, R = V/I

There is a little known cousin to the famous big three called conductance. It is the inverse of resistance, its symbol is G and the unit is the Siemens (It used to be called the mho, but that was too undignified for an international standards committee.) G = 1/R, I = GV and so on.

We tend to divide the materials of the world into those with low conductance, which we call insulators, and those with high conductance called (wait for it) conductors. However, there is a third division. There are materials whose conductance varies with voltage. These are the semiconductors. We build devices like diodes and transistors by stacking different semiconducting materials together and channeling current through the junction. Then the current follows Ohm's law in the I=GV version, but since G itself varies with V, the final formula gets V twice, resulting in an exponential relationship like I=kV2 . A device with a single junction in it is a diode, which as you know will only conduct in one direction. Here's a graph to confuse things:

ent_wiki.png [Wikipedia]

Basically, there are four things that can happen depending on the voltage applied across the diode.

  • Large negative voltages will let the magic smoke out. The breakdown voltage is the first number you see when shopping for diodes.
  • With a negative voltage less than the breakdown, nothing in particular happens. This turns out to be surprisingly useful.
  • When the voltage is switched to positive, we see the exponential current flow I'm talking about. Of course, we soon reach a voltage where the curve goes straight up, so all current available flows. Normally, we try to exceed that voltage, which we call the forward bias threshold, or forward voltage drop. If we subtract that voltage from our calculations, plain old Ohm's law on the rest of the circuit tells us how much current will flow.
  • Current flowing through a device heats it up, so if we exceed the power limit of the diode (P=IV) it will cook. Poof.

Of course these things are all over our railroads, as we make current flow in one direction, or apply a bit more than the forward bias voltage to make LEDs light up. But we can also use diodes to detect the presence of current, as I will cover in the next episode.

Incidentally, the diode symbol is seriously messed up.

DiodeSym.png 

By convention, we speak of current as flowing from positive (+) to negative (-), when in reality electrons move in the opposite direction (this was due to a bad guess on the part of Ben Franklin.) You would think that an arrow with a cross through it would mean current won't go that way, but actually it is a drawing of the first diodes, which consisted of a metal point touching a piece of crystal:

detector.jpg 

 The names anode and cathode come from tubes, where the cathode is a wire that is heated and spews electrons. The anode is a plate of metal, and if biased positive relative to the cathode, current will flow.

pqe

Reply 0
Neil Erickson NeilEr

Presence of a train

1. Oh goody, I love presents

2. My O scale engines certainly have presence!

3. I look forward to this thread and promise not post any more silly comments.

In another thread I remembered Rob Clarks use of cheap IR detectors with an Arduino. How will this differ?

Neil Erickson, Hawai’i 

My Blogs

Reply 0
Greg Williams GregW66

Interesting...

Following

Greg Williams
Superintendent - Eastern Canada Division - NMRA
Reply 0
Pelsea

Block detection...

@ Neil-- IR detectors and such only look at a single point on the track. If something casts a shadow on the detector, it reacts. For block detection, we want to know if there is any rolling stock in a given section of track. The prototype does it by applying a voltage across the rails-- any axle on the track will bridge the rails and draw a current. That current throws relays and things happen. Since you are a dead rail guy, you could easily do something similar. Of course, you'd have to isolate various sections with insulated joiners and run feeders to the sections just like the live railers do.

In rail powered systems, we are already applying voltage, either DC or DCC, and we can detect a motor or lighted car by measuring the current draw. That's what this circuit will do. It has some similarity to Rob's circuit in that an LED and phototransistor are involved, but it works by bleeding enough current off to light the LED. That gets tricky on a variable DC system. Stay tuned.

pqe

Reply 0
Neil Erickson NeilEr

Dead Rail

Thanks Pelsea - I have been toying with charging on the rails but only sidings and at stations on the mainline or in the roundhouse. This would really be a five volt power supply from the charger so would have a protection circuit in the charger and not in the engine.

Detecting a car across the rails in these areas with 5V might be a possibility and along the r-o-w where I could cut isolated sections for detection - particularly in staging.

Following along profession so don't want to go too far astray. I'll check your office hours for other questions!

Neil Erickson, Hawai’i 

My Blogs

Reply 0
Patrick 1

Wow

Keep preaching Jedi master.  I want to know what you’re talking about and learn.  This along with my current physics class is just what I need to test out this brain of mine and see what it can handle.  

Keep it up 

Reply 0
Tim Latham

Following

Also following...

Tim Latham

Mississippi Central R.R. "The Natchez Route"

HO Scale 1905 to 1935

https://model-railroad-hobbyist.com/blog/timlatham

 

Reply 0
Pelsea

Designing the block detector

The design of any electronic circuit starts with the same elements as the design of a layout-- givens and druthers.

Givens

  • The purpose of the circuit is to light a lamp when rolling stock draws power from the rails.
  • The current expected ranges from 4 mA to 5 amps-- i.e. one 3.3k axle resistor to an accidental short.

Druthers

  • The operation of locomotives should not be affected
  • Brightness of lamp should be independent of throttle
  • Wiring should be as simple as possible
  • Circuit should work on either DC or DCC
  • Circuit should be simple to build
  • Circuit should be cheap.

The obvious approach to the problem is to steal a bit of current from the track and divert it through a lamp.This would require a current divider circuit with two resistors:

esistors.png 

If there is nothing on the track, no current will flow. Close the circuit with a motor or resistive wheelsets, and there will be current. Note that the resistors will be in series with the locomotive motor. This is generally considered to be a bad thing, to judge by the work we go to providing booster power packs and heavy gauge bus wiring. I didn't bother to calculate values for the resistors (they would depend on the lamp) but the one on the left would be a small value. In fact so small (a couple of ohms), that it would have to be a high power resistor, meaning big and expensive. So the resistive approach is a non-starter.

We can also steal a bit of current by putting a diode in series with the feeder:

%26diode.png 

This will give us a voltage due to the forward voltage drop of the diode. This also reduces the voltage on the tracks, but it won't affect the throttle action much. (I know it'll only work for one direction, but I'll get to that.) The typical Vf of a diode is 0.7 volts or so. If we had a lamp that only needs 0.7 volts, our work would be nearly done, but the smallest I know of wants twice that. So do LEDs. But I can fix this by doubling up the diodes. I'll also make it bipolar:

iodesLED.png 

The resistor doesn't have to be big (maybe 33 ohms) because the voltage there is only the difference between two diodes (about 1.4V) and an LED (about 1.1 V). With diodes going both ways the circuit will work with a DC throttle going either direction, and it will work with DCC too.

There are a couple of practical issues though. First off, diodes that can handle 5 amps are pretty big and cost maybe $0.40 ea. But we can get four diodes in a package called a bridge that takes up less space and cost $0.69 for the whole thing. And do we really want two lights, one for each direction? So here's a design that uses a bridge and encapsulates the LEDs into a single part that can switch a third lamp of any sort.

r%20LED3.png 

The magic part is called an optoisolator. It is the LED/photodiode combination used in IR detectors, but in a single box so you can't drive a train between them. They exist to pass information from one system to another with no actual electrical connection. You will note that the extra LED needs a power supply with ground. That's not much of a problem. We can put all of the indicators on a panel a long way from the block detector and connect everything up with simple pairs of thin wire.

Note that the + and - terminals of the rectifier are shorted together. If you trace the current flow, you will see that this is equivalent to the circuit above, as the current flows through two diodes each way, either D1 and D3 or D2 and D4.

This design doesn't cover all of my druthers, but is close enough to be useful. (For DC it still needs a bit of work.) I'll actually build one of these tomorrow.

pqe

Reply 0
Pelsea

Building the detector

It doesn't take long to put a detector together, as there aren't very many parts. Just in case these posts jump a page, here is the schematic again:

r%20LED5.png 

I'm going to build this on two boards, with the diode bridge and optoisolator on one (detector board) and the LED on another (indicator board). That way, we can develop various indicator designs, including one that will manage a lot of LEDs, something more sensitive for DC, or even something Arduino based.

I chose to build this on a prototyping board that is set up like a solderless breadboard with pins grouped in 5s. Specifically this is a BPS - BR1 from Busboard Prototype Systems, but there are many to choose from. The board is longer than I need so I broke a 2.5" section off. Here's the layout for the detector board:

ctLayout.png 

I decided to use screw terminal blocks to make installation easy. Fry's electronics had some Philmore TB132 blocks on sale, but if your bus wire is bigger than 14 ga, you'll need something beefier.

There's a lot of leeway in the diode bridge. This one is an NTE 5309 (also Fry's). It's rated 4 Amps, but all I'm running is a powerCab. A bigger one (if you really need it) won't take much extra space, and the wires will line up the same, unless you get one of these:

ridge12A.jpg 

In any case, the pins are clearly labeled, so hooking that up would only require rerouting some jumpers.

There is less selection for optoisolators. You need to get one that has AC input. I used an H11AA1 ($0.59 from Jameco). This has six pins, but we only use 4. Richard Schumacher recommends the 2506-1 ($1.39 from Digikey) but there was less choice in 1986. (The 2506 only has four pins. From the spec sheet it would be less sensitive in this application.)

Here's the built board:

BD-04aa.jpg 

If you've never soldered a board together, please look over my Building Simple Circuits thread. That covers basics of construction. There's a lot of room, so the order in which you add parts makes little difference. I put the big items in place first, then the resistor, then the jumpers. Note that the Indicator terminal has Positive and Negative connections. It would be a good idea to mark those with something visible in dim light.

The indicator board is simpler yet:

DLayout2.png              BD-04b.jpg 

Alert readers will note that the resistor does not match the schematic. In fact, you will want to play with it to match the LED and power supply you are using. I start with 1k and work my way down until the LED is good and bright. (This has been amply covered in many threads.) Again, the terminal blocks should be marked.

Here's the whole works wired for testing:

BD-04c.jpg    BD-04d.jpg 

This is a test with DCC. I'm using a lighted caboose as a test subject, but the circuit works with practically anything, including a 3.3k resistor standing in for a single wheel set. However, it is a bit dim with a 3.3k, a problem I'll address in the next installment.

pqe

Questions? Anybody?

Reply 0
Pelsea

Tweaks

As I said above, the simple LED indicator works in most situations, but comes up short reacting to a single wheel set, and is even worse on DC systems. As the voltage across the tracks falls or the wheel resistance rises, there just isn't enough current to light an LED. This system is analog in the low current condition.You get a nice fade in across the Vf region of the bridge diodes, but the indicator will be hard to see in a well lit room. We need to react to the slightest hint of current through our detection circuit. We could reduce the 33 ohm resistor value, but that would risk cooking the optoisolator by a short across the tracks. There are several options based on opamps or comparators like the LM 339, but those are complex and can be finicky to set up. Mr. Schumacher suggests using an old friend of ours, the 555 timer IC

Just as a bit of review, the heart of the 555 is a set/reset flip-flop. If the voltage at the trigger pin is pulled below 1/3 of Vcc (the power supply), the flip-flop is set and the output at pin 3 goes high. (Pin 7 goes low for purposes of discharging a timing capacitor, but we won't use that here.) Pin 6 is called threshold-- if the voltage there goes above 2/3 of Vcc, the flip-flop is reset. (Pins 4 and 5 don't do anything useful here, but we have to connect pin 4 to Vcc and 5 through a capacitor to ground to keep them from affecting the action.)

555.png 

In Schumacher's circuit, the 555 is used as a voltage driven flip-flop. We connect both the trigger (2) and the threshold (6) to a capacitor that is normally charged through a high value resistor. When the detector is active, this capacitor will be held at low voltage by the optoisolator and the output (3) will be on to light LEDs or whatever. When the block clears, the capacitor will charge up and, after a time, shut the 555 off. This arrangement has the advantage of reducing any flicker caused by dirty track.

 

%20555-1.png 

Here's a layout:

DLayout3.png 

Most proto boards have bus strips that run down the edges, and I have put them to use in this layout to carry the positive and negative power. There are a few things to note in this build:

  • The big capacitor is polarized. Most have the negative lead marked-- that's what connects to ground.
  • The cathode of the LED connects to ground, because it is lit by the 555 output going high. Don't trust the length of LED leads to indicate polarity. The flat side is the cathode.
  • I often mount resistors on edge to save room (although this can be carried too far.) Be sure the resistor is snug against the circuit board.
  • The .1µf capacitor between Vcc and ground is not shown on the schematic. Any time you use a 555, there should be one of these as close to the pin 8 connection as possible. Its purpose is to prevent interaction between different 555s that share the same power.

Here is a built board:

BD-05a.jpg 

Again I need to mark the terminals. I usually use a paint pen to get something really visible. The input terminal block is hiding the jumper from pin 4 to Vcc, but it is there. By the way, you can use bare wire for the short jumpers. I only used insulated wire so it would show up better in the pictures.

Here is the system under test:

BD-05b.jpg    BD-05c.jpg 

On the right side the LED is triggered by a 3.3k resistor across the rails. On my DC lash-up, this requires 3 volts from the power supply, putting a bit more than 2 volts on the track (remember, the diodes steal a volt or so). If this is above the stall voltage of your loco, you may need to use 2.2k resistors in the wheels. Of course the more cars in the block the more reliable the indication, and a pulse style power pack (I don't have one to test with) should work as well as DCC.

I'm pretty sure I have my druthers and givens covered. None of these parts costs more than 50 cents or so, except possibly the protoboard, and you have options for that. I'm not going to go into signaling systems since there are already many designs available. If you build one of these, let me know how it comes out.

Have fun!

pqe

Reply 0
barthollis

OK I have a question!

My DCC system has an adjustment I can make that will vary the voltage on the track.  If I were to put your design to use, should I increase the voltage (plus 1.5V) so the track voltage would be as it was before?

Bart

Reply 0
Pelsea

Adjusting voltage...

I wouldn’t bother on my layout, but then I seldom operate above step five. (When your layout is only seven feet long, you don’t hurry.) If you feel you can’t reach the top speed you need, crank it up.

One important item— if you detect one section of track, you have to detect them all. Otherwise, locomotives will change speed when they cross the boundary. You don’t need the entire circuit in dark territory, just the diode bridge.

pqe

Reply 0
cz17west

I've used this circuit for

I've used this circuit for many years, before the opto couplers I used a 1.5volt relay on a old DC layout in the 70's

Currently I use the Vishay SFH628A without the 33 ohm resistor on my DCC layout without any problems. Omitting the resistors gives me more sensitivity, around minimum 6800 ohms to 15,000 ohms. I was concerned about the current through the diode as the max surge current is 2.5 amps for 10 microseconds but after many shorts over the years I have not had a problem, and this is with a old EasyDcc 10 amp booster.

A great dependable detector

Reply 0
Pelsea

Vishay SFH628A

With a forward current surge capacity of 2.5 A, that is one tough opto. The ones I discussed are only good for an amp. I see them at $1.50 from Digikey. Good choice. I'd probably still use a 5 ohm resistor, just because I'm the nervious type.

pqe

Reply 0
Jim at BSME

555 usage

That is neat how the 555 is used to compensate for dirty track and intermittent drops it current, keeping the occupied indication until the track really is empty.

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

Multiple blocks

Thanks Pelsea, fantastic work!

How can I use this on multiple blocks? Should I simple isolate one of the rails ? 

Cheers

Reply 0
Pelsea

One or both...

Whatever is convenient. However, if you only gap one side, make sure that the ungapped rail is connected to the "pass-through" terminals on the detector. That would be the top screws that connect to J1. Gapping both rails can simplify hunting down shorts, as documented plenty of times in this forum.

orWiring.png 

Of course, if there is an auto reverser involved, you must gap both rails. I recommend putting the reverser between the detector and booster, in case the reverser draws enough current to give a false occupied reading. If you want to include the turnout in the same block as the reverse loop (which I think makes sense) you need another detector for the turnout. Two detectors can share the same indicator circuit. 

pqe

Reply 0
bcsanches

Thanks!

Thank you! The drawing is quite clear!

I soon will order the components and try to build my own, this week I hope to start laying down track on my layout.

Best Regards

Reply 0
Eugene Griffin EGRX

I wonder if...

Thanks, this circuit gave me an idea.

I dislike the control of a diesel locomotive's engine sound using a throttle. 

The amount of current needed for the load and the grade determines the rpm of the diesel engine.

So now I wonder if there is enough difference in a models current draw based on load and grade to control the sound of the diesel.

Thanks for this thread and a future project.

Eugene

Reply 0
eastwind

Thanks!

Thanks! Hope to try this someday.

You can call me EW. Here's my blog index

Reply 0
yogiVanBuskirk

Just found this thread, very

Just found this thread, very interesting!

A few questions:

 I would like to adapt this for Arduino inputs, using 5V Vcc on the 555. Do you think the pull up R on the OptoC input would need to be changed for the lower Vcc? Would the 1uF cap also need to be lowered?

Thanks for your project, Bill

Reply 0
JeffRA

Adapting to Arduino

Quote:

I would like to adapt this for Arduino inputs, using 5V Vcc on the 555. Do you think the pull up R on the OptoC input would need to be changed for the lower Vcc? Would the 1uF cap also need to be lowered?

The pull-up resistor on pin 2 of the 555 timer determines how long it takes to charge the capacitor and thus turn off the LED. At 5v it will take longer to charge than at 12v so the delay will be longer. This may not be a problem for you. Alternatively, you could try different values for the resistor to see what works best for you but keep above, say, a few thousand ohms so as to not damage the opto-isolator. You could also use a potentiometer in place of the resistor to find out what value works best but, again, if you do, put it in series with, say, a 10K resistor so that there is a minimum resistance so as not to damage the opto-islolator if the potentiometer is turned all the way down.

On the other hand you could try smaller values for the capacitor as at 5v it is going to take longer to charge. It's probably simpler, though, to vary the resistor instead.

If you are adapting it for an Arduino one consideration is whether you actually need the LED indicator board. You could connect pin 4 of the opto-isolator to ground and connect pin 5 to +5v through a pull-up resistor. The value of the pull-up resistor is not critical; 10K would be O.K. if the detector board was adjacent to the Arduino; perhaps 2K or 4K to give more noise immunity if it is further away. Pin 5 would then go to an input pin on the Arduino. I don't know the characteristics of the detector board output. If it swings enough you could use an Arduino digital input pin and measure whether it is high or low; if it is a more gradual swing you could use an Arduino analog pin and measure the voltage in software. You would need to try it to see what works.

Depending on what you measure you can decide if the block is occupied. To handle track noise you could make measurements over a few seconds and average the result.

....Jeff (N scale, DCC++)

Nova Scotia, Canada.

Reply 0
JeffRA

Further thoughts

After my post it occurred to me that the delay time created by the resistor and capacitor is, perhaps, independent of the voltage supplied. Although the capacitor will take longer to charge at 5v rather than 12v, the 555 timer running at 5v will be switching at a lower voltage than it does when running at 12v and this will compensate.

....Jeff (N scale, DCC++)

Nova Scotia, Canada.

Reply 0
Reply