Skip to main content

Stan, tried your approach and it works perfectly. Using a 5.1K resistor I get relay activation and very good sensor sensitivity.

As to a sensor approach on the TT. We currently have 9 different locations for the TT. We are using a stepper motor/Arduino for position control. The stepper controller provides selectable steps/rev (up to 6400) plus the stepper to TT is gear driven for further resolution. We use a limit switch for initial positioning and the spur/engine house track fixed locations are in a table generated with a calibration program. There are currently only 2 main line entry/exit points and I am just trying to add a safety feature to prevent an engine from going into the pit if I have not positioned the TT. The TT is very complex and adding even a single emitter would be a mess.

I think I will use a 2nd relay to disable the sensor function and will activate it from the control panel, where I only have 12VDC available (5V is provided from a regulator under the layout near the slip ring and is fed off a 12V bus. My relays are all 5V, so can I just add a larger resistor (like 12K) from 12V to the relay control input?

Ken

 

As I understand it, you want a control panel bypass/over-ride switch that prevents any of the relay modules from triggering.  But you only have 12V DC at the control panel.

Assuming the 5V and 12V DC share a common Ground, you could do something like this which does not require an additional relay.

kens trains IR 1

That's good thinking to extrapolate using a 12K (instead of 5K) resistor since you have 12V instead of 5V DC.  12K is kind of an unusual value for the weekend-DIY'er so you might find 10K, 15K, 20K work equally well.

So if the control panel switch is "open", then 12V DC is not supplied to any of the relay modules (only 3 shown above using the miracle of cut-and-paste).  So none of the relay modules can trigger whether their respective beams are broken or not.

Attachments

Images (1)
  • kens trains IR 1

Stan that's a great suggestion, but one problem. As I said the TT is complex. Under the table is a set of electronics/relays to activate sound--(currently also trying to learn how to use DFPlayer module to replace that stuff). Power (~5.4VDC) to that audio setup and to the TT (via the slip ring) is supplied from a voltage regulator that receives 12VDC. I could add a 2nd voltage regulator to supply 5V to the detection/override functions. I guess it's a matter of what is most convenient and effective. Also, it doesn't seem reasonable to keep those components always powered even if not being used--so maybe that's best approach.

By the way I did keep increasing resistance values and am using 15K.

By the way, if I haven't been too much of a pest, I would really like to know why current level (if that's what is the controlling agent) through an IR sensor affects its' sensitivity (or at least that's what I observed). Maybe I need to check some spec.s.

Thanks again for all of the help & suggestions.

Ken

ken's trains posted:

... I could add a 2nd voltage regulator to supply 5V to the detection/override functions. I guess it's a matter of what is most convenient and effective. Also, it doesn't seem reasonable to keep those components always powered even if not being used-- 

Many options.  My observation was you shouldn't need a 2nd relay.  That is, the control panel toggle switch could either (1) block triggers to the relay modules, or (2) as you suggest simply cut power to the IR relay modules themselves.  

If using method 2), DC-to-DC voltage regulator modules (to convert 12V DC to 5V DC) are about $1 on eBay with free shipping from Asia.

ken's trains posted:

...By the way I did keep increasing resistance values and am using 15K.

By the way, if I haven't been too much of a pest, I would really like to know why current level (if that's what is the controlling agent) through an IR sensor affects its' sensitivity (or at least that's what I observed).

If I understand your question, the IR sensor is not binary "on" or "off" like a toggle switch.  Instead, the electrical resistance between the 2 terminals varies depending on the amount of IR energy hitting it.  More IR energy lowers the effective resistance.  In your application the IR sensor (photo-transistor so actually a semiconductor) is effectively behaving as a garden variety photo-resistor where the resistance between the 2 terminals decreases as light increases.

photoresistor

Apparently you were having a sensitivity issue so that's why I suggested you increase the trigger resistor value from 1K to 5K or whatever.  Increasing the resistor value decreases the amount of current available to trigger the relay.  In your application, the IR sensor shunts or diverts the trigger current.  Increasing the resistor value means less current needs to be diverted to keep the relay off when the IR beam is present.  Thus this increases sensitivity since less IR energy is needed.

