Skip to main content

HC-SR04 Ultrasonic Sensor

Train Detection Block Signals

I thought I share the use of this ultrasonic sensor, I was able to utilize the sensor in my outdoor dead rail layout as a train/block detection on my layout.

Since converting the Baldy & Palms Railroad to “dead rail” in early 2021, the track detection circuit on the upper loop has been functioning correctly about 80% of the time.  The reed switch circuit would get triggered by the magnets at one end of the block and not at the other end.  This made the circuit go out of sync.  I decided to try several other sensors with the Arduino to find a suitable solution. I tried the current sensor, voltage sensor, relay circuit, and the IR sensor, none of these performed reliably.  

E5AAA3D6-6672-4723-A343-8FA647551FB3CC6447FA-7E70-465F-A3A1-868B85D6BD7A67884DD9-A5F2-4578-9331-ACD003FE76B0I discovered the HC-SR04 ultrasonic sensor and decided to experiment with this sensor.  I also created a better Arduino code with the HC-SR04 sensor.  I adapted the HC-SR04 sensor to fit in a small signal shed to match and blend with the block signal.  The Arduino code is written so the HC-SR04 monitors motion from about 4 to 8 CM across the track. When a train is detected on one end of the block, the signal will turn red, and remain red until the train exits the other end of the block, at which the signal will reset to a clear green signal.  This can be used with two or three aspect signals.  The code just needs a few lines of code activated. The circuit has performed very well, so I plan to incorporate this circuit in other trains detection blocks on the layout. Check out the YT video for the Arduino code sketch and circuit design.   YT Video - HC-SR04 Block Signal

Hope this post helps other outdoor layouts having the same problem and eliminate the need to put magnets on locomotives and rolling stock.

Attachments

Images (3)
  • E5AAA3D6-6672-4723-A343-8FA647551FB3: Approaching upper loop
  • CC6447FA-7E70-465F-A3A1-868B85D6BD7A: Exit upper loop
  • 67884DD9-A5F2-4578-9331-ACD003FE76B0: HC-SR04 sensor
Videos (1)
trim.349B1F13-F9FE-4C7B-B3ED-5CC63BAD6F68
Last edited by sjbuff
Original Post

Replies sorted oldest to newest

@sjbuff posted:

HC-SR02 Ultrasonic Sensor

...

Maybe a typo; I think it's the HC-SR04 (not 02).  For 78 cents (including shipping) I just bought one just to see what it is!  It may not get here for a couple months but oh well!

hc-sr04

If you have a datasheet or something with more technical specs than the typical eBay Asia website provides please post it...

Or a bit more from Amazon with presumably faster delivery...

a bit more on Amazon

Attachments

Images (2)
  • hc-sr04
  • a bit more on Amazon
Last edited by stan2004
@SteveH posted:

Ron, this appears to be a great solution for block detection, especially for an outdoor layout. Thank you for sharing.

Maybe a dumb question as I assume you would have designed it this way... Do your hardware configuration and sketch provide for block occupancy signalling if a train runs in either direction?

I'm curious, would that require you to know the direction the train is running in....how does that work?

@A. Wells Can you please rephrase you question, I don't understand what you're asking.

If my question was unclear, here's another way to ask it.  Since the sensors merely detect a series of 8 transmitted 40kHz pulses reflected back to itself from the train passing in front of it, the sensor itself would be unaware of which direction a train is passing.  The sketch would need to be written in such a way as to turn on the signals when a train enters the detection zone from either end, and off again when it exits.  I don't presently have the knowledge to understand what the sketch does exactly, but this is something I'm considering learning more about.

@SteveH posted:

@A. Wells Can you please rephrase you question, I don't understand what you're asking.

If my question was unclear, here's another way to ask it.  Since the sensors merely detect a series of 8 transmitted 40kHz pulses reflected back to itself from the train passing in front of it, the sensor itself would be unaware of which direction a train is passing.  The sketch would need to be written in such a way as to turn on the signals when a train enters the detection zone from either end, and off again when it exits.  I don't presently have the knowledge to understand what the sketch does exactly, but this is something I'm considering learning more about.

Oh, gotcha!  Like with my crossing gate set-up which requires 4 magic areas.  Two to detect the train entering the outer area from either direction and two to detect when trains leave the gate area.  (I'm still waiting on a magic refill from Mouser.)

I'm assuming I can get away with not having to detect the direction of the train.  However, if I'm going to need to get an estimate of speed, I might as well to report direction.

Last edited by A. Wells

SteveH  and other interested: 

I added the Arduino sketch, which you may use and tweak to fit your design.  Let me do my best to explain how the sketch works with the ultrasonic sensor.  When Arduino is first powered up, the two HC-RS04's are initiated to get their bearing.  The sensors are now pinging outward to a distance of about 100 centimeters.   Same time the block signal is defaulted to a clear GREEN signal.  As the Arduino code runs the loop of code, the code is looking for changes in the distance sensing of both HC-SR04's.  I have written the code so the HC-SR04's are looking for changes between 4 and 8 centimeters. Any object detected outside the parameters is ignored. Once either side of the block (either HC-SR04) detects a object within the trigger parameters, the code will initiate the code for the signal to change a occupied RED signal. 

Now the train has entered into the occupied block section. The signal will now remain in a occupied RED state until the train exits the other end of the block. I wrote the Arduino code to only switch case to  the default clear GREEN signal when the train exits the opposite end of the block. Since I'm using two aspect signals, I needed to transition mode from RED to GREEN, so I added a flashing red sequence for a few seconds until returning to default clear GREEN status.

The train can come from either direction to occupy the block, but in order to clear the block the train needs to exit the opposite side of the block.  Instead of the flashing red sequence, you could add a YELLOW signal for a few seconds before returning to default clear signal.  (This code is in the sketch, but is not active.)

What's happening when the train is in the occupied block, and has pasted one of the HC-SR04 sensors.  The exit sensor is waiting for a object trigger to move to the next case of beginning the default clear signal sequence.  Until the exit sensor is triggered, the block state will remain occupied RED state.

I am also working on a circuit with the HC-SR04 for a grade crossing activation.  With pretty much the same code principals.  They're a bunch of things you can do with this circuit, tie the sensor to a station announcement for instance, or sawmill sounds when approaching a lumber mill siding.  All this is done through the Arduino and a sound board and is activates the animation when a train rolls by.

I hope this explains how I'm using the HC-SR04 to detect trains.  I found this to be good solution to my outdoor o scale layout.  I went with this method, because I did not want to rely on the track continuity to maintain the circuit state.  This way, once the senor is triggered, the state remains same until another trigger and a change of state.

Attachments

This is "other interested".  Do you have any issues with false leave detections  when the open areas between cars pass in front the sensors?  Have you considered using a comparator IC with low and high values (hysteresis) and pots to trigger a signal into the Arduino?  This would make it easier to adjust on the fly instead of having to recompile the code.

Other Interested

What amazes me (I watched your video) is how you methodically experimented with various technologies - optical, magnetic, electrical, and finally acoustic - to arrive at a solution.

My 78-cent free-shipping (!) acoustic module won't get here for months if at all but what I want to see if it's practical for the average OGR reader to apply this.  By that, I think most guys think of the 153IR ($45.99 MSRP) as the standard for occupancy detection when insulated-rail is not an option.  You simply position the 153IR next to the track, apply AC Accessory power, and hook the controlled accessory (signal, crossing gate, whatever) directly to some screw-terminals.  No soldering, no programming, no fuss, no muss!

Remember folks, OGR is a discussion forum and we're in the Electrical section.  So I may be talking to an audience of 1 (myself) but oh well!

In reviewing the datasheet, what's needed is a periodic pulse to trigger the module to send out an acoustic pulse.  This might occur, say, 10 times per second.  The module looks for an echo from the inaudible (ultrasonic) burst hitting a passing train in which case it generates an "echo detected" pulse.  The elapsed time (measured in a fraction of a second) from trigger to echo indicates how far the target is.  A building or other scenery structure on the other side of the track will generate an echo so the "trick" is to measure time to the echo and discriminate (ignore) reflections that come from distant objects (vs. a passing train).  All this indeed takes advantage of the "power" of an Arduino.

What I'm pondering is if it's practical and cost-effective to cobble together a circuit that embeds this 78-cent module into a, say, $5-10 DIY module that emulates a 153IR...without an Arduino.  While the Arduino and the like have been a godsend to the O-gauge community, it can be a daunting endeavor to the average OGR reader.  Likewise, there are many who find soldering or working at the component-level a show-stopper.  I get that.

Last edited by stan2004
@stan2004 posted:
What I'm pondering is if it's practical and cost-effective to cobble together a circuit that embeds this 78-cent module into a, say, $5-10 DIY module that emulates a 153IR...without an Arduino.  While the Arduino and the like have been a godsend to the O-gauge community, it can be a daunting endeavor to the average OGR reader.  Likewise, there are many who find soldering or working at the component-level a show-stopper.  I get that.

It's obviously possible, but I don't know if you'll hit that price target.

This statement in the data sheet is a bit confusing.

When tested objects, the range of area is not less than 0.5 square meters
and the plane requests as smooth as possible, otherwise ,it will affect the
results of measuring.

I hope that doesn't mean they expect that large an object to range on, we'll have to go to bigger engines!

Thanks all, remember my main issue was to get a sensor to function in the outdoor ambient light of sunshine and shadows throughout the day.  Also I am running dead rail, so there is zero track voltage as well.  I tried the 153IR, but did not get reliable results.  The HC-SR04 has been error free since I installed.  I am quite impressed.  I agree for most OGR reader and railroaders, the IR sensor, voltage and current sensors would probably work just fine indoors.   Many in the G scale layout use the reed switch and magnet circuit, but I found this to be not 100%.  I did use this method for awhile until I found this ultrasonic sensor.

I have been fiddling with the Arduino for awhile now, and YES the code and understanding of coding and circuit can be intimidating for many.  I've spend a lot of time learning the code and building circuits, which I enjoy.  Now to apply this to my layout is what I'm working to achieve.  Plans for other circuits are also in the works.

Attachments

Images (1)
  • HC-SR04_block_detection_circuit: Tinkercad circuit

For those who might be interested, here's avideo on the HC-SR04 from YouTube. It's 48 minutes long but fairly comprehensive. It shows how to use the Arduino with this device and provides code to program the sensor in raw form as well as how to program it with a library.

He concentrates somewhat on getting accurate readings for distance measurements including using a temperature and humidity sensor to calculate the speed of sound with more precision.

I realize that this amount of accuracy is not pertinent to this application, but you might imagine being able to differentiate between two trains on parallel tracks.

It’s all in the code, I’m pretty sure code can be written to sense different distance. My code looks for objects within 4 and 8cm. Adding code to sense a different area should be doable. Within the range of the sensor. This will be something I can experiment with.  The video from the Dronebot Workshop is very comprehensive and worth the watch for those seeking more information on this sensor.

...

This statement in the data sheet is a bit confusing.

When tested objects, the range of area is not less than 0.5 square meters
and the plane requests as smooth as possible, otherwise ,it will affect the
results of measuring.

Yup.  That's why I wanted to mess with one.  I'm thinking the 0.5 sq. meter "range of area" is suggesting you don't want interfering clutter that can create false reflections.  Or maybe it means you don't want a separate HC-SR04 within that range because of interference.  The smoothness might be implying the target should be a flat surface perpendicular to the acoustic burst for better reflection.

I see this as part-and-parcel of learning about this "technology."  That is, with the IR technology we've learned how ambient lighting (especially sunlight) can interfere with operation.  Likewise, the IR reflections are better when the passing train is white or lightly colored rather than black or dark.

Last edited by stan2004

@SteveH - This goes back to one of your early comments regarding detecting train direction and block occupation detection.  There is a scenario where you can make a block think it's empty (when it's actually not) by reversing the consist while it's over the "last" detector.  However, I think for most people this isn't necessary and just a matter of pedantics.  For a crossing gate though, it might be a necessity.

