Pelsea

The simple crossing signal circuit was designed to be operated by a manual switch, but it's fairly easy to automate it. This thread will start with a basic two detector version but eventually I hope to present a way to add as many detectors as you like and a time delay circuit to let trains clear before releasing the crossing. This circuit depends on ambient light to operate, but the level needed to trigger it is adjustable.

This is the schematic:

ctorComp.png 

This is really two independent circuits with their outputs connected together. Each has three design elements-- a voltage divider with a photo resistor as the bottom half, an operational amplifier used as a comparator, and a high current output IC called a "Darlington Pair". (The latter is not entirely necessary, a simple NPN transistor can be substituted for low current applications like lighting an LED.) These parts will be described in some detail in the following post.

pqe

Reply 0
Pelsea

The characters

SD01b.png The detector circuit uses an arrangement of resistors known as a voltage divider. That's not complicated, just two resistors connected in series between a known voltage (like the power supply) and ground. The point where the resistors connect will have a voltage that is in proportion to the values of the resistors. If the resistors are the same, the voltage at the connection will be half of the supply. If the lower resistor is smaller than the upper, the voltage will be lower than half the supply. Since the same current flows through both resistors, Ohm's law makes this so. The lower part of this voltage divider is a photocell (photo resistor), which has a high resistance in the dark and a low resistance in the light. That means that if the photocell is in the track, the voltage will go up when a train blocks off the light. Note that I have not specified a value for the top resistor in the voltage divider (just the enigmatic R).You are going to have to figure that out from the resistance value of your photocell.

8001_sml.jpg 

This is what a photocell looks like. It is a resistor, so there is no polarity. They can be found from many suppliers, but there's a lot of variation as to exactly what is available- The one I used is called a P8001. Set the value of the resistors marked R as half of what the photocell measures in the dark.  If your photocell is 3K with your thumb on it, R should be 1.5k.

 

 

SD01c.png A comparator is a device that has two inputs, one marked + and one marked - . (The inputs are called non-inverting and inverting.) If the voltage at the + input is more positive than the -, the output of the device will be at the positive power supply. If the opposite is true (+ lower than -) the output will be at ground. We will use the comparator to compare the voltage at our photocell with an adjustable reference voltage. The reference comes from another voltage divider, this one a potentiometer (tapped resistor, you will remember) connected be tween +12V and ground. Potentiometers that are use for occasional adjustments instead of as panel controls are often called trimpots.

impot-sm.jpg    pot.png 

Trimpots come in a variety of shapes, so if yours doesn't look like this one, you should verify the connections with your resistance meter. The resistance between the ends will always be the value of the part. The resistance between either end and the wiper will vary as the screw is turned.

TL082.JPG 

The comparator itself is actually a device called an operational amplifier, and comparator is only one of many possible uses. The TL082 package has two of these devices, which makes it handy for this circuit. (There are probably a thousand operational amplifiers, or op-amps out there. I chose this one simply because I have some around. It is cheap, rugged and performs quite well in the kind of audio circuits I build most of the time.) If you wanted to expand the circuit to include four detectors, the TL084 package has four of them. When it comes to wiring up this chip, there is a common power and ground for all devices, but they are otherwise completely independent.

Once the comparator is in the circuit, the output will go high when the photocell is in the dark. This will turn on the connected transistors. Engineers spend most of a year studying the ins and outs of transistors, but for the purposes of this and any other simple circuits I will present, you can think of it as a switch.

2n3904.jpeg               TIP120.png 

The important thing with any transistor is to get it hooked up right way round. The pins on a transistor are labeled Collector (C), Emitter (E) and Base (B). Note that the emitter is marked with an arrow in the schematic symbol. That  arrow in the symbol should point from positive to negative.

There are tens of thousands of transistors out there, but I will stay with the two types illustrated above. The 2n3904 on the left is a low current device, limited to 200mA. That's plenty for most things, but when serious current is needed, I grab a TIP 120, which is shown on the right. (It is actually a pair of transistors that share a case.) These are both NPN type transistors which means the emitter arrow is Not Pointing iN. 

