GT Mills
Does anyone have a "latching circuit" diagram for switching power on/off/on to signal lights? 

Purpose:  Model a Michigan C&O, two-light, block signal system.  Here I am keeping the bottom LED constant red, and switching the top 2-color LED  between red and green.

Idea:  Use a latched circuit to switch top LED color. 

Plan:  The train approaches a green/red  block signal, rolls through photoswitch #1 and switches the top green LED to red.  It stays red until the train rolls through photoswitch #2, which switches it back to green.  LED remains green until train rolls through photoswitch #1 again.  

Materials on hand:  10  new Allen-Bradley photoswitches (normal off), 5 ea. diffuse P/N 42SMP-7601 and 5 ea. retroreflective 42SMU-7601. Size 0.5" x 1.125" x 1.125", with adjustable sensitivity.  Diffuse works up to 12" away, reflective works up to 13 ft. away.  These use no external source, IR etc., and they work the same whether in the dark or in bright ambient lighting.  

OK, I got this far ...
IMG_7292.jpgIMG_7293.jpg




Skorpio
  It's worth looking into Arduino for what you want.  Several people have done it and explained how and included the "sketches" required to operate the system.
(2) DIY and Digital Railroad - YouTube   is just one of them, you'll have to look thro' the listing tho' to find what you want.
  As you've worked with electronics before you should grasp the methods pretty easily.
There are many others on YouTube and elsewhere on the internet.
"The N scaler" is one blog worth checking as well  - The N Scaler – 21st Century Model Railroading in N Scale


Keith
Reply 1
trainzluvr
Off hand I'm thinking maybe some flip-flop circuit either with transistors or cheap 74xx logic gates would do the job...why use a hammer (Arduino) to kill an ant?
Reply 3
GT Mills
I'm finding some interesting latching circuits that might work, some using timers, some not. 
Reply 1
Andy Reichert
A standard "Presto "board will do that.  Photo switch #1 sets the led outputs and photo switch #2 resets them. 
Andy
Reply 1
Terry Chamberlain jterryc
Greg,

What you're actually looking for is a 'bistable multivibrator' - a very old-fashioned term for what is essentially a pair of cross-coupled transistors.  Go to  https://www.electronics-tutorials.ws/waveforms/bistable.html   where you will find the following diagram - 

           BistableMultivibrator-Circuit.png

You can use any small-signal NPN transistors, such as 2N3904, for TR1 and TR2 and connect your optical switches (assumed to provide an output which connects to 0V (Ground) when activated) to points A and B  instead of the SPDT switch. Your LEDs connect to the transistor outputs (Q and Qbar) with R1 and R4 set at 1K for a 12volt VCC supply. R2 and R4 can be 10K each.

Using such expensive optical switches is probably not how I (or most other model railroaders) would do it, but if you already have the kit then put it to some use !
Reply 4
GT Mills
Greg,

What you're actually looking for is a 'bistable multivibrator' - ...

Using such expensive optical switches is probably not how I (or most other model railroaders) would do it, but if you already have the kit then put it to some use !


A toggle switch which remains locked in either one position or the other is not going to work.  The"latched circuit" must use a momentary contact switch - in my case the photoswitches I have on hand.   The schematic can show it as a single momentary contact switch, but in practice it will be two photoswitches in parallel. 

Push the MCS once and the circuit goes to closed and lights the  green side of the bi-color LED, and stays green, even though the MCS is no longer closed.  Push the MCS again and the circuit goes to  open, the green side goes off and all you can see is the red side which is always on, but uses a 2x resistor so the green overcomes the red when the circuit is closed and green is lit. 
Reply 1
GT Mills
A standard "Presto "board will do that.  Photo switch #1 sets the led outputs and photo switch #2 resets them. 
Andy


What's a Presto board??
Reply 2
trainzluvr
As I said...Flip Flop

http://www.radanpro.com/Radan2400/Oscillators/Circuits%20Page%209.htm

Problem is that you have an interruptable signal source (IR detector), as cars pass by the sensor will activate and deactivate.

Probably also need some kind of a "buffer" so when the IR detector is triggered, the signal remains active for a specific duration of time. Perhaps charging a capacitor and letting it discharge over time.
Reply 1
GT Mills
trainzluvr wrote:
As I said...Flip Flop

http://www.radanpro.com/Radan2400/Oscillators/Circuits%20Page%209.htm

Problem is that you have an interruptable signal source (IR detector), as cars pass by the sensor will activate and deactivate.

Probably also need some kind of a "buffer" so when the IR detector is triggered, the signal remains active for a specific duration of time. Perhaps charging a capacitor and letting it discharge over time.


Good point.  Field of View for the photoswitch is 6°, should be able to angle the thing slightly to "eliminate" the gaps between cars.

Found what I was looking for here:  https://circuitdigest.com/electronic-circuits/soft-latch-switch-circuit

This design uses one push button switch to latch it on, then latch it off again the second time it's hit.  The capacitor is to prevent false switching from stray currents.  BC547 is NPN transistor,  BC557 is PNP. 


Soft-Latch-Switch-Circuit-Diagram.png
Reply 1
Andy Reichert
GT Mills wrote:


What's a Presto board??


It's a board I designed to operate (i.e. latch on and off or reverse) stall turnout motors and LEDS and other high current devices from (a) separate SET and RESET push buttons and (b) SET and  RESET  logic level signals. 

Sounds like it could be a plug and play for your application. I could always send you one or two to try out.

Andy[PRESTOPINOUTv2-800]
Reply 0
Terry Chamberlain jterryc
Just to clarify things - the bistable circuit I showed does not require the switch to remain closed. You could replace the SPDT switch with a pair of momentary-contact pushbuttons - press one button to switch on the transistor it's connnected to, push the other button to switch on the other transistor. When either transistor is switched on, its output goes to 0V and the output from the other transistor goes to +VCC, since it is switched off by the cross-coupling through R2 and R3.

An interesting (if odd) way you describe switching the LEDs using different resistor values - I don't quite see why you couldn't simply use the different transistor outputs.

Anyway, it will be interesting to see your final solution.
Reply 2
GT Mills
Just to clarify things ....

Anyway, it will be interesting to see your final solution.



The article reads:
"The Bistable Multivibrator circuit above is stable in both states, either with one transistor “OFF” and the other “ON” or with the first transistor “ON” and the second “OFF”. Lets suppose that the switch is in the left position, position “A”. The base of transistor TR1 will be grounded and in its cut-off region producing an output at Q. That would mean that transistor TR2 is “ON” as its base is connected to Vcc through the series combination of resistors R1 and R2. As transistor TR2 is “ON” there will be zero output at Q, the opposite or inverse of Q.

If the switch is now move to the right, position “B”, transistor TR2 will switch “OFF” and transistor TR1 will switch “ON” through the combination of resistors R3 and R4 resulting in an output at Q and zero output at Q the reverse of above. Then we can say that one stable state exists when transistor TR1 is “ON” and TR2 is “OFF”, switch position “A”, and another stable state exists when transistor TR1 is “OFF” and TR2 is “ON”, switch position “B”."

This is a mechanically-latched circuit requiring the switch to remain closed - to either one side or the other - in order to keep that side's transistor circuit open by grounding out the base feeder leg.  If you substitute a momentary contact switch, then the default with the switch open is both transistors always closed/ saturated, both LEDs always on... a "default on" circuit rather than  "default off." 
Reply 1
Terry Chamberlain jterryc
GT Mills wrote:

This is a mechanically-latched circuit requiring the switch to remain closed - to either one side or the other - in order to keep that side's transistor circuit open by grounding out the base feeder leg.  If you substitute a momentary contact switch, then the default with the switch open is both transistors always closed/ saturated, both LEDs always on... a "default on" circuit rather than  "default off." 


Not so - the cross-coupling provided by R2 and R3 maintains one transistor 'on' and the other 'off' - 

       BistableMultivibrator-Circuit.png

If, for example, the base of TR1 is momentarily grounded by a pushbutton switch (or your optical sensor) then TR1 is switched off, ie. it stops conducting, no longer drawing current through R1 and allowing the voltage at its collector (Output Q) to rise to +VCC. Via resistor R2 this also raises the voltage at the base of transistor TR2 to around 0.7 volts, switching TR2 on. This results in TR2 drawing current through R4, bringing the voltage at its collector close to 0V and this is fed back to the base of transistor TR1, maintaining TR1 in the off state - regardless of whether the pushbutton there is operated or not.

A similar (but reversed) sequence of actions occurs if the base of transistor TR2 is momentarily grounded, switching TR2 off and letting its output (Qbar) rise to +VCC which, via resistor R3 switches transistor TR1 on . . . 

I hope that this makes things a little clearer.
Reply 1
GT Mills


Not so - the cross-coupling provided by R2 and R3 maintains one transistor 'on' and the other 'off' - ...I hope that this makes things a little clearer.


I'll make one of these up on a bread board to test tomorrow.  What resistors to use?  I'm thinking  5.9V wall wart power, R1 & 4 = 1K,  R2 & 3 = ~520K,  TR1 & 2 = 2N3904 NPN, and a couple of LEDs.
Reply 1
David Pennington Long Haired David
I outline the Atlas two colour that I drive from an Arduino. The description and the sketch is on my blog at Gentle Model Railroads .

if you need any more let me know.




Reply 2
GT Mills
I outline the Atlas two colour that I drive from an Arduino. The description and the sketch is on my blog at Gentle Model Railroads .

if you need any more let me know.


Thank you David!  Please post it up here if you will, we'd like to see it!  But blog mining for an arduino circuit @ 20x the cost & much more complicated...

Really just looking for a basic transistor-switched circuit.  I could go with a decade timer controlled circuit like the one below, which is pretty cool, but then I'd have to buy the timers...tho $1.60 for 10 won't break the bank, HahA!  Here I'd sub an LED for the relay with its diode sponge and AC bulb, and my photoswitches for the push button switch of course.  But, hey, this circuit is REALLY simple. 
Decade Timer.png
Reply 1
Andy Reichert


Not so - the cross-coupling provided by R2 and R3 maintains one transistor 'on' and the other 'off' - 

       BistableMultivibrator-Circuit.png