Anthony

Sure you can.  The block has signals on both ends, when either sensor is triggered, the blocks is turns RED.  Take it, in my scenario - trains roll through the block, there is no need to stop in the block and reverse back from the entering sensor.  Which if the train did reverse the train back out, the sensor would still remain RED, because the code is waiting for a trigger on the other end of the block.  Yeah a train could roll into the block from the other end, past the RED and trigger the CLEAR sequence.

But this scenario would not always play out, I'd lose my model railroading engineers certificate blowing by a RED signal. haha 😊

My next project is a crossing gate circuit, which has the same theory in mind, a trigger to active crossing gates when train approaches and another trigger when train exits the crossing gate area.  The Arduino code is where all the animation can be controlled.

@sjbuff posted:

Sure you can.  The block has signals on both ends, when either sensor is triggered, the blocks is turns RED.  Take it, in my scenario - trains roll through the block, there is no need to stop in the block and reverse back from the entering sensor.  Which if the train did reverse the train back out, the sensor would still remain RED, because the code is waiting for a trigger on the other end of the block.  Yeah a train could roll into the block from the other end, past the RED and trigger the CLEAR sequence.

But this scenario would not always play out, I'd lose my model railroading engineers certificate blowing by a RED signal. haha 😊

My next project is a crossing gate circuit, which has the same theory in mind, a trigger to active crossing gates when train approaches and another trigger when train exits the crossing gate area.  The Arduino code is where all the animation can be controlled.

I'm curious if you saw my topic on Crossing Gate Regulations from last week?  I want to try to make it as close to real life as possible.  I didn't want the gates to come down right when the train is on top of the crossing.  This wouldn't be good for my tractor trailers.

A. Wells. /No I did not, I’ll go check out your post. My thought is to have the sensor, say 3 feet away from crossing on both sides , and trigger lights and gates to the approaching train, and clear when other sensor detects the train has pasted. Returning gate up and stopping the flashing lights.  I also thought of placing a flashing amber light as the default state, then I know the circuit is working. I’ve seen European crossings with a slow flashing amber light when crossing is clear and moves to flashing red when a train is approaching.  I know not prototypical for US crossings, but it’s cool to see the crossing always active.

I received my 78 cent HC-SR04 and designed a circuit to make it work like the Lionel 153IR or MTH Scaletrax ITAD.

HC-SR04 proof of concept - january 2022

That is, you supply AC Accessory voltage.  You position the occupancy detector on the side of a track.  You hook up the controlled accessory to the relay outputs.  You set the sensitivity/range ... for example to detect a engine across a 2nd distant parallel track.  You set the time delay to keep relay on after train passes.

It works swimmingly and could be done for $5 in jelly-bean components for a well-stocked DIY'er.  My out-of-pocket was just the 78 cents for the sensor module.  I don't recommend you try this at home since it is a lot of component-level assembly and such.  I show the 153IR and ITAD by way of "size" comparison to show the circuit could fit in a trackside cabinet albeit there would be some work to custom-fabricate a housing maybe requiring a 3-D printer or whatever.

But if anyone is truly interested in how I did it, I can elaborate my observations and thinking.

This is a very interesting module which is very widely available and very widely used especially in hobbyist and robotics applications.  Just google HC-SR04 and you will be overwhelmed!

Thank you @sjbuff for introducing this technology to the forum!

Attachments

Images (1)
  • HC-SR04 proof of concept - january 2022
@stan2004 posted:

I received my 78 cent HC-SR04 and designed a circuit to make it work like the Lionel 153IR or MTH Scaletrax ITAD.

That is, you supply AC Accessory voltage.  You position the occupancy detector on the side of a track.  You hook up the controlled accessory to the relay outputs.  You set the sensitivity/range ... for example to detect a engine across a 2nd distant parallel track.  You set the time delay to keep relay on after train passes.

It works swimmingly and could be done for $5 in jelly-bean components for a well-stocked DIY'er.  My out-of-pocket was just the 78 cents for the sensor module.  I don't recommend you try this at home since it is a lot of component-level assembly and such.  I show the 153IR and ITAD by way of "size" comparison to show the circuit could fit in a trackside cabinet albeit there would be some work to custom-fabricate a housing maybe requiring a 3-D printer or whatever.

But if anyone is truly interested in how I did it, I can elaborate my observations and thinking.

This is a very interesting module which is very widely available and very widely used especially in hobbyist and robotics applications.  Just google HC-SR04 and you will be overwhelmed!

Thank you @sjbuff for introducing this technology to the forum!

Stan, can I get the schematic and BOM for this?  I'll create and post a PCB that will make assembly practical for a wider audience if they don't have to do a lot of wiring.

hc-sr04 proof of concept

Image should be expandable.

Here's the theory of operation.  Reviewing the HC-SR04 datasheet first will help.

Timer1, a 555 timer IC generates short pulses 10 times per second to trigger the HC-SR04 to send an ultrasonic burst.  This is the TRIG signal to the HC-SR04.  The HC-SR04 then generates a pulse output whose width is proportional to the distance to the target.  This is the ECHO signal and is a pulse stream at the 10 times per second rate.  The ECHO pulse width translates to 17cm/msec.  So if ECHO signal is 1 msec wide, the target is 17cm away.  If ECHO signal is 2msec, the target is 34cm.  Practically speaking, if positioned on the side of a track, a typical target (passing train) distance would be 5cm away so we're looking for pulse widths around 5cm/17cm x 1 msec = 0.3msec or 300 usec.

Timer2, half of a 74HC123 dual-monostable timer, generates an adjustable pulse width corresponding to the desired sensitivity or range of the sensor.  Since the sensor has a purported range of several meters, it will always be getting an echo from some part of the layout beyond the tracks.  In other words, the ECHO pulse width must be tested to find SHORT pulses meaning the target is only, say, 5-15cm distant.  The test will be to look for ECHO pulse width which are narrower than 300usec (5cm) - 900usec (15cm).  So Timer2 uses a trimpot to generate an adjustable pulse width that covers this range.

Timer3, the other half of the dual 74HC123 does the timing discrimination.  It compares the ECHO signal pulse width to the reference pulse width and if the ECHO is narrower than the desired target distance, it then generates a long pulse that turns on the SPDT relay.  The long pulse is settable in seconds just like the 153IR or ITAD.

It's that simple!  I show in the red circle what an Arduino or microcontroller could do.  You'd still need some kind of power supply to convert Accessory AC to 5V DC that the Arduino needs.  You'd still need some trimpots or method to adjust the distance-to-target sensitivity and the relay delay time.  And you'd still need some buffer to drive the SPDT relay.

Parts list attached.  The only non-jelly-bean (garden-variety) part is the relay.  The HK4100F is widely available and has 3 Amp contacts so plenty for a 153IR/ITAD type application.  Datasheet attached. 

Some effort was made to minimize the number of unique parts.  If your parts cupboard is bare and you're trying to build 1 or 2 to mess with, it will be oh so frustrating since minimum quantities, shipping, etc. will drive the cost thru the roof. 

Again, this is just a proof-of-concept.  I make no claims that this is better, worse, or whatever than any of our existing occupancy detection methods.  I suppose this would most likely be compared to the 153IR/ITAD Infrared methods.  In that regard, I'd think the occasionally reported issues/problems detecting IR/optical reflections off dark-colored surfaces would not be a factor for acoustic reflections.

OTOH, I only got 1 module to mess with, but I'm thinking there may be issues trying to use two or more of these in close proximity.  That is, the HC-SR04 sensor range is claimed to be several meters

Attachments

Not a dumb question at all.  The 5V circuit uses about 10mA when idle and waiting for a train.  Then about 50mA when the relay turns on.  With 14V/18V AC input:

When idle, 7805 input is about 19/23V DC.  So TO-220 dissipation is about 140/180mW; so that's no problem.

When active, 7805 input is about 16/20V DC.  So TO-220 dissipation is about 550/750mW; so yes, it does get a bit toasty but within spec.  So yes, I suppose you wouldn't want to mount the 7805 against a plastic wall or whatever.  Note that the 7805 input voltage drops when relay turns on because "only" half-wave rectification is used.

Believe it or not I thought about that - in trying to minimize the number of different components, you'll see there is another 220uF in the circuit.  220uF worked out well since it is not large enough to maintain the half-wave rectified DC level when the relay turns on and droops about 3V DC or so reducing the TO-220 dissipation by 150mW or so.  Every little bit helps!

Wow!  If you're really considering making a PCB design, keep me in the loop and post stuff here.  I'm sure I'll have comments.  I'd think the biggest stumbling block will be finding/making an enclosure.  The 2 trimpots have to be cleverly positioned for screwdriver access...though these tend to be one-and-done adjustments for a given layout.

Stan, thank you very much for drawing the schematic and posting it here.  Have you done any testing to find out how well the detection works with rounded objects (like tank cars and steam boilers)?

Also, curious about its ability to either detect and/or discriminate between the presence of trains on two or more parallel tracks, if the detector is either placed close to the first track or some distance further away from the parallel tracks.

For example, if attempting to use the detector to activate grade crossing signals for 2 or 3 parallel tracks, would one detector sense the presence of passing trains on any of those tracks and activate the signalling circuit if placed at a sufficient distance from the tracks?

As an opposing example, if the detector were placed close to to a mainline track for detection of a train heading into this mainline grade crossing, but there is also another nearby diverging spur track on the far side ~ 6" away from the closer detected track that doesn't cross the auto road, could a train on the spur be ignored by the detector?

@stan2004 posted:
Wow!  If you're really considering making a PCB design, keep me in the loop and post stuff here.  I'm sure I'll have comments.  I'd think the biggest stumbling block will be finding/making an enclosure.  The 2 trimpots have to be cleverly positioned for screwdriver access...though these tend to be one-and-done adjustments for a given layout.