Attachments

Images (1)
  • photoresistor
Last edited by stan2004

Stan, thank you for the explanation.

As to sensor (safety) control, it turns out that going thru my many purchases from ebay, I bought a number of rotary switches (I have 2 ZW Transformers and used them to switch tracks & throttles). One of the switches is a 4-pole/5 pos. switch and is perfect for the job. I am not only turning safety functions on/off, I am also selecting a specific track section, illuminating a lamp on the selected track section, and changing ZW throttles based on where the engine is coming from/going to.

And Adriatic, I used the (~) symbol to indicate approximate. I need to fiddle with the regulator output to make sure I have enough 'juice' to drive the servos on the TT without overdriving the optics.

 

Hi all. Well had a little health issues, but back to work.

At this time, the Turntable is done. It is fully functional and ready to demo. However, we have also been working on a drawbridge and the control logic is still in work. When that is done, we will back a video of both in operation and post on youtube (since it will be a long-and too large-video). At that time I will post a link.

In the mean time to use my existing parts, I need some help (probably from Stan). I am using the optical sensor approach to stop trains from running off the table if the bridge is not down. However, the 2-channel relays I have require a LOW to trigger. The circuit I used (Stan's design) incorporated a transistor to provide the additional drive to trigger the 1-channel relays I was using. They required a HIGH to trigger. What I need is a simple inverter or circuit change to get a LOW trigger when the beam is broken. I have enclosed a schematic of the circuit I use with the 1-channel, HIGH trigger relays.

IR Circuit001

Attachments

Images (1)
  • IR Circuit001

Mike I cannot seem to do anything simple. I have 2 outside lines that run around my 26 x 14 room. I have a large inside section that is industrial. I have a narrow walkway between outside & inside. Also, the outside lines cross by 2 doorways for other rooms (cannot block), so that portion of outside lines is moved toward inside. Bridge is to connect outside lines. When up, I can walk through. So, 2 lines must be joined to cross single lane bridge(can't make 2 lane--too heavy). I wish to automate whole process of handling 2 trains waiting to cross bridge without using manual controls.

IR%2520Circuit001

Another option to "invert" the logic is to use the COM-NC relay contacts instead of COM-NO relay contacts.  This may or may not apply to your application.  For example, one school of thought with fail-safe type circuits is to ask what happens if the fail-safe circuit itself "fails"; for example what happens if the 5V power supply drops out?  The relay would then connect COM-NC so one would argue this should be the relay position that disconnects power to the trains … i.e., dead-man switch.

Attachments

Images (1)
  • IR%2520Circuit001
Last edited by stan2004

Stan, so happy you are still here. I may not need the circuit you provided for this application because I think the logic is complex enough that I will be using an Arduino for control. My 2-channel relays can be operated with the Arduino. But your suggestion about using the proper relay contacts makes perfect sense. When beam is detected, relay will be triggered and contacts will be closed. Broken beam or power loss and relay default state is contacts open.

Only question; is it ok to keep relay energized for lengthy period??

What he said.

Of course with any scheme that involves a continuously active relay, the relay coil is consuming power.  The relays used in the eBay modules consume about 1/3 Watt... or about 70 mA at 5V. 

Note that if you end up using an Arduino or similar microcontroller to drive the relay module, you can use a PWM-able (if that's a word?!) digital output to drop the effective voltage.  That is, while you turn on the relay with 5V, once on it will remain closed with only ~2V.  This is a commonly used technique to reduce power...not that you're constrained by power.

Thank you both for the input. And Stan by the way I have used the PWM output to dim LEDs and it's a great suggestion. One more question. If I did not use an Arduino, I would need a circuit to generate a LOW when the beam is detected (for the dead-man-sw approach). The 2 circuits I have produce a H or L when the beam is broken. I found that when using the circuit that triggers with a HIGH and connected to the relay that triggers with a LOW it does not trigger when the beam is detected. So I would need a circuit that toggles H and L.

It never seems to end. I am lost again. I used the circuit with the transistor that produces a high when the beam is broken. I use that output as an input to an arduino. I wrote a simple program that tests the state of the beam (HIGH is broken) and sends a HIGH or LOW (when the beam is unbroken) to the relay trigger. The relay is triggered by a LOW (and I have tested that the arduino will cycle the relay by just outputting H's & L's). My operational code is very simple, but when I run it and the beam is unbroken, the relay just chatters. When I break the beam, the relay opens and stays. My program design keeps the trigger output LOW if the input DOES NOT = HIGH (!=). I have tried many different approaches, but I believe the problem is that the output when the beam is unbroken is floating and causing random H & L. If that is the cause, is there a design solution that will give me a solid GRD output when the beam is unbroken and a solid HIGH (~5v) when beam is broken?

 

If driving an Arduino digital input pin, you need a resistor to define or pull up (to 5V or hi level) the "floating" node when the beam is broken.  The eBay relay modules effectively have such a resistor on its input trigger pins.

LO%20trigger%20when%20beam%20detected

Presumably somewhere in your Arduino sketch you define the digital pin connected to the IR sensor to be an input.  If using pin number X, look for something like:

pinMode (x, INPUT)

Instead, try:

pinMode (x, INPUT_PULLUP)

and, lo and behold, you get: 

pullup

Since your transistor-based circuit is already hooked up, just change the pinMode instruction and you should be off to the races. 

Attachments

Images (2)
  • LO%20trigger%20when%20beam%20detected
  • pullup
Last edited by stan2004

Thanks all of you for your help. However, my circuit board has been made like the schematic above for "HI trigger when beam broken". Therefore, I tried Stan's suggestion, but probably didn't make the correct change to the circuit and it did not produce a LOW to operate the relay when beam detected. I tried Stan's simpler approach (w/o transistor) and worked fine. I can remove (unsolder) all the extra parts and go simple, but would like to know what to do to make existing circuit work--and I did change the input as you suggested on the Arduino. That was all I did to the above 'HI trigger' circuit.

Don't want to be lazy so looked up NPN operation. If I understand, when beam is detected, most current flows to GRD through sensor. Therefore, transistor is off and emitter would be floating. So maybe a resistor from E to GRD would solve problem?

Please forgive me, don't mean to turn forum into electronics course, but if I get better understanding, I can stop bothering you all and show you Turntable and Drawbridge results.

Last edited by ken's trains
ken's trains posted:

Don't want to be lazy so looked up NPN operation. If I understand, when beam is detected, most current flows to GRD through sensor. Therefore, transistor is off and emitter would be floating. So maybe a resistor from E to GRD would solve problem?

Correct.  When beam is detected, NPN is off, emitter is "floating" so a resistor from E to GRD would solve the problem  In this case you should use the regular pinMode (x, INPUT) instead of INPUT_PULLUP.  Someone correct me if I'm wrong, but there is no Arduino that supports pinMode (x, INPUT_PULLDOWN).

HI when beam broken

I realize the NPN circuit is all wired up, but couldn't you just run a jumper wire as shown in purple above?  It's OK to leave the NPN as-is with the E disconnected.

 

Attachments

Images (1)
  • HI when beam broken
Last edited by stan2004

Stan, I need to add a little more to your above simple circuit (the circuit where 'HI when beam broken and no transistor'). Since one of my uses will be to assure that the train has cleared my isolated track section, and since the detector output is an arduino input, I don't want a momentary beam detection to open the relay under control (like between cars--and I know I could place detectors on diagonal but complexity is more fun). So I would like to put an adjustable delay in "beam detection". So when beam is broken, output's at approx. 5V, and then is detected, it slowly falls to it's lowest value. I would then use AC inputs on arduino to define input levels for relay trigger/no trigger (range is 0-255). And yes I could do sw debounce, but this should be easier--except for me.

Stan, I did a more playing. Used your above 'top' circuit with the transistor and also stuff you provided from earlier IR detection circuits. I put a diode between the (2) 10K resistors and a 4.7 uf cap from the diode output to ground. This kinda worked, in that when beam is made, trigger output (only connected to meter--won't trigger relay) very slowly (20-30 sec.) drops close to zero. When broken, fairly quickly rises to almost 5V. That's a pretty small cap and a very long decay time. How best to adjust to something like 2-3 sec. to decay to close to zero? The relay not triggering not an issue since that output will be an arduino input--again using the AC input pins.

ken's trains posted:

.. So I would like to put an adjustable delay in "beam detection". So when beam is broken, output's at approx. 5V, and then is detected, it slowly falls to it's lowest value. 

HI%2520when%2520beam%2520broken

Add a capacitor across the 10K resistor at the output.  When the beam is broken the output quickly rises to approx. 5V.  When beam is detected the output will slowly fall to its lowest value.  The voltage decay will be exponential rather than straight-linear.  But in round-numbers, it will take about 3 x R x C.  For example, if R=10K and C=100uF, it will drop to near 0 in about 3 x 10K x 100uF = 3 seconds.  If you only have, say, 10uF then use R=100K and you'll get about the same decay (3 x 100K x 10uF = 3 seconds).

The output quickly rises because the NPN transistor turns ON when the beam is broken.  The transistor rapidly charges up the new capacitor.  When the beam is detected, the IR sensor turns ON which turns OFF the transistor.  With the transistor turned OFF, the capacitor discharges thru the resistor in parallel with it.  You might get slightly different timing on a voltmeter bench test vs. with the Arduino actually connected because the Arduino pin itself is a load that discharges the capacitor.  OTOH you may not see any practical difference for the matter at hand.

 

Attachments

Images (1)
  • HI%2520when%2520beam%2520broken
Last edited by stan2004

Yes Leo you are correct. That's the problem with composing msg.s late at night.

I tried Stan's circuit using just the digital pin (for input), and there is no delay on the decay as observed on the arduino output to the relay. When I measure just w-meter at the trigger output of the circuit , the decay to almost zero takes several sec--which is what I want. I guess maybe the digital pins toggle on transition? So now I will use my meter measurements & analog pin to toggle on levels and see how that works.

Hi all. Back with another question. I need to trigger 2 remote relays with a single Arduino output. They require LOW trigger. They are far apart (wiring nightmare) and I only ran one wire (actually have 2 sets of these remote relays and 2 wires for each set). Made a test circuit to check. One relay triggers when output goes LOW, but drops out when I connect to 2nd relay.

My thought was to use transistor to provide necessary source current. If I use Stan's circuit above w/o IR sensors and just use Arduino HIGH to turn on transistor, and connect collector to 5VDC so trigger is held HIGH till Arduino goes LOW, will that work. I believe I need approx. 80mA to trigger both. Any better circuit would be much appreciated.

Ken

Stan (and others), I apologize. My issue was the need to LOW trigger 2 relays with one Arduino output. I assumed that since the relays were optically coupled, no problem. But I couldn't get them to activate with the LOW from the Arduino. Finally used brain, put VOM in series with relay trigger pin & ground and measured 1.2mA. So, problem was not an Arduino sourcing limit. Turns out it was a bad breadboard (very typical of stuff I've gotten recently). And Stan, by the way, I modified one of your previous circuits (with a transistor driver before I discovered real problem) and it worked great, but it  should not be required.

Ken

There's also a maximum total current on all the pins I suspect, I can't imagine the Arduino processor will handle 40ma on every I/O pin.

The maximum total current sourced or sinked by the chip is stated as 200mA on the 328p datasheet.  However, the notes suggest that you have to pay attention to current per port if you expect  the rated current or voltage to be delivered on a particular pin:

3. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: ATmega328P: 1] The sum of all IOL, for ports C0 - C5, should not exceed 100mA. 2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA. 3] The sum of all IOL, for ports D0 - D4, should not exceed 100mA. If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.
4. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: ATmega328P: 1] The sum of all IOH, for ports C0 - C5, D0- D4, should not exceed 150mA. 2] The sum of all IOH, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 150mA. If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition.
Last edited by Professor Chaos

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.
×
×