If, for example, the base of TR1 is momentarily grounded by a pushbutton switch (or your optical sensor) then TR1 is switched off, ie. it stops conducting, no longer drawing current through R1 and allowing the voltage at its collector (Output Q) to rise to +VCC. Via resistor R2 this also raises the voltage at the base of transistor TR2 to around 0.7 volts, switching TR2 on. This results in TR2 drawing current through R4, bringing the voltage at its collector close to 0V and this is fed back to the base of transistor TR1, maintaining TR1 in the off state - regardless of whether the pushbutton there is operated or not.

A similar (but reversed) sequence of actions occurs if the base of transistor TR2 is momentarily grounded, switching TR2 off and letting its output (Qbar) rise to +VCC which, via resistor R3 switches transistor TR1 on . . . 

I hope that this makes things a little clearer.


You don't have to build those from discrete parts.  Set-reset binaries  come in 2's,  4's and 8's on cheap (a few cents) ) chips going as far back as the 74xx series.  Common, equally cheap, little prototyping  PCBs save 90 % of the wiring up.

BTW, I interpreted the OP as asking for a set pulse signal in one location and a reset pulse signal further down the track  Now we seem to be talking about just toggling at a single position. Could I have some clarification please.

Andy
Reply 2
Terry Chamberlain jterryc
GT Mills wrote:


I'll make one of these up on a bread board to test tomorrow.  What resistors to use?  I'm thinking  5.9V wall wart power, R1 & 4 = 1K,  R2 & 3 = ~520K,  TR1 & 2 = 2N3904 NPN, and a couple of LEDs.


Greg,

You should use 10K for R2 and R3 - 520K will not provide enough base current into the transistors to switch them fully on. The full circuit that you can try is - 

           Bistable+LEDs_Cct.png

With your proposed supply of 5.9 volts, using 270 ohms for R5 and R6 will supply the LEDs with around 15mA, but with modern LEDs the value is not critical.

Andy,

Placing switches S1 and S2 at the required track positions, together with the relevant LEDs (on extended wires, of course) gives Greg the functionality he requested - the rest of the circuitry can be located anywhere that's convenient.

And, yes, I agree that you could do the job just as easily with an R-S flip-flop or a couple of NAND gates, but using discrete components allows Greg to see exactly what's going on - and trace any wiring faults if things don't work as expected - it's a bit more difficult to do this with just a chip on your breadboard.
Reply 2
Andy Reichert
I'd prefer to know the output specification of the photo switch before connecting it directly to the base of  transistor as above. Allen Bradley won't disclose the details as it's discontinued. What a distributor says is that it's a PNP o/p and the power supply is 10-30 V DC . 

Andy
Reply 1
Terry Chamberlain jterryc
Fair point, Andy - I hadn't gone as far as to consider the actual connection of Greg's optical sensors. You are quite right in pointing out that they have PNP outputs and they require a power supply of at least 11 volts to operate. The Allen-Bradley data sheet is attached below for your and Greg's information (if he hasn't already got a copy) .

The PNP outputs mean that the output signal is referenced to the positive supply rail rather than to ground so, to connect it to the bistable circuit given previously, requires the addition of a couple of transistors to invert the outputs from the optical sensors. These transistors (Q3 and Q4 in the circuit below) take the place of the two pushbuttons - 

Bistable+LEDs+OptoSensors-Cct.png

The circuit now runs from a 12 volt supply, with values of the LED resistors  (R5 and R6) adjusted to suit.

When, say, optical sensor XR1 is triggered, its Normally Open output (NO) changes from 0V to +12V, switching transistor Q3 on and bringing its collector and the base of transistor Q1 close to ground. This, as the pushbutton did previously, switches Q1 off - and Q2 is then switched on via the cross-coupling, illuminating LED 2. Similarly, actuating optical sensor XR2 switches Q4 on, Q2 off and Q1 back on - flipping the state of the bistable, extinguishing LED2 and lighting up LED 1.

Hopefully, Greg can try some of this out on his breadboard and see if the circuit works as described.
Reply 2
GT Mills
I'd prefer to know the output specification of the photo switch before connecting it directly to the base of  transistor as above. Allen Bradley won't disclose the details as it's discontinued. What a distributor says is that it's a PNP o/p and the power supply is 10-30 V DC . 

Andy


10-30V input, whatever goes in comes out the switched side of the photoswitch so  I'll need to add a resistor step down circuit  ahead of the latching circuit since most transistors work on ~5v.   Bench power is a 16V DC wall wart, in practice I'll probably use fixed 12VDC.
Reply 1
Terry Chamberlain jterryc
The 2N3904 transistors will work fine with a 12VDC supply - see the full circuit in my previous post
Reply 1
GT Mills
These are the scanned docs that come with the two types of photoswitches, both are PNP switched side normally open. 
Reply 1
GT Mills
...

Bistable+LEDs+OptoSensors-Cct.png

....

Hopefully, Greg can try some of this out on his breadboard and see if the circuit works as described.


THANKS!  I was going to do it a bit differently but  I like yours better.
Reply 1
Reply