Stan, you will most certainly be in the loop!  I'm entering the schematic into DipTrace now, and then I'll do a trial fit to see what size PCB will work.  Since I don't have that relay, and I already got bit by low current contacts, I'll be using the Songle 5V relay with 10A contacts.  I may have to improve the 5V supply.

That was fast!

1. Bridge is rotated.  AC inputs are going to the + and - terminals of the bridge.

2. Output of 1st 74HC123 should be pin 13 Q (not Q*).

And how about humoring me and plopping down the pads for the HK4100 relay.  I figure I'll be building one and presumably this shouldn't change the board size which I figure is what drives the raw PCB cost.  I guess you would need to build the part for your library.  In other words, just add a 2nd relay in parallel and the builder can decide which to install.  Note that the HK4100F is the relay used in the Lionel 153IR.

hk4100f alternate

Attachments

Images (1)
  • hk4100f alternate

OK, I noticed that not only was the bridge rotated, but I also left a surface mount part in the design.  But I didn't pick up that I used the wrong output on the HC123, good catch.

I'll have to look at putting in the pads for the HK4100 relay, given the large traces for the 10A model, that could be interesting fitting it in.  I didn't initially consider it as I also didn't have any of them on hand, and the only place I saw them was overseas with weeks of delay.

@stan2004 , I notice that there are two different pinout diagrams in the data sheet for the HK4100F, and they don't have any identification as to which matches what part number.  Which one of these is the "right" pinout?  Truthfully, I can't imagine why they needed two totally different base pinouts for the same specification part...

I'm "assuming" that the first one is the HK4100F and the second one is the HK4101F, but since there is no labeling of any kind on the two sets of base diagrams, I'm not 100% sure that assumption is correct.

 

This is the datasheet for the relay that I have: HK4100F-HUIKE.pdf

Attachments

Images (2)
  • mceclip0
  • mceclip1
Files (1)

Stan and John:

I'm glad that my suggestion on using a HC-SR04 in the model train world is a good idea.  I like how you're looking at ways to use this sensor without the Arduino.  Making a straight circuit with simple distance adjustments can make this sensor even easier to use.  Hats off to you both.  I'm working on a grade crossing circuit, which I'll post once I have finalized the code and sketch.  Thanks again from all us model railroaders. 😊🚂

@stan2004 , I notice that there are two different pinout diagrams in the data sheet for the HK4100F, and they don't have any identification as to which matches what part number.  Which one of these is the "right" pinout?  Truthfully, I can't imagine why they needed two totally different base pinouts for the same specification part...

hk4100f spdt

I see what you mean.  I'm after the 6-pin version.  The 2nd diagram (which I too assume is the HK4101F) has only 5-pins; and if you google HK4101F, pics show it to be 5-pin so I think that clinches it.

Attachments

Images (1)
  • hk4100f spdt
@SteveH posted:

... Have you done any testing to find out how well the detection works with rounded objects (like tank cars and steam boilers)?

Also, curious about its ability to either detect and/or discriminate between the presence of trains on two or more parallel tracks, if the detector is either placed close to the first track or some distance further away from the parallel tracks.

For example, if attempting to use the detector to activate grade crossing signals for 2 or 3 parallel tracks, would one detector sense the presence of passing trains on any of those tracks and activate the signalling circuit if placed at a sufficient distance from the tracks?

As an opposing example, if the detector were placed close to to a mainline track for detection of a train heading into this mainline grade crossing, but there is also another nearby diverging spur track on the far side ~ 6" away from the closer detected track that doesn't cross the auto road, could a train on the spur be ignored by the detector?

Haven't forgotten about you!  I figured I'd first attend to GRJ's efforts since getting a PCB would really move the ball down the field!

No, I have only done bench testing so that I could have all manners of instrumentation handy.  I have found the most useful tool at this proof-of-concept stage is the oscilloscope since I can watch each and every ECHO pulse and see how it changes in real-time as objects come in and out of reflection range.  But I just placed a Hudson boiler, a tennis ball can, and a coffee cup, with the sensitivity trimpot set to look for targets ~10 cm or less and they all tripped the detector within 1 cm of what a flat surface did.

I think it's the notion of setting the sensitivity as X cm or less that is novel. That is, with the speed-of-sound it is practical to  measure "time-of-flight" since the ECHO pulse width changes about 60 microseconds per cm.  Obviously trying to measure time-of-flight for the infrared method means measuring the speed-of-light which would not be practical!  As an aside, I suspect the next sensor idea might be an optical sensor that uses "auto-focus" like technology to estimate distance to objects.

Anyway, if parallel O-gauge tracks are, say, 10 cm apart (600 microseconds change in ECHO pulse width) it is not hard to imagine this amount of timing change can indeed be reliably discriminated.  I don't know if there's any application for this, but the "X cm or less" sensitivity setting means if you have 2 or more parallel track, this ultrasonic method can be reliably set to only trigger on the closest track (or the two closest tracks) and ignore anything further away.

As mentioned, the big unknown is the ability to use 2 or more of these in close proximity since the ultrasonic bursts are just sound waves and sound scatters rather well in air - unlike optical beams which stay in their lane.  Of course a downside of the ultrasonic method is it would NOT work in a vacuum whereas the optical method would!

I guess all that can be said so far is it's early days and we're trying to catch up to @sjbuff and his ground-breaking work!

GRJ, I did not see the part number of the trimpot but wanted to confirm it increase R with CW turn?  Measure-twice, solder-once!

Also, it looks like the 1uF capacitor after the 7805 disappeared?  I'd like some "bulk" capacitance on the 5V supply line near or midway between the timing IC chips even if your 3-pin regulator a small cap on the output side.

Stan, good call on the pots, I'll check again and make sure the rotation is correct.  One final thing I have to do is create a BOM once we think the design is laying flat.

As for the power supply, I used my switcher, but the same holes and pinout fit the LM7805.  There's room for that with an optional heatsink if so desired, so I think we have all bases covered.

I added two .1uf caps right across the two chips, my chosen method of bypass in most cases.  I got the second relay component mapped out and configured on the board.  I was having trouble putting it on top of the other one, so I just stuck it beside it.

I'll make sure about the pot connections and then post all the files again.  Here's a teaser of the 3D view as it stands now.  This should be as it looks completed, the wiring of the pots shouldn't change anything about positioning.  Too bad I didn't have a 3D model of the HC-SR04 to complete the picture...

Once we like the total design, I'll order some PCB's.

Attachments

Images (1)
  • mceclip0
@stan2004 posted:

Any way to place some mounting holes in the corners - maybe for #4 screws (holes about 1/8") ?

I don't know what 3D format you need, but if you google it there are downloadable 3D models of the HC-SR04.  For example:

hc-sr04 3d model

Stan, I could certainly look into some mounting holes, totally forgot about that option.  As for the 3D models, it has to be in a format that DipTrace imports.  The 3D modeling aspect is something I haven't spent a lot of time on as most of the stuff I do I can create a suitable model from existing parts.

Take a close look at the schematic if you will and make sure we're all laying flat there.  I'll make any other changes we need and put some holes in the corners for mounting posts.

Stan, Thank you for answering my questions about range and adjacent tracks discrimination.  John, thank you for working up the PCB layout.

Maybe something else to consider.  I'm wondering about the scenario of using this module for crossing gates and the benefit of having two detectors, one on each side of the grade crossing for trains approaching from either direction.

Also there is the notion of using this for block detection and having one or more additional detectors within and at the other end of the block.

Would it be possible to provide one or more inputs just prior to the relay trigger so that outputs of multiple modules could be wired together to activate the relay?  I see some advantages to this approach vs. just wiring the relay outputs from multiple modules together.

This may or course require a buffer between the Q2 output and the junction of D3 and the Relay coil.

Thoughts?

Last edited by SteveH

Stan, I'm ordering this from JLCPCB as it's six square inches and $30.  The whole order of 30 boards shipped DHL is $57, much easier to digest than $30 for three!  I'll send you some boards when I get them.  If you have a hankering to order some from OSHPark, here's the Gerber files.

HC-SR04 Ultrasonic Train Detector Gerber.zip

Attachments

What are you going to do with 30 boards?

I realize that's "only" $2/board but I really think just a few boards, even if $30 at Osh Park for 6 sq. inches, will help to get our arms around the packaging.  I really think the enclosure will be a stumbling block and should/will drive the board layout.  Again, I will gladly pay the $30 ($10/board) and send you 1 to mess with...

Well, the order is in, Since the DHL shipping was the lion's share of the order, I just bumped it from ten to thirty.   Too late to make a change on this one.

I also wanted 2oz copper for the relay traces, and with OSHPark you have to go to the thin board for that option.  This isn't a candidate for thin boards, at least IMO.

Last edited by gunrunnerjohn
@SteveH posted:

...
Maybe something else to consider.  I'm wondering about the scenario of using this module for crossing gates and the benefit of having two detectors, one on each side of the grade crossing for trains approaching from either direction.

...
Thoughts?

So my thoughts are:

1. The 5-wire crossing gate.

2%20or%20more%20scaletrax%20ITAD%20with%202%20or%20more%20crossing%20gates

As you describe there is an application where either detector should trigger a crossing gate.  And if the crossing gate is the 5-wire style, you can't simply parallel the NO and NC relay outputs as they would fight each other if only one detector is triggered.  So the "standard" answer is an external arbitration relay.  And since this can be done for around $5 DIY (like above) or $10 with an off-the-shelf relay, I too thought about this but want to focus on the detection sensing technology.

So yes, some kind of "party-line" connection could be made between 2 or more detectors so that if ANY detector is active then a chosen relay would trigger.

AFAIK, the latest Lionel incarnation of the crossing gates has only 3-wires.  This only requires a connection to the relay NO of the detector...and all the NO contacts can be paralleled without an external arbitration relay.

2. Judicious choice of the "DELAY" time.

The 153IR and MTH ITAD detectors have the Delay adjustment to keep the relay triggered 10 seconds or more after the detected object passes.  The DELAY gives the consist time to reach the other detector.  Obviously you could stop the consist right on the crossing with the caboose 1" beyond the detector and the gates would go up.  Well, don't do that!

3. Latching detector.

Can't recall if it was the current thread but the idea of the gates going down when, say, the East side detector is triggered...but then don't go back up until the West side detector is cleared.  That is, if you have just an engine it is likely the engine will be between the two detectors for some interval during which the gates go up.  So perhaps a mode where the relay latches when either detector triggers, and then unlatches only after the other detector is triggered and cleared.  And this should support bi-directional travel.  Well, this design obviously doesn't support this.  I suppose a basic latching mechanism as described could get "fooled" if a consist trips the East detector...stops...and then backs up never reaching the West detector at all.  In which case maybe the DELAY timer comes into play to release the gates after some settable time interval.