SD01d.png 

As I said, these transistors are used as current switches. We connect the collector to the power supply or the emitter to ground. The thing we want to power gets connected either between the power supply and the collector or between the emitter and ground. In either case, when the voltage at the base is fairly high, current will flow, but when the voltage at the base is near ground, current will not flow. Thus, a switch. There needs to be a resistor in there somewhere to limit the current, but that is generally a part of what we are turning on.

The two parts of our circuit come together at the right, where the emitters of the transistors are connected together. This is where we connect the blinker circuit, or any other load, such as an LED for occupancy indication, or a solenoid for a crossing gate. The resistors shown in the schematic probably won't be necessary, their job is to make my circuit simulation program happy. The resistor marked load represents the thing we are powering, and the resistor marked limit will control the current to the load if needed. For instance, if this were powering an LED, the limit resistor is the one we always have to include to control the brightness. (And keep in the smoke.)

Here's the circuit on a solderless breadboard:

SD01a.jpg 

The black box at the lower right is the trimpot. Note the power connections and the yellow wires that go to pins 2 and 6 of the IC. The green wires connect the photocells to pins 3 and 5. The two resistors go to pin 1 of their TIP 120, and the yellow wire above the IC connects the emitters of the TIP120.The output wire is the yellow one that goes off the left edge.

I'm going to have to rearrange things on the blinker circuit board to make room for all of this, but I think I can make it fit. That will turn up in a day or two.

pqe

Reply 0
HVT Dave

No schematic

PQE,

The schematic in the opening post doesn't show up in Chrome or IE, just a small symbol.  Am I missing something?

Dave

Dave

Member of the Four Amigos

 

Reply 0
NormanW

No schematic

No schematic on Android tablet either.

Reply 0
Pelsea

Schematic

 Weird. Now I see it now I don't. It's on the server, the URL is valid, but it keeps going away. I reloaded it, so try clearing your cache. In any case, here it is again:

ctorComp.png 

pqe

Reply 0
pschmidt700

I see it in Chrome

Coming across just fine, Pelsea.

Reply 0
BruceNscale

Bulk Photocells Pack

Hi Pelsea,

Check out eBay for bulk packages of photocells.  Cost drops to 10 cents each.

 

ignature.jpg 

Happy Modeling, Bruce

Reply 0
timbowilts

Distance from circuit to photocells

Stupid question time from across the pond. Is there any upper limit on the lengths of the connections to the photo resistors?

Reply 0
Pelsea

Distance

Well, I haven't tested this with long runs, but any problem should be manageable by adjusting the trim pot. Route the wires away from any interference sources such as power transformers.

pqe

Reply 0
dapenguin

both circuits on one board

I redrew this on graph paper and got both on one 30 column board.

Start this circuit (detector) on column 1 rather than column 11 so that column 3 is your load rather than 13.

The flasher circuit starts on column 16 rather than 6. Column 3 of the detector feeds to column 16. 

Power comes in at column 14.  If you move the connection on 15 to 17 the power can use 14 & 15, Using the a-j holes as jumpers tp feed both top and bottom.

Columns 18, 29, & 30 and maybe 17 are empty.

So does the above still work?????

?? For the flasher circuit, I did not see a connection to pin 4 on the breadboard ??

awaiting you critical comments,
TCC:}