---------

Anyway, just wanted to jot down my thoughts.  Yes, the tried-and-true insulated-rail method does not have any of these issues...but then again this is more fun discussing new ideas in our hobby! 

Attachments

Images (1)
  • 2%20or%20more%20scaletrax%20ITAD%20with%202%20or%20more%20crossing%20gates
Last edited by stan2004

My vision was once the east trigger activated the gate crossing,  the crossing gates lower and lights would flash until the next phase is triggered by west sensor. At this point the gate would not default to clear until the west trigger sensor completes its process.  I know in the Arduino code I use a command called (switch case) where each case is a particular event.  When one event begins ( lights and gates activated ) the microprocessor will continue to loop back in the code to look at all the possible switch case options and pending the input of the HC-SR04's the switch case would advance to the next option.  Using a relay to trigger NO or NC, I'm not sure you can get the same results as switch case scenario.  A calculated delay would be needed when switching the relay.

I am really looking forward on the prototype, and seeing what becomes of this circuit.  Fantastic job you guys, running with this..  👍

Well it was a bit awkward to set up but here's a scope video showing what I consider to be surprisingly stable and reliable ECHO pulse timing.  In other words, I believe what I'm seeing. 

The scope is displaying 10 pulses per second.  It takes a while to appreciate what is going on here!  This is measuring distance in real-time. 

I'm wondering if there are other O-gauge applications that could benefit from the ability to reliably measure distance to an object - perhaps for some TBD animated accessory?

That is really cool! 👍 Yes to measure in real time.  I was also thinking to sense a train coming into a station for example and have a station announcement be triggered.  Or when a train out of view has cleared a particular area, trigger a location icon on a control panel, there's a bunch of things that this circuit could be used for. 

On the question of 40kHz interference amongst multiple HC-SR04 units, John's idea of a detector link that would stagger the transmitted pulse outputs among multiple units is intriguing.

Another alternative would be in the physical realm. There are a multitude of inexpensive porous acoustic absorbers which should be effective in this frequency range.  For example, mineral wool, natural fabrics, etc.  At this frequency, it should require little material thickness to effectively adsorb the propagated signal and prevent nearby detectors from interfering with each other.

Stan, would you be interested in seeing if this theory is applicable by placing something like a couple of layers of denim between the detector and another reflective object to see if the signal is adsorbed?

OK.  I'm game for a snipe hunt!

denim and black component foam

So if I place 1 or 2 layers of denim (from a pair of jeans) in front of sensor, it simply reflects back and the sensor detects it.  I have no way to quantify how much acoustic energy went thru the denim since the ECHO pulse width drops to the distance to the denim.

OTOH, if I place a 1/2" thick piece of black antistatic ESD foam, the acoustic energy goes thru.  So a target beyond the foam is what gets detected.  Some of the energy is getting absorbed or dispersed since the ability to detect objects beyond the foam is reduced.

Not sure if this is what you're after but it is interesting how the antistatic foam is like glass to an infrared beam.

Attachments

Images (1)
  • denim and black component foam
Last edited by stan2004
@stan2004 posted:

OK.  I'm game for a snipe hunt!

So if I place 1 or 2 layers of denim (from a pair of jeans) in front of sensor, it simply reflects back and the sensor detects it.  I have way to see how much energy went thru the denim since the ECHO pulse width drops to the distance to the denim.

OTOH, if I place a 1/2" thick piece of black antistatic ESD foam, the acoustic energy goes thru.  So a target beyond the foam is what gets detected.  Some of the energy is getting absorbed or dispersed since the ability to detect objects beyond the foam is reduced.

Not sure if this is what you're after but it is interesting how the antistatic foam is like glass to an infrared beam.

Infrared beam?  You've been working with that other technology too long!

Stan, you get an A+ on today's lab experiment, plus extra credit.   I'm a little surprised that the denim is so acoustically reflective at 40kHz.  Conventional wisdom in the applied acoustics field indicates that denim should be very absorptive throughout the higher audible frequency range (2.5k-20kHz).  But based on practical applications and personal observations, I have often wondered if that may be incorrect when it comes to frequencies above 10kHz or so.

As an example, most Noise Reduction Coefficient charts claim an essentially flat NRC around 1 above 4kHz for most absorptive materials (1 being 100% absorptive and 0 being completely reflective).

Based on your findings it seems clear that denim is in fact too dense to absorb much of the 40kHz energy produced by these transducers.  It is possible that a softer looser weave cotton material like fuzzy flannel or uncompressed yet sufficiently thick multi-layered gauze could be more absorbent at 40kHz.

It may also be that the wave energy intensity, especially close to the transducer (see inverse square law for sound) would be too intense for effective absorption without going to extreme measures.

It's also possible that discovering an ideal inexpensive material that would be easy for most people to implement is probably well described (in your words) as a snipe hunt.  Thanks again for contributing to the greater knowledge base here on the forum.

@sjbuff posted:

HC-SR04 Ultrasonic Sensor

Train Detection Block Signals

I thought I share the use of this ultrasonic sensor, I was able to utilize the sensor in my outdoor dead rail layout as a train/block detection on my layout.

Since converting the Baldy & Palms Railroad to “dead rail” in early 2021, the track detection circuit on the upper loop has been functioning correctly about 80% of the time.  The reed switch circuit would get triggered by the magnets at one end of the block and not at the other end.  This made the circuit go out of sync.  I decided to try several other sensors with the Arduino to find a suitable solution. I tried the current sensor, voltage sensor, relay circuit, and the IR sensor, none of these performed reliably.  

E5AAA3D6-6672-4723-A343-8FA647551FB3CC6447FA-7E70-465F-A3A1-868B85D6BD7A67884DD9-A5F2-4578-9331-ACD003FE76B0I discovered the HC-SR04 ultrasonic sensor and decided to experiment with this sensor.  I also created a better Arduino code with the HC-SR04 sensor.  I adapted the HC-SR04 sensor to fit in a small signal shed to match and blend with the block signal.  The Arduino code is written so the HC-SR04 monitors motion from about 4 to 8 CM across the track. When a train is detected on one end of the block, the signal will turn red, and remain red until the train exits the other end of the block, at which the signal will reset to a clear green signal.  This can be used with two or three aspect signals.  The code just needs a few lines of code activated. The circuit has performed very well, so I plan to incorporate this circuit in other trains detection blocks on the layout. Check out the YT video for the Arduino code sketch and circuit design.   YT Video - HC-SR04 Block Signal

Hope this post helps other outdoor layouts having the same problem and eliminate the need to put magnets on locomotives and rolling stock.

I must ask this question, in G scale we use a simple magnet reed switch and timed relay for our trains. Works great and the switch just drops between the rails.

@stan2004 posted:

Thanks for the BOM; I needed to confirm the footprints on various parts so I could order what I didn't have.  I supposedly just made the cut-off for parts from China as their New Year shutdown week is starting.  We'll see...

I needed to generate that anyway, so it was no big deal.  Hopefully, the boards made it before the New Year cutoff, they're coming from China as well.

Looks like they're making them anyway...

Attachments

Images (1)
  • mceclip0
@ThatGuy posted:

I must ask this question, in G scale we use a simple magnet reed switch and timed relay for our trains. Works great and the switch just drops between the rails.

Yes - I've been using the reed switch/magnet for awhile now, and received mixed results.  Magnet would not trigger the reed switch often.  In my case once the magnet triggered the signal, the other end of the block would trigger the signal back to clear.  If the reed switch missed the trigger, the block would not clear. I found the ultrasonic sensor more reliable in my situation. 

Getting closer, the boards are completed, they should be shipping them soon.  I should have them within a week if DHL is awake.

I think my parts might just beat you to the finish line.  I see that JLCPCB and LCSC.com (where I ordered parts) are affiliated and perhaps the same company.  In any case I ordered the parts when you ordered the boards.  My tracking suggests the package did come by air and is somewhere in the US presumably to be given to USPS.

lcsc tracking

Meanwhile, I was hunting around and am astonished by the wide distribution of the HC-SR04 module.

hc-sr04 prices all over the map

Amazon has multiple sellers.  eBay has multiple sellers - and even multiple sellers at 78 cents with free shipping from Asia (takes about 2-3 weeks).  Even DigiKey is/was in the game though I think it was more a "convenience" item given their pricing.  I think there must be some factory in Asia cranking these things out as fast as they can!

Anyway, since we're cooling our heels waiting for stuff, on separate note, I am comfortable recommending LCSC.com for componentsif you aren't in a rush.  In this project, I knew the boards wouldn't be here for a few weeks, so I was able to find a single-source for components I did not have in GRJ's BOM.  First off, to be clear, I am a fan of DigiKey and have been purchasing components from them for over 40 years!  Here's a fun photo of a sample of my DigiKey packing slips! 

digikey orders

I'm only talking about hobbyist orders and prototyping quantities...I don't have anything useful to say on comparing LCSC vs. DigiKey for production ordering (quantities in the thousands or millions).

I compared pricing for some parts in the BOM. I was too lazy to figure out how to make a neat table but here's the qty 10 pricing for LCSC vs. DigiKey:

0.022 capacitor    12 vs. 17 cents

220uF capacitor    7 vs. 22 cents

200K trimpot     9 vs. 40 cents

555 timer IC     16 vs. 32 cents

7805 voltage IC     23 vs. 52 cents

2-pin screw terminal    13 vs. 53 cents

G5LE 10A relay    $0.60 vs. $1.57

eBay (Asia seller) will typically offer better pricing on any given component.  But when you need a variety of parts in small hobbyist/prototyping quantities, it is a nuisance and roll-of-the-dice to buy one part here, one part there, from multiple eBay sellers.  Like DigiKey you will be overwhelmed by the LCSC.com website when you get inundated with hundreds or thousands of choices for a simple component description...and then struggle to narrow down the choices via sometimes cryptic selector columns.

Bottom line.  I've noticed a lot more interest/ability for guys on OGR designing their own PC boards.  I suppose a lot of this is from the low-cost fabrication options like OshPark and free PC board design software. That said, and given that it typically takes 2 week or so to receive boards (unless paying usurious expedite fees), perhaps it's worth a look at LCSC.com for components. 

Attachments

Images (3)
  • lcsc tracking
  • hc-sr04 prices all over the map
  • digikey orders

Looks like the boards have shipped as well.  Apparently, DHL just thinks shipment info received, so I'll probably have it in about 3-4 days.

Thank you for your order from JLCPCB. It’s our pleasure serving you. We are pleased to inform you that the items listed below have been shipped via DHL International Express. Tracking Number: 9975697034,

Attachments

Images (1)
  • mceclip0

Thanks everyone involved in making the pcb board and components list. Here I thought I found a good solution to eliminate the need of a IR sensor in an outdoor environment, never would I thought this could be a viable solution to substitute the IR153, and the use of this circuit without needing an Arduino is awesome for the average railroad modeler. Hats off to all. 👏👍🚂

Well guys, let's not count them chickens before they hatch!   I'm thinking it would be useful to get prototypes in the hands of some interested parties who would be willing to actually mess with it on their layout.   Like those late-night TV ads for some medical device, I believe it would have to be one of those "at little or no cost to you" deals though Medicare would not be required.

All the occupancy detection schemes have their plusses and minuses.  I think part of the fun with alternative technologies like ultrasonics is the adventure of finding new applications.  I think the precise distance discrimination/sensing capability might have as of yet undiscovered applications in running out trains!   

I remain baffled as to how the HC-SR04 module on eBay is 78 cents (free shipping from Asia) and includes a tracking number.

@stan2004 posted:
I remain baffled as to how the HC-SR04 module on eBay is 78 cents (free shipping from Asia) and includes a tracking number.

Stan, it amazes me at the costs of some of the stuff from China, small wonder they're eating our lunch!  I'm just afraid when they finish our lunch, the gravy train will pull into the station and stuff will get VERY expensive!

Here's the "first look" at an assembled PCB for this unit.  I have to say, works pretty well!  It's closest range appears to be 3-4 inches and the longest range was around 3 feet.  This was strictly preliminary testing saving a boxcar around.  Plug-n-play, it ran right out of the box.

I used Stan's choice for the relay, it's a 3A model.  You'll note the blank space for a 10A relay, you can mount either one.  I'm using a 5V 500ma switching module that I use on a number of products, but you can also use the LM7805T regulator in that spot as well.

I give a big hand to Stan, it worked as advertised just copying his schematic and plopping it onto a PCB.

HC-SR04 Ultrasonic Train Detector 1st PCB

Attachments

Images (1)
  • HC-SR04 Ultrasonic Train Detector 1st PCB
Last edited by gunrunnerjohn

As expected, there is interference when two of these can see each other.

I started out with the obvious configuration below.

I set the range to sense about 6-8" and fired the two up.  About every 15 seconds at a somewhat random time, one or both would trigger.

Next I pointed them at a 45 degree angle at the parts cabinets you see at the top of the shot, and it was pretty much the same, slightly less often I'd say.  Finally, I moved them about 4 feet apart and pointed at the cabinets or straight on they still triggered in a similar manner.

The last test was point them out where there was about 7-8 feet to the first obstruction, they didn't trigger at that point, at least for around 10 minutes.

An obstruction placed in front of one but out of the sensing range did seem to block the signal and the other unit stopped randomly triggering.

Obviously, the use of these would have to meet some guidelines on positioning.

OTOH, they seem dead reliable triggering on a lot of different surfaces.

Attachments

Images (1)
  • mceclip0

John, those turned out very nice!  Too bad they interfere with each other.  Wonder if some type of a trackside enclosure would help the interference, maybe narrow the sensing area or something. Still quite useable for many things though.

If you are planning to sell any of those PCBs, I would be interested in at least two of them. I have some of the HC-SR04s I got a couple years ago for something else and never used. And thanks for creating and testing!

Any obstruction that blocks the path appears to knock down the interference, and once I turned them to where there wasn't anything to reflect the beam for a few feet, they no longer had a conflict.  I was impressed on how well they ranged, if you had the sensing distance at about 6", anything at 9" didn't trip them at all.

I think what is behind what you aim them at is a primary factor in their interference.

I did order complete sets of parts and found some terminal blocks for the connections.  I'll have to wait for the Far East, getting the chips from my common sources was not possible, all the major houses were out of them.  eBay wanted a King's Ransom for the 'HC123 chips.

A better mousetrap has always been the bane of DIY invention!

I am just about done with my "phantom" occupancy detector.  That is, any self-respecting modeler built the phantom/transparent P-51 when it came out 50 years ago or so!

phantom ultrasonic detector

My idea is like the traveling O-gauge boxcar from a few years back.  My thought is I will send this to a fellow OGR member who would try it on their layout and give us feedback.  I will pay the $5 shipping.  Then, the next guy does his thing and writes up comments/observations on OGR and sends it to the next guy paying the $5 shipping.  And so on.  At some point I guess it comes back to me.  What I see is a DIY collaboration to experiment with a "new" occupancy-detection technology without the nuisance of ordering components, soldering boards, and so on.  Masks not required.   Anyone interested???

Separately, I commented earlier that packaging is a practical issue.  The ultrasonic module is kind of unusual and may be difficult to embed in a trackside utility cabinet or whatever.

ultrasonic split

So what if the HC-SR04 module can be placed in a simpler housing that sits trackside...and there are 4-wires that go to the electronics board that sits below the layout.  I realize I'm stumbling over my own words but I don't think it's practical to fabricate an odd-shaped trackside cabinet that is realistic...even with a 3-D printer.  The Lionel 153IR occupancy detector is quite an unusual shape; and IMO it doesn't even look like a realistic layout accessory.

I'm thinking it would be much easier to fabricate an above-ground cabinet for JUST the HC-SR04 module....and then run 4-wires to the electronics which can be the circuit board without an enclosure as it would sit below ground (under the layout).  Again, feedback???

Attachments

Images (2)
  • phantom ultrasonic detector
  • ultrasonic split
Last edited by stan2004

Sorry I haven't commented lately, Life has made me take a break from anything to do with trains.

Stan, I like your idea, and I would be interested if it was all just plug and play. I would even be willing to try and build a cabinet for it that might look more realistic.

I do have one question though, how do you think this would work with 3 or 4 tracks within the same range?

@mike g. posted:

...

Stan, I like your idea, and I would be interested if it was all just plug and play. I would even be willing to try and build a cabinet for it that might look more realistic.

I do have one question though, how do you think this would work with 3 or 4 tracks within the same range?

Well we have at least one brave soul!   Yes, it will be plug-and-play.  You apply accessory AC to the 2-terminal connector...and then attach 2 or 3 wires (depending on your accessory) to the 3-terminal connector.  No soldering required.

The unusual thing about this ultrasonic detector is the sensitivity is very precise in terms of distance to target.   So if you have 4 parallel tracks, you should be able to set the detector to trigger on the closest track ONLY (ignore 3 distant tracks)...or the 2 closest tracks ONLY (ignore 2 distant tracks)...or the 3 closest track ONLY (ignore most distant track).

Obviously, those guys that are able to wire the parallel tracks using the insulated-rail method can effect similar precision on which track(s) trigger an accessory.  This method has the sometimes useful benefit that in can be done after-the-fact so you don't have to rip-up carefully ballasted track.  It also applies to 2-rail or situations where you might not be able to use the insulated-rail method.

As GRJ alluded to earlier, it's not clear how much interest there is in this "new" technique.  I'm particularly interested in guys that might discover some specific applications where the ultrasonic method is particularly well suited.  Sort of like the topic of this thread in the first place...where the ultrasonic method turned out to be particularly suited for an outdoor layout.

John; I would be interested in a few boards if you still have stock; say 4 or maybe 6. Can you let me know pricing etc please.

Many thanks to the OP for tuning us into this neat idea, and Stan for developing the circuit to put it into motion, and to you for laying out the circuit board and BOM! Neat project. I only just got tuned into this thread thanks to rtr12!

Thanks, Rod

John I presume your parts kit will be less the actual HC-SR04 detectors, and likely the relays, since there are two options there. Did I get that right? Is everything else on the BOM included?

Also I am not clear on how two of these are interconnected (or if they are) so that the signal goes red on block entry and green on exit? How does that work?

Stan I love that transparent P-51 Mustang model. Sure wish I had known about that back in the day. I am a big fan of warbirds and in particular the  Mustang; the perfect marriage of American airframe design and the ubiquitous British RR Merlin V-12 water cooled engine. Always would have loved a flight in one, but alas the remaining airworthy examples are all in the hands of rich warbird collectors I guess. Very neat to see (and hear) them at airshows though. Sigh..... Sorry for digressing.

Rod

I anticipate having all the parts in any kit.

I have a bunch of each relay, so I'll just use them up.  I also have a number of the HC-SR04 modules.  The Chinese, in a rare fit of generosity, sent me a duplicate order for six of them out of the blue, so I have more than I anticipated having.  I also put in an order for eight more from AliExpress so I had enough for all the remaining boards.  The other components that were not readily available or too expensive are also coming from AliExpress.

The relays are simply a set of FORM-C contacts that are totally isolated from any circuitry on the sensor board or it's power.  You can obviously wire it just like any other ITAD type sensor for common signals.  For the ones I make and keep, I'll probably use the 10A relays to give me maximum flexibility in their deployment.  The 3A relays have lower coil currents, so for signals they are probably a slightly better choice.

I'm building a layout now and I want block occupancy detection for signals, visual confirmation of occupancy and future automation.  I am an old model railroader and very familiar with insulated rail.   On a longer mainline block away from yards, one must put in several insulated rails to pick up occupancy.  I wonder if this sensor could have an advantage over insulated rail in these circumstances.  Might need several just like insulated rails?  They sound a little fussy for use in dense yard areas?  Wondering?

Bill

@Rod Stewart posted:

...

Also I am not clear on how two of these are interconnected (or if they are) so that the signal goes red on block entry and green on exit? How does that work?



...

The two detector configuration, for example one on each side of a crossing, has been a wiring challenge for 3-wire signals where you must explicitly drive the Red wire to turn the signal Red, or the Green wire to turn the signal Green.  The 3rd wire is common.  There are crossing gates that have this same requirement - explicitly drive one wire for gates down and drive another wire for gates up.

In such a situation, two Lionel 153IRs or MTH ITADs require an external relay to arbitrate the possibilities that one or both of the detectors might be triggered.  That's because these detectors have its relay outputs (to the signal) hard-wired internally to AC power.

two spdt relays in OR configuration

As designed and as GRJ mentioned above, the relay COM (common) is isolated from anything else and is not internally connected to Accessory AC.  This allows you to take the COM of relay 2 and connect it to NC of relay 1 (shown above as "the key").  In doing so you can then have the two relays working together so that if either or both detectors are triggered, the signal will receive the correct command.

This situation has been described in earlier OGR threads.  I'd have to dig around to find it, but there was one thread where some time was spent discussing how to modify a 153IR to isolate the relay contacts thereby allowing this type of "daisy-chain" like wiring thereby not requiring an external relay.  I believe the conclusion was it would be quite a bother to do so considering an external relay would be maybe $10 or so.

The issue though, which is unresolved, is how closely you can place two of these ultrasonic detectors without interfering each other.  After all each detector is sending an acoustic pulse that bounces around and might make its way to the other detector.  GRJ discusses some placement/interference experiments in a previous post. 

As a "new" technology, this is exactly what we're trying to find out.  What are the limitations, guidelines, or whatever to applying this?

But speaking of "interference" haven't you come to a crossing with the gates down and there's no train in sight?!  The gates go up after a while and life goes on.  This "false positive" might actually make a layout more interesting!