TC Carr
Malheur, Kopperton & Tejas * Sn3½ in 1923
(the I don't know yet) * Sn2 "Gilpin in Idaho"
​Anaconda, Oregon & Pacific * S Scale Heavy Electric
My Blog Index

Reply 0
Pelsea

Pin 4

That's a bit of an oopsie. Pin 4 is the reset, which clears the output when brought to ground. Connecting it to the positive rail is a safety feature, because an unconnected pin can do random things. The result is an occasional hiccup in the blinking pattern.

Good eye.

pqe

Reply 0
dapenguin

ur velcum{)

Now if my phone will just send me the photo I took of my doodling.

TC Carr
Malheur, Kopperton & Tejas * Sn3½ in 1923
(the I don't know yet) * Sn2 "Gilpin in Idaho"
​Anaconda, Oregon & Pacific * S Scale Heavy Electric
My Blog Index

Reply 0
Pelsea

Delaying the shut off

One potential problem with this version of the detector is that with only two sensors it might not work well with an actual train. I'm confident that the lighting on most layouts will trigger it reliably (I've tested it in the near dark), but it's possible that there may be enough light between cars to let the blinker stop briefly and restart. Extra sensors will help, but unless you space them really close together, there will always be a time when only one is in play. One solution is to add a time delay when the circuit shuts off. If the lights keep blinking a few seconds after the caboose clears the crossing, the problem is solved, and the operation is more protypical to boot. So all we need is a circuit that turns on instantly, but keeps going for a bit after the on signal is removed.

When I have a timing problem, I always look at the 555 IC first. We have already seen the "astable" mode of the 555, where it goes on and off in perpetuity. That's the heart of the crossing signal. The 555 also has a "monostable" (or one-shot) mode, where a trigger pulse causes it to turn on for a set time. Here is the schematic:

layedOff.png 

Note that pins 6 and 7 of the 555 are connected together. That's what makes this a one-shot. Normally, pin 7 is at ground. That means the 10 µF capacitor is discharged (0V). When the chip is triggered, pin 7 is let go, so the 270k resistor will slowly charge the capacitor up toward the power supply. The trigger also sets the output high. Pin 6 measures the voltage on the capacitor, and when it reaches 2/3 of the power supply, pin 7 gets grounded and the output is shut down. The time the output will be high is set by how long it takes the capacitor to charge to 2/3 of the power supply. That turns out to be slightly longer than the value of the capacitor times the value of the resistor, in seconds. The value of the capacitor is 10 microfarads, or ten millionths of a farad. That means we would be talking very short times, except the value of the resistor is 270,000 ohms, putting the cycle at just under 3 seconds. (Play with the time by changing the resistor.)

We want the output of the 555 to continue powering the blinker after the power from the detector shuts off. The two diodes route the power that way while preventing the output of the 555 and the output of the detector from interfering with each other. The only fly in the ointment is the trigger input to the 555 must be a brief negative pulse that goes below 1/3 the power supply and returns to above 2/3 the power supply before the timing interval is over. The output of the detector just goes to 0 volts and stays there. To fix this, we take advantage of a peculiar characteristic of capacitors. Here's a drawing that illustrates what goes on:

capcycle.png A capacitor consists of two conductive plates separated by an insulator. When a voltage is connected across the capacitor, current flows into one plate, and an equal current flows out of the other plate. This leads to a buildup of electrons on one side of the insulator and a deficit of electrons on the other. When the insulator has as much of this as it can take, the current stops flowing. If you remove the voltage and connect the plates together, current will flow the other way as the electrons get themselves back into balance. That discharge current is heavy at a first but slows down as the equilibrium is restored. If you measure the voltage on the back of the capacitor, you see a spike when the applied voltage changes, and an opposite spike when it changes back. Interestingly, if you change the voltage fast enough, the signal will appear to go right through the capacitor with little change.

Our circuit uses the 100nF (that's 0.1 microfarads) capacitor to apply such a spike to pin 2 of the 555. The associated resistors are there to adjust the voltage at pin 2, keeping it higher than 2/3 the power supply most of the time, but the spike pulls the voltage to ground. So, to recap: When the detector output goes high, it powers the blinker via a diode, so the blinker will keep going as long as the detector is in the dark. When the detector output goes low, the 100nf capacitor applies a negative spike that turns on the 555, giving the blinker three more seconds of power through the other diode.

Here's the circuit on the breadboard:

SD04d.jpg 

The green wire is the output of the detector, the yellow wire is powering the blinker. Note the two diodes with their black stripes facing the yellow wire. These are 1n4148 diodes, but practically any will do. The brown disc next to the diodes is the 100nf capacitor. This is a ceramic style, and non polarized.

Here we see everything in action:

SD04b.jpg   SD04c.jpg 

Blinking on the left with my finger in place, still blinking after my finger is removed. Three seconds later, not blinking.

My next job is to put all of this on one board.

pqe

Reply 0
dapenguin

556?

Why not use a 556 and build this into the blinker circuit?

On a separate note;  Can the 'blinker' circuit be used to power a wigwag using two (2) electro magnets rather than diodes???

TCC:}

TC Carr
Malheur, Kopperton & Tejas * Sn3½ in 1923
(the I don't know yet) * Sn2 "Gilpin in Idaho"
​Anaconda, Oregon & Pacific * S Scale Heavy Electric
My Blog Index

Reply 0
Pelsea

one 556 vs two 555s

Well, it won't work for this design, because the delay 555 has to supply power to the blinker 555, and in a 556 both devices share the power and ground pins. Perhaps something could be done with the reset of the blinker, but added complexity will be needed to shut off the LEDs. Mostly its because I have a bunch of 555s in a drawer here, but no 556s.

I like to use a 556 when two timers are needed in one circuit, like a variable rate pulse generator with a fixed pulse width, but if the circuits are independent I use individual 555s. The layout of external parts is usually easier-- they get pretty crowded around a 556.

The 555 will handle 200 ma, so you could probably handle a couple of small solenoids, but I would probably do something along the lines of the high current flasher on this page. (This uses a 556, with the second unit as an inverter.)

pqe

Reply 0
pschmidt700

Go, Pelsea, go!

Quote:

The value of the capacitor is 10 microfarads, or ten millionths of a farad. That means we would be talking very short times, except the value of the resistor is 270,000 ohms, putting the cycle at just under 3 seconds. 

What would happen with a larger cap (100microfarads) and a 27K resistor? Same time constant (2.7 seconds), but would the larger capacitance have an adverse effect on the circuit?

Reply 0
Pelsea

Time constant

The combination of 100uf capacitor and 27k resistor would work the same. We try to avoid bigger capacitors because they are, well, big. They can also have leakage and internal resistance which lead to imprecise operation.

Incidentally, the time constant is the time it takes the capacitor to reach 63% of the supply voltage, but since the 555 flips at 2/3 voltage, the operation period is actually 1.1*R*C.

pqe

Reply 0
Kevin Rowbotham

Indeed, Do go on!

Interesting stuff.  Nice tutorial.

Looking forward to more.

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Pelsea

The Grand Finale!

I have combined all three circuits onto a single board:

SD05a.jpg 

This could be a bit more compact, but I have learned not to try to use every single pad. When things get jammed together it is hard to build and hard to debug. As you can see, I have expanded the detector section to include 4 photocells-- I'll show the changes required to do that a bit later. Both the detectors and LEDs are connected via headers. In the final installation with the LEDs in flasher crossbucks and the photocells in the track, there will probably be some barrier strips or other connectors involved as well.

Here is the board without the test doodads:

SD05b(1).jpg 

As you remember the detector circuit at the right powers (via some purple wire and a diode) the blinker circuit when any of the photocells are dark. When the power from the detector goes away, the delay is triggered via the capacitor seen on row 26. The delay supplies power to the blinker (another purple wire and diode at row 20) for an additional 3 seconds. Both power connections can be seen in this close-up:

SD05h.jpg 

In order to make this power switching work, I had to disconnect part of the + buss from the rest of the board. (I marked the isolated section, which runs from row 3 to 13 with some red marker). I cut the trace with a # 16 Xacto blade, leaving it as shown here:

SD05g.jpg 

The circuit is otherwise laid out exactly as presented in the blinker circuit thread.

Here is a close-up of the delay section. 

SD05d.jpg 

The duration of the delay is controlled by the resistor and capacitor at the top of row 22 and 23. Make either one bigger for a longer delay before the blinkers shut down. The resistors at the bottom of the picture work with the small ceramic capacitor at the right to trigger the delay when the power from the detector shuts off.

Increasing the number of inputs to the detector is simple. Here is the schematic for four:

Comp2(1).png 

(Drawing corrected 9/7/15)

You can see it is a bit repetitious. A single section is an opamp comparator with a photocell and resistor on the inverting (-) input and a reference voltage on the non-inverting (+) input. The out put is connected via a 10k resistor the the base of a 2N3904 (npn) transistor. The collectors of the transistors are all connected to positive power, and the emitters are all connected together. It is this emitter buss that provides power to the blinker. (I used a TIP 120 transistor in the first version to ensure there would be power for anything you wanted to hook up. The 2N3904s are more than capable of driving the blinker.) If you should feel the need for even more inputs, just add more of these sections.

Here's the expanded detector:

SD05e.jpg 

All four opamps are contained in the chip, a TL084. Here is the way the devices are fitted into the chip:

TL084.jpeg 

Notice the power connections. There are several popular quad opamp packages, and some of them are connected quite differently. Always consult the data sheet before hooking up.

Here's another angle on the detector showing some connections that were hidden above;

SD05f.jpg 

There are some parts here that are not shown on any of the schematics. I am referring to small (.01µf) capacitors that are connected to the positive power and ground buss here and there. There's one on row 37 at the bottom of this photo. There should be one near each chip. Their job is to catch any power spikes generated by the chips as they switch on and off.

This view also shows the orientation of the transistors. These particular devices are set up so as you look at the flat face, the leads are emitter, base, collector from left to right. There are 6 possible ways the leads could be arranged, and believe me, every single one can be found on some transistor somewhere. Again you must consult a data sheet before hooking up. Luckily, data sheets for everything can be found on the net- just search on the part number.

About wire colors- My circuits tend to be colorful, but the choice of colors is not random. I've found that a bit of fanaticism about wire color pays off in the long run because it makes the circuit much easier to follow. It may vary a bit from project to project (depending on what wire I have around), but I always use red wires for the positive power, blue for the negative, and black for the ground. (OK, there's some blue ground jumpers in the earlier posts, but I was out of black, and anyway ground is the negative supply on those.) This project uses yellow and white for inputs and violet or brown for outputs.

About capacitor values. There is nothing so confusing as the markings on capacitors. And unlike resistors, which any meter can easily check, you have to spring for a $200 Fluke to measure capacitance. Big caps have a label printed on the side-- something like 10µF (that's a microfarad- a farad is lots of charge. I mean LOTs.) Small capacitors used to be marked in micro-microfarads (mmf), but a few years ago that unit was changed to pf (picofarad). There's not much room on these things, so all you get is a number- 0 to 99 is straight pf. Above that it gets weird. The system works like resistors, but with numbers instead of colors. So a 100 pf cap is labeled 101. The midrange gets even stranger. If there is a decimal point, the unit is µf: .1 .01 and .001 are really common sizes. But those sizes might also be listed in pf, so they would be 104, 103 or 102. And now there's a new unit, the nanofarad, which is a thousand pf. So the same three could be 100n, 10n or just 1n. Electrolytic caps (the bigger ones) also have a voltage rating on them. It's a good thing these are in plain English, like 16v, because if you exceed their voltage rating, they may explode. Incidentally, capacitor values are only accurate within 20%, so if a circuit is a bit out of tune, just grab another cap of the same value-- it may work better.

That's a wrap for this project- there are always modifications and improvements possible, but I think I've got the basic function covered. As always, corrections and brickbats are welcomed.

Thanks for looking in.

pqe

 

 

Reply 0
Steve_F

Thanks

Thank you for taking the time to show how you did this. It has helped me in building an unrelated project, the first time I have used a proto board!.

Reply 0
edfhinton

Following along - Detector circuit question

I have yet to have my parts arrive to start playing, but looking at your write-up of the detector circuit I am thinking I must be reading something incorrectly either on one of the diagrams or looking at the photo of the wiring.

You describe the inverting input as the (-) and the non-inverting as the (+).  In the circuit diagram and description you show the inverting (-) as the one connecting to the photocell and resister (and the non-inverting going to the pot.) The chip diagram you show appears to have the non-inverting (+) inputs closest to power, but it looks in the picture like those connect with the white wires to the photocells whereas it looks like the inverting (-) are connected with the yellow wires to the pot.  

Is there something I am misreading or perhaps not interpretting the components in the photo incorrectly?  Or are the inverting and non-inverting reversed from what was described and does it matter?

Thanks,

-Ed

 

----------------------------------------------------------------------

Proprietor - Northern New England Scenic (V3). N scale NH B&M Eastern and western coastal routes in the mid-1950s.

https://nnescenicmodelrr.com

 

Reply 0
edfhinton

Partially answered my own question...

I think I see part of my answer.  The diagram in the grand finale post shows the non-inverting and inverting inputs connected reversed from what the diagram in the start of the thread showed.  So it appears to me (again, if I am reading correctly) that the actual build matches the original diagram, not the one in the grand finale post.  

So that brings me just to the last part of my question - does it matter?  If wired as shown in the grand finale diagram, would it also work?  I am a big believer in understanding not only how to follow how to do something but also why, as I think it helps when unexpected things happen or for troubleshooting.

Thanks so much for these posts.  I am really looking forward to having parts to try some of this out, starting with the simple circuit from the first thread and then if I find it as much fun as I suspect I might then graduating to some of these other circuits.

Thanks,

_Ed

 

 

----------------------------------------------------------------------

Proprietor - Northern New England Scenic (V3). N scale NH B&M Eastern and western coastal routes in the mid-1950s.

https://nnescenicmodelrr.com

 

Reply 0
edfhinton

My guess at the answer...

I am going to try to answer the rest of my own question - and perhaps you can let me know if I have it correct or not. Re-reading the beginning of the thread, I believe it is saying we want the detector to emit a voltage when the photocell is blocked by the train to get the transister to turn on (current to flow).  So I am surmising that if we followed the circuit diagram showing the 4 detectors in the grand finale post with the non-inverting and inverting inputs reversed, then I think we would get the opposite effect, causing the transister to turn on when there is no train present.

Do I understand it correctly, and that therefore it really does matter which drawing of the circuit to follow?  (Although I suppose if I am correct and you correct the diagram then none of my quesitons on this will make sense anymore.)

Thanks,

-Ed

 

----------------------------------------------------------------------

Proprietor - Northern New England Scenic (V3). N scale NH B&M Eastern and western coastal routes in the mid-1950s.

https://nnescenicmodelrr.com

 

Reply 0
Pelsea

Big oops

The diagram at the beginning of the thread and the text descriptions are correct- the reference voltage is connected to the  inverting inputs and the photocells to the non-inverting. You are correct about the effect-- the blinker would blink when any photocell was in the light. I screwed the drawing up trying to get it to fit onto a single page. It's fixed now (I hope).

Thanks for pointing that out. I'm glad someone is giving these the eagle eye. 

pqe

Reply 0
edfhinton

Glad I understood it...

Thanks for checking it and confirming I understood the impact that reversing those would have.  

This is reminding me why in college so long ago I almost double majored in EE (I was CS).  Sometimes I wish I had taken the few extra courses I was missing.  But a big turning point was almost electrocuting myself because someone had left a plug with two exposed wires as a tail with the plug sticking out from under a metal cased oscilloscope.  When I plugged in the oscilloscope (it was a lab course), it did not get power.  I discovered after a few minutes that I had not plugged in the oscilloscope.  I had plugged in the tail with the exposed wires.  I wonder to this day if I would be typing this if the hot exposed wire had been touching the metal case of the unplugged oscilloscope while I was touching the same metal outer case.  

-Ed

----------------------------------------------------------------------

Proprietor - Northern New England Scenic (V3). N scale NH B&M Eastern and western coastal routes in the mid-1950s.

https://nnescenicmodelrr.com

 

Reply 0
Reply