Attachments

Images (1)
  • two spdt relays in OR configuration

John, glad to hear that your kits will be complete with detectors and relays. Good news!

Stan I recall the previous thread and the daisy chaining of two or more detector relays as you show above. I was wondering if that is how it might be done. Thanks for sharing.

I also recall the lengthy thread about 2 years ago regarding use of 153IR's and Itad's for driving interconnected crossing gates, signals and such. I agree that modding a 153IR to isolate the relay common is a bit of a chore considering adding an external relay to the circuit is pretty simple. I wound up creating a small pcb to accommodate a small 2 amp relay for these stuations, and it works quite well. I have also previously used DZ-1008 relays in a couple of similar setups on the layout to drive crossing gate pairs, but they do seem like overkill for driving signals. But hey, they work.

Overall this is a pretty neat project and I hope it continues to generate interest! Looking forward to the kits John.

Rod

@Rod Stewart posted:

...

Stan I recall the previous thread and the daisy chaining of two or more detector relays as you show above. I was wondering if that is how it might be done. Thanks for sharing.

I also recall the lengthy thread about 2 years ago regarding use of 153IR's and Itad's for driving interconnected crossing gates, signals and such. I agree that modding a 153IR to isolate the relay common is a bit of a chore considering adding an external relay to the circuit is pretty simple.

...

Right, the daisy-chaining is exactly how it might be done.  It's all about isolating the common of the SPDT relays.  In addition to the nuisance of performing surgery on the 153IR circuit board, that thread also revealed how different versions of the 153IR (all with the same SKU #) had different instructions of which wires/traces to cut, jumper, etc..

Of course the more recent releases of signals and crossing gates have gone to a single trigger wire (rather than two).  In such cases you can parallel the NO outputs of multiple 153IR or detector relays such that if any of the relays is active then the signal or gate is triggered.

Last edited by stan2004

In thinking about this some more I like Stan’s idea about mounting only the HC-SR04 heads at track level, maybe in a small 3D printed trackside cabinet, and having the board mounted under table so it’s out of the way. I am looking forward to getting the kits and playing around just to see what we can do with them.

I have no real complaints with the way my current signals, gates, etc operate using mostly Z-Stuff sensors and 153IR’s. But from what is being described in this thread these detectors should be more reliable, not prone to differences in lighting or different paint color problems, triggered by any kind of surface, and easily adjusted to small or wide ranges of sensing. The real test will be tank cars, which IR sensors just mostly do not detect in my experience.

Rod

@stan2004, I have a question for you.  I decided to put a few of these together, and a real oddity surfaced.  I started out with the Toshiba TC74HC123APNEWF, and that worked as expected, I get about three feet of max sensing distance.  I picked up some TI CD74HC123E parts that were claimed by TI to be compatible.  They work, but...  I only get a sensing distance of something over a foot at max settings!  I chased my tail for a spell, then swapped one of the Toshiba parts in, and the operation resumed as expected.  Would you expect this circuit to have that much variability just based on the different characteristics of the 'HC123?  I actually expected very little difference, so I'm a bit surprised.  I swapped several out and all changed the behavior, so I'm sure it's the 'HC123 that is the difference.

Last edited by gunrunnerjohn

hc123 k constant difference

Toshiba datasheet suggests the pulse width is just less than 1.05 x R x C (R=205K max, C=-.022uF)

TI datasheet pulse width is 0.45 x R x C so just under 1/2 the pulse width for the same external R and C values.

So the Toshiba part would max out at 2-3 times the range of the TI part...which is apparently what you're seeing.

As I see it, this is flushing out the design issues exactly as intended.  I'm not sure I'd need or want a 3 foot sensing range from detector to train...but again I'd like to hear ideas on where this would apply.

Attachments

Images (1)
  • hc123 k constant difference
@stan2004 posted:

Toshiba datasheet suggests the pulse width is just less than 1.05 x R x C (R=205K max, C=-.022uF)

TI datasheet pulse width is 0.45 x R x C so just under 1/2 the pulse width for the same external R and C values.

So the Toshiba part would max out at 2-3 times the range of the TI part...which is apparently what you're seeing.

As I see it, this is flushing out the design issues exactly as intended.  I'm not sure I'd need or want a 3 foot sensing range from detector to train...but again I'd like to hear ideas on where this would apply.

Stan, I confess I didn't even look at the datasheet, I just "assumed" that the two parts would be very similar in operation and timing.  Lesson learned.   I figure the longer distance operation can't hurt since you can also adjust it down to a couple inches.  Since I only have a few of the TI parts, I'll just stick with the Toshiba parts.

The off-shore parts were a bust!  I ended up getting them from Digikey for a bit more money.

The NE555 parts from AliExpress were all defective, I put four of them in a board and none worked.  So I fired up a simple test circuit on a project board and it turned out that only 9 or 10 of the 50 worked, obviously defective pulls.  I decided to pitch them all, not taking a chance.   I filed a dispute as well, I want my $3 back!   The 'HC123 parts worked, but as illustrated in previous posts, I failed to consider how much different they would be than the others I was using.  I decided to get get more of the Toshiba parts to keep the parts kit consistent. The caps from off-shore worked fine, I got the extra resistors locally as they're cheap anywhere.  I also rounded up enough regulators to equip them all, turns out I have a hundred from another build that were left over.

I also found some terminal strips that work in the board, so I'll have screw-terminals for the connections.  It ends up costing a bit more, but it's a much neater installation.

I think the final parts are in my mailbox, I'm going to go up and fetch them today.  I'll just have to kit up the parts and I'll be set...

OK, the parts are in.  I have a few of these built, I was tinkering with a couple of them.  I built a couple with the 10A relays, and the rest with the 3A relays.  A kit will consist of everything you see here, enough to build a complete working board as shown.  Kits will be $15 for the 3A relay version and $17 for the 10A relay version.  Note that there is no adjustment or calibration necessary, other than setting the detection range and relay trip duration pots, it's all fixed components.  All connections are side entry screw terminal blocks.

If anyone wants one of these assembled versions, add $15 for the labor for assembly/testing.

HC-SR04 Assembled Sensor Boards

Attachments

Images (1)
  • HC-SR04 Assembled Sensor Boards
@sjbuff posted:

HC-SR04 Ultrasonic Sensor

Train Detection Block Signals

I thought I share the use of this ultrasonic sensor, I was able to utilize the sensor in my outdoor dead rail layout as a train/block detection on my layout.

Since converting the Baldy & Palms Railroad to “dead rail” in early 2021, the track detection circuit on the upper loop has been functioning correctly about 80% of the time.  The reed switch circuit would get triggered by the magnets at one end of the block and not at the other end.  This made the circuit go out of sync.  I decided to try several other sensors with the Arduino to find a suitable solution. I tried the current sensor, voltage sensor, relay circuit, and the IR sensor, none of these performed reliably.  

E5AAA3D6-6672-4723-A343-8FA647551FB3CC6447FA-7E70-465F-A3A1-868B85D6BD7A67884DD9-A5F2-4578-9331-ACD003FE76B0I discovered the HC-SR04 ultrasonic sensor and decided to experiment with this sensor.  I also created a better Arduino code with the HC-SR04 sensor.  I adapted the HC-SR04 sensor to fit in a small signal shed to match and blend with the block signal.  The Arduino code is written so the HC-SR04 monitors motion from about 4 to 8 CM across the track. When a train is detected on one end of the block, the signal will turn red, and remain red until the train exits the other end of the block, at which the signal will reset to a clear green signal.  This can be used with two or three aspect signals.  The code just needs a few lines of code activated. The circuit has performed very well, so I plan to incorporate this circuit in other trains detection blocks on the layout. Check out the YT video for the Arduino code sketch and circuit design.   YT Video - HC-SR04 Block Signal

Hope this post helps other outdoor layouts having the same problem and eliminate the need to put magnets on locomotives and rolling stock.

To me this is the hard way to do this, in g scale we use a magnet and reed switch to a relay it can be self latching with a second reed switch as the kick out. All off the shelf and very cheap as well as trouble free.

@stan2004 posted:

hc123 k constant difference

Toshiba datasheet suggests the pulse width is just less than 1.05 x R x C (R=205K max, C=-.022uF)

TI datasheet pulse width is 0.45 x R x C so just under 1/2 the pulse width for the same external R and C values.

So the Toshiba part would max out at 2-3 times the range of the TI part...which is apparently what you're seeing.

As I see it, this is flushing out the design issues exactly as intended.  I'm not sure I'd need or want a 3 foot sensing range from detector to train...but again I'd like to hear ideas on where this would apply.

As described above, I was using the equation: pulse width = K * R * C.  In this case K=0.45 for T.I. and about 1.0 for the Toshiba per the datasheet I pulled off the web.

There is something squirrely going on though.  I dug thru my parts stash of 74HC123 chips and estimated the "K" constant in the Range adjustment circuit.

0.38   Texas Inst. just received from LCSC - presumably a fresh date code though not clear what year

0.44   ST Micro date code 1998

0.49   TOSHIBA #1 date code 1989

0.51  TOSHIBA #2 date code 1989

1.0    National Semi date code 1990

So in this sample of 5, most were around K=0.45 and the odd-ball was K=1.0.  So it was the National chip from 30 years ago that has the longer pulse time like your current Toshiba part.  My older Toshiba parts from 30 years ago behave like the modern T.I. part.  The 74HC logic chips are fairly long in the tooth and there have been comings-and-goings in the chip business.  But it's known that for legacy chip families like this that as manufacturers upgrade there chip fab equipment certain characteristics can change - in this case apparently the K parameter. 

All this is a moot point since you're "shipping" fresh Toshiba parts which provide the extended Range adjustability.

Here's something that we discussed, a remote cable to connect the sensor to the board.  It looks like it doesn't change anything except the mounting of the sensor.  The cable is build using Dupont Connectors.  I didn't see any adverse effects, but the cable is only a foot long.  However, I suspect any reasonable length cable would work here.

An important note:  Since the cable has no keying, I labeled each end and the board with the signals, if you reverse it, I'm pretty sure the sensor will die a horrible death!

mceclip2

Attachments

Images (2)
  • mceclip0
  • mceclip2

I set up one of these on the bench, and I was quite impressed with how precise the triggering range can be.  It works within about an inch in distance.  It would trigger every time at, say 10 inches, but never at around 11.5".  I have to think this resolution might work for some applications better than an IR sensor that reflects off the target.  The IR boards just reduce the sensitivity of the receiver to change the range, that's a very inexact method of adjusting range.  I fooled around with a variety of different materials in front of the ultrasonic sensor, and it was amazingly consistent with any of them.

BTW, still have a few sets of parts all kitted up if someone want's to build one or more of these.

This is just a 'FYI' for anyone that might be interested and may not know of other sensors similar to the HC-SR04.

Finally got around to looking at the video link posted by Consolidated Leo on the first page of this thread.  (I'm a little behind as usual) While the video was Arduino related, there was another sensor mentioned that can be set to emulate the HC-SR04 sensor. The Sensor itself is supposed to be waterproof, but obviously the driver board is not waterproof.

Waterproof-Ultrasonic-Module-JSN-SR04T-AJ-SR04M-Water-Proof-Integrated-Distance-Measuring-Transducer-Sensor-for-Arduino.jpg_640x640

Since it can be set to emulate the HC-SR04 I was thinking it just might work with Stan's circuit that GRJ has made the PCBs and kits for. I have not tried this and I know it adds an extra board. Just thought it might be an option for consideration if anyone was interested and unaware of other sensors like the HC-SR04?  I was thinking it might be smaller and easier to disguise along the tracks with the driver board being remotely connected to the sensor, using a fairly long cord (which is included).  These are a bit more costly than the HC-SR04s, about $3.60 from AliExpress at the time of this post.  You can see it here - Waterproof Ultrasonic Module JSN-SR04T / AJ-SR04M.

There are better instructions available at the DroneBot Workshop website (from Consolidated Leo's link above).  The AliExpress instructions were somewhat lacking, like some of the instructions provided with other off shore devices.  They also talked about one more waterproof sensor there, but it was described as more of a switch and I didn't think it would work with Stan's circuit without modifications (probably major), which I thought would be above my abilities? It's also quite a bit more expensive.

Also as Consolidated Leo described above, complete details are provided (including code) to make either of these sensors (including the HC-SR04) work with an Arduino if anyone is interested.  It's a good learning video if you are new to Arduinos and the DroneBot website is also a good learning site. The website not all Arduino only, it also includes electronics tutorials, helpful if you are trying to learn more.

Attachments

Images (1)
  • Waterproof-Ultrasonic-Module-JSN-SR04T-AJ-SR04M-Water-Proof-Integrated-Distance-Measuring-Transducer-Sensor-for-Arduino.jpg_640x640
Last edited by rtr12

Hopefully that's exact HC-SR04 emulation or really close anyway so it works with the already designed circuit and PCB.  I've forgotten the other 4 modes already, but didn't look that closely at those.  I was thinking the same thing about hiding them on a layout and they have a fairly long cord, or at least looks to be fairly long.  I'll be interested in your opinion of them and getting them the next day is definitely very nice, no waiting required! 

That's good to hear, I'm glad it worked.  How was the remote sensor part?  Hopefully it was a bit smaller and would easier to conceal on one's layout somewhere than the HC-SR04.  They are a little more expensive, but might be worth it for some applications.  And that was a mighty quick delivery too!  I wouldn't have time to forget why I ordered it with that fast of a delivery. 

Well, I can report that the JSN-SR04T works just like the HC-SR04 in the board.  The only difference I see is a slight variance in the distance setting, the closest setting doesn't work, other than that, it seems pretty much like the HC-SR04 in operation.  Obviously, I didn't test all the other modes that require a different hardware platform.

Good news John. That should mean that other than any cost considerations, the JSN-SR04T should work every bit as well. Were you able to determine what the minimum useable setting distance is?

Rod

Last edited by Rod Stewart
@Rod Stewart posted:

Good news John. That should mean that other than any cost considerations, the JSN-SR04T should work every bit as well. Were you able to determine what the minimum useable setting distance is?

Rod

Rod, the minimum distance seems about the same, 3-4 inches.

@rtr12 posted:

That's good to hear, I'm glad it worked.  How was the remote sensor part?  Hopefully it was a bit smaller and would easier to conceal on one's layout somewhere than the HC-SR04.  They are a little more expensive, but might be worth it for some applications.  And that was a mighty quick delivery too!  I wouldn't have time to forget why I ordered it with that fast of a delivery.

The remote sensor is certainly much smaller than the whole HC-SR04 board, about 1.25" in diameter and an inch or a bit more in depth.  You pay a little more at Amazon, but next day delivery makes up for some of that.

Last edited by gunrunnerjohn

Rod, the minimum distance seems about the same, 3-4 inches.

...

Is there any marking as to which version of the JSN-SR04T you got?

jsn-sr04t

In reading some reviews, it appears the original version was 5V only, but there is a more recent version that additionally operates at 3V (not that 3V operation is needed in this case).  Additionally, as per above, the minimum distance for whichever version this is, is 25cm or ~10 inches which I'd think is too far for most O-gauge trackside occupancy detection?

Also, in at least one review, it was claimed that the 4-pins changed definition between versions.  Hard to know what to believe.

Attachments

Images (1)
  • jsn-sr04t

Well I received 2 kits from grj and got one built today. Hooray; it works just as advertised! All needed parts are included in the kit, including an HC-SR04 sensor and your choice of 3 amp or 10 amp relay. And they all fit quite well. The parts packaging is excellent; well done John.

I did a little testing of the range and reset delay, with the following results:

Range: Min= 3/4", 1/4 turn = 3", 3/8 turn = 7.5", 1/2 turn = 14", 3/4 turn = 27"

Delay: Min = 1 sec, 1/4 turn = 5 sec, 1/2 turn = 20 sec, 3/4 turn = 40 sec, full CW = 45 sec

These are all with the particular set of components in the kit, YMMV. But adjustability is good and will cover most of our model RR needs I figure.

The only things I would suggest are: 1. Take care with the LM7805 TO-220 Vreg mounting. It's #1 pin is the far left one when viewed from the inscription side, so the chip mounts with the inscription facing outwards and the tab towards the center of the board.

The pads for Q1 and Q2 are tiny and close spaced. It's fiddly and very easy to solder bridge them. Take care and examine afterwards with a magnifying glass. I would have preferred the TO-92-100 pattern, but that's just me.

Kudos to the OP for the idea, Stan2004 for the circuit design, and grj for the board design and putting the kits together!!

I plan to install a couple of these once we are back home and see how they work in the real layout world.

Rod

If it had it to do over again, I'd actually use the footprint for the LM7085T, I used my footprint for the RECOM switching module.  I didn't think the LM7805 would handle the larger relay, but with a heatsink it works fine.  I normally mount the regulators the other way, so that one was just the lack of a second spin of the boards.  I think I'll start using the TO-92-100 pattern in the future as I hear you about the transistor pattern, it is tricky.

Now you're talking John; that revision looks great! But this thing all in all looks like a home run to me as is. Can't wait to try them on the layout. And the isolated relay common covers all the bases! I especially like the idea that a range of 4" to 8" should be easily doable, and hopefully will mitigate unwanted reflections. We shall see!

The little transducer cones on the HC-SR04 board are only 5/8" diam and project a little less than 1/2" from the face of the board. Plus they are an inobtrusive aluminum color. So I think it will be easy enough to disguise them in some sort of small trackside cabinet structure, especially if tethering them to the main board located  below the layout. All good.

Rod

Last edited by Rod Stewart

That all sounds very good with the kits and their operation!  My kits seem to be stuck in downtown KC (since Thursday). Fortunately, they now say Monday delivery!  I hope to have one built up next week sometime. 

And as Rod said above, thanks to sjbuff for the original idea and sharing it here, thanks to Stan for the circuit design and thanks to GRJ for the PCB design and getting the kits together!

I have been doing a little more playing with my first kit build, and have some observations.

At idle (with 14VAC board supply) with no relay triggered the LM7805 Vreg is barely warm to the touch. After the 10 amp relay has been triggered a few minutes it gets quite warm though, over 40C, perhaps 50C or so. Don't have my temp gun here so can't be sure, but definitely a small heat sink would be a good idea. I think it is running a fair bit shy of shutdown high though. The 10 amp relay draws about 90 ma of coil power, but the 3 amp version draws way less. So it would likely be just fine without a heatsink. The tiny Q1/Q2 transistors get only slightly warm to touch.

The transducers have a cone of dispersion that is about 15º each side of centerline at 3" away; and about 8º each side at 7.5" away. So it is more of a "parabola of dispersion" I guess, that is about 1.6" diameter at 3" distance, and about 2.1" diameter at 7.5" away. Flat surfaces parallel to the axis of the parabola (such as a tabletop) don't reflect the signal. But any structure or something like track or roadbed that is within this parabola will likely cause unwanted reflections. This means that at a distance of 8" away the transducers will have to be mounted AT LEAST 1-1/4" above top of rail to be safe. This would be an issue if aiming the transducers at say truck height, but aiming at any part of a car body should work fine. Even an unloaded flat car should trigger the relay, as long as the side of the deck is within the dispersion parabola. For O gauge tubular or Fastrack for instance, a height above grade of about 2" for the transducer centerline looks like it should work. This needs to be confirmed in the real world though!

For distances over 8" the cone will be somewhat bigger; which might require the transducers to be mounted a touch higher, but I did not check this out yet.

Some may recall the first versions of the 153IR had the annoying habit of untriggering after the delay timed out, even if the train was still stopped in front of it. This was fixed in later versions thankfully. But this new device stays triggered as long as something reflects the signal, so all is good.

Rod

Last edited by Rod Stewart
@BOB WALKER posted:

Did you ever consider using the Sharp distance measuring sensor? I have used it with good results in several projects.

Bob, I did a search for Sharp distance measuring and got several hits. One is a flat module that appears to be IR based, so it would likely be no better than the 153IR or any ither IR device. Another offering was called Pololu and looks a lot like the HC-SR04, though it was not clear what the technology is. Both seem to be around 9 bucks, so they are way more costly than the HC-SR04. Sorry I am not seeing any advantage?

It would help if you could tell us which particular device you are referring to?

Rod

Last edited by Rod Stewart
@BOB WALKER posted:

The Sharp unit is a GP2YOA21YKOF proximity detector which outputs a voltage corresponding to the distance to an object. I used it in several projects described in train magazines. Here's one of them.

https://www.youtube.com/watch?v=P8NJNvCfCU

I'm at a loss as to how this is superior, and it's an optical sensor.

Sharp GP2YOA21YKOF Specification.pdf

So I have some real layout experience to relate with these sensors. Today I did my #2 build and mounted it on a scrap of 2 x 4 to do some layout testing. This puts the CL of the heads at about 2" above grade, which seems like a good height for use with O gauge tubular track on cork roadbed.

I set the range pot to max (about 7" with these components) and it worked really well. No false triggering or spurious responses. and there is a "rock" wall about 13" away which had me worried, but no issues. And it nicely covers the two tracks at this location. Set the delay to about 12 seconds which looks about right to me. It is very repeatable. The train I was running has a consist of about 6 tank cars plus a few box cars etc. It triggered when it should have, and not anytime else. My conclusion (based on an example of one!) is that as long as the range setting is reasonable, which it will be with the specified components, there should be no problem with reflections, false triggering, etc. Works great.

When you stop a train in front of it with the gap between cars lined up with the detector heads, it times out as expected. But stopping with any part of any car in the beam of the signal kept it triggered nicely. No dropouts at all. I may try lining the head height up with the couplers and see if that keeps it triggered between cars. But overall I am very happy with how they work just as is.

Attached is a short video clip of the test setup. This is hooked up where a 153IR controller normally sits; one I had some troubles with as reported recently in a separate topic.

In summary I think these guys work better at detecting trains than anything else I have tried on my layout. The next step is to whip up some sort of small trackside building or similar to mount it in. How about it you 3D print design guys??

Of course another option is remote mounting the board under the layout as discussed earlier in this thread, but I have not tried that yet. Anyone else who had tried grj's kits got any experiences to report?? I think he has some kits left, for anyone else who wants to get their feet wet. its pretty neat technology. And thanks again Stan 2004 for doing the circuit design, it works really well!!

Rod

Attachments

Videos (1)
Train Detector Test

Try them at an angle to the track and they may catch the train and ignore the gaps.

In the datasheet for the HC-SR04 they say that the "Measuring Angle" is 15 degrees. Not sure but I think that may mean you have to be within 15 degrees of perpendicular to the reflecting surface for it to read the reflection. If true, that might limit how far off these can be mounted, but a little more experimenting  will tell I guess.

Rod

They might be erring on the conservative side.  I got reliable readings at over 40 degrees when I rolled a tiny car in at that angle.  I think coming in at 20-25 degrees would solve the problem of the gaps between cars and still provide reliable triggering.



Good to know John. Overall I am quite happy with the way these things work. Just need to come up with a convincing small structure to put on the layout that will hide the sensor heads now.

I have been playing with some housing ideas for the sensor head that might work on the layout without looking too "clunky". Here are some pix of one idea. This is actually the large relay cabinet in the Lionel trackside accessory collection. I placed it on a convenient chunk of 1 x 2 just to get to the height needed for the sensor ports. To the right is a pic of the sensor head mounted in the cabinet with holes drilled in the back which would be aimed across the tracks. So the whole thing is pretty unobtrusive.

Housing 3Housing 5

Here is the finished cabinet with the sensor installed, ready for layout trials. Only trouble is I need to build up another train detector board first because the two I built so far have the sensor soldered into the board! Oh well.

Housing 6

Note that going this route would be a bit pricy as the Lionel trackside kit seems to sell for up to about $30. Kind of crazy for 4 or 5 simple little plastic doodads that don't do anything except sit on the layout, but hey. One idea I am exploring is getting a 3D printer file together for something similar to this. I have a sketch made up that will fit these sensor heads really well, and it is higher so you don't need the wooden block under it. That would allow one to print up half a dozen or however many you need pretty inexpensively.

Research continues.

Rod

Attachments

Images (3)
  • Housing 3
  • Housing 5
  • Housing 6
Last edited by Rod Stewart

So I tried the sensor on the layout today with great results. I put it in place of a 153IR which had been giving some problems. And it works great. It is 100% compatible with the other 153IR at the other end of two road crossings. Its range is good; it easily covers two adjacent tracks. No false triggering during my testing. And best of all it triggers reliably with tanks cars; something that most IR sensors have trouble with. I parked a couple of them in front of the sensor just to make sure it was solid. Worked really well. Here is a pic:

HC-SR04 In Housing on Layout.

Note this is just a test setup so the control board is plopped on the table right in front of the sensor cabinet, in the foreground. A permanent installation would have the control board sitting below the table with the sensor tethered to it. All good. Now I have to figure out something to use to house a few more of these guys.

Rod

Attachments

Images (1)
  • HC-SR04 In Housing on Layout.

I got a question I got a couple kits from John and finally got around to putting one together. And it didn’t seam to work very well then I noticed I had 7VDC coming out of the voltage regulator 😳

I need To go back through it and make sure I didn’t screw something else up but I’d bet that the sensor is dead now.

so to the point what voltage are you guy feeding these things? 14VAC? 8VAC? I wouldn’t had thought it to make much difference but just wanted to check

It appears there are 2 versions of the PCB out there.  I know there was some discussion about modifications to the initial PCB design IF another batch was ordered.   I guess they were ordered?

hc-sr04 versions

I see the 7805 voltage regulator (circled red) faces oppositely.  The left photo looks to be PCB Rev 1.0 (circled yellow); the right photo Rev 1.1?

If you're having a problem with the voltage regulator, can you confirm the 7805 orientation matches the version.

Attachments

Images (1)
  • hc-sr04 versions
@zhubl posted:

I got a question I got a couple kits from John and finally got around to putting one together. And it didn’t seam to work very well then I noticed I had 7VDC coming out of the voltage regulator 😳

I need To go back through it and make sure I didn’t screw something else up but I’d bet that the sensor is dead now.

so to the point what voltage are you guy feeding these things? 14VAC? 8VAC? I wouldn’t had thought it to make much difference but just wanted to check

Zachariah, the voltage on pin 3 of the 7805 should be pretty much 5 vdc, spot on. Your board should have the 7805 oriented as shown in Stan's pic above of 3/11, with the tab facing inwards and the inscription outwards. Grj revised this orientation on later boards to that shown in the 4/27 view. But I believe all original kits of grj's are as per 3/11. Grj will maybe confirm this.

Rod

@Rod Stewart posted:

Zachariah, the voltage on pin 3 of the 7805 should be pretty much 5 vdc, spot on. Your board should have the 7805 oriented as shown in Stan's pic above of 3/11, with the tab facing inwards and the inscription outwards. Grj revised this orientation on later boards to that shown in the 4/27 view. But I believe all original kits of grj's are as per 3/11. Grj will maybe confirm this.

Rod

Correct, the first spin of the boards were the top picture.  I did a second one that I didn't buy any boards from.

@zhubl posted:

I did confirm I have V1.0 and put the voltage regulator in backwards (that’ll show me to just slap a board together without tripping checking) anywho I still think I fried the HC-SR04 so I need to swap that out with the other one I got.

Sorry about that Zachariah, I really should have made that clearer, I was trying to accommodate both the switching power supply module and the regulator, and I did a poor job of documenting it.

Sorry about that Zachariah, I really should have made that clearer, I was trying to accommodate both the switching power supply module and the regulator, and I did a poor job of documenting it.

And to think you were a "professional"

No worries John I'm thinking that only the sensor module it's self was damaged but I'll find out soon enough



@Rod Stewart posted:

Ouch! Do you plan to flip the Vreg and see if bychance it works ok? You may have cooked the 5555 and the 74HC123 in the process, hard to say. But you have nothing to lose in trying it out.

Rod

I did do that but no cigar yet like I said above I'm betting then senor module is the only thing damaged as it's probably the only thing with a strict 5V rating. Not too worried about the 555 it should be fine the 74HC123 could be but we'll see I would imagine it should be fine but I'll double check the data sheet for the ratings.

More progress with HC-SR04 sensors to report. The pix below show my second installation on the layout. Working great.

Completed Instalation #2.0Completed Installation #2.1

With the help of formumite Gary Glozer we made a file to 3D print the upper cabinet, which houses the actual sensor. The sensor looks out the backside across the adjacent track.

I also made up a 3D print file for the base which houses the actual circuit board. This keeps all the wiring hookup above the bench for ease of access. The circuit board is made from a kit available from grj based on Stan2004's original circuit, as discussed earlier in this topic. The two sets of stairs were also printed up from .stl files found on the forum in the 3D printing repository category, and modified.

This sensor and it's mate replace two 153IR's which had been in use since about 2005 or so. One had become quite undependable.

Rod

Attachments

Images (2)
  • Completed Instalation #2.0
  • Completed Installation #2.1
@sjbuff posted:

Rod the sensor housing looks fantastic! You did a fine job. Glad the sensor is working to your expectations. I’ve recently used the HCSR04 as a gate crossing sensor. I’ll post some video once done editing video.

Thanks Ron; it's been a really gratifying project. The sensors work great and you deserve big kudos for bringing this technology to our attention. Sorry if I kind of hijacked the topic a little, but the project really developed a life of its own! Any future installs on my layout will be using these sensors as a standard, and I will be switching some older IR sensors over as time and initiative permits.

For anyone who wants to print their own cabinets and/or pcb bases like those pictured, I can make the .stl files available, just shoot me an email.

Rod

Since it seems that most practical applications of this unit would have the board at a remote location with a wire between the sensor and the board, it made sense to see if it could be smaller.  Here's a 1.5" x 2.0" version, it has the same components and functionality of the earlier 2" x 3" board, just in half the space.  This would likely facilitate putting it in trackside cabinets easier than the larger board.  I did sacrifice the high current relay and just used the 3 amp relay, more than sufficient for signals.

   

Attachments

Images (2)
  • mceclip1
  • mceclip2

I would like to get my hands on some on the HCSR04 3D cabinets, those are really cool. Like Gunner I don’t have a 3D printer either. I’d gladly pay a $$ for a few cabinets for future projects.
I’m glad this sensor grew legs of its own. I stumbled on this sensor our out of luck.
Having an outdoor layout, the go to sensors just did not perform satisfactory.
Kudos to all who taken this sensor to new endeavors. Hats off to all.

Last edited by sjbuff

OK, I hated to sacrifice the 10A relay, so I shuffled the parts and got it all to fit in the 1.5" x 2.0" board with the high current relay.   I did have to sacrifice the mounting holes, but since the backside has no components, double-sided foam tape works well.

1. Yeah, easy for me to say, but can you confirm (again) that you can't put the HK4100F 3A relay overlayed on the G5LE 10A relay in some fashion that you can install either on the same PCB rev?  I'm physically holding both parts and looking at the first PCB rev and it sure seems like something could be done to allow either part to be installed without changing the size of the PCB.

2. If you are rev'ing the PCB, any chance you could spin all ICs so that pin 1, the square-pad, is in the same corner?  Nit-picking to be sure.

3. Could you drop some holes/vias on the trimpots to allow insertion of the common/inexpensive 3362P style trimpot?

4. Separate to item 1, I thought part of the reason you went to the switcher 5V regulator was because the G5LE relay used double the coil power as the HK4100F.  In your last post with the 10A relay it appears the 7805 is still there?  I don't have the switcher part in hand but I suspect it might be physically larger than the 7805 and the regulator chip looks awfully close to the G5LE.

5. I realize there appears to be NO "pin 1" square-pad on the interconnect to the ultrasonic module, but any ideas on how to silkscreen something to reduce chance of hooking up backwards for the case where a 4-wire cable connects the PCB to the sensor module?  That is, if the PCB and sensor module are separate, the PCB might be mounted "upside down" under the layout and hence be backwards requiring additional attention to detail. The module seems to use silkscreen lettering (Vcc Trig Echo Gnd).  Alas, I have no constructive suggestions.

Last edited by stan2004

Add Reply

Post

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
Link copied to your clipboard.
×
×