Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Help with photoresistors needed

2072 views
8 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    January 2016
  • 42 posts
Help with photoresistors needed
Posted by BigCityFreight on Thursday, February 6, 2020 7:43 PM

This is a follow-up to my "boosting IR sensitivity" thread from a few days ago. One person suggested switching to LTR-301 photoresistors so I decided to try that. The good news is that I wired one up, plugged it in and it activates the signals, so I know it works with the board the signals are plugged into.

The bad news is that it's working the opposite of what I want it to do, meaning that instead of turning on when the photoresistor is in the dimmed light, it's turning on when it's very bright, such as when I add my cell phone light or work light to the room lighting.

As a newbie to all of this electronic stuff, I read up on some things and watched some videos and from what I can tell, the only way to make this a "dark" detecting circuit (ie the trains are blocking the light as they pass overhead, thus activating the grade crossing signals) is to add a transistor in a circuit along with a 100k resistor, like this one: http://www.learningaboutelectronics.com/Articles/Dark-activated-light-circuit.php (minus the LED and the 330ohm resistor, since I don't need those, I assume).

Some more detail: The two wires from the signal board (one for the collector and one for ground) show about 4.3 on my multimeter. When light is added to the photoresistor, it drops close to zero and the signals activate - this is the same thing that happens for the IR sensors that I have hooked up.

Is my transistor guess correct and if so, is there anything else I should know before trying to build this circuit? And would the 2N3904 NPN Transistor used in the demo above be fine for my application? 

As always, thanks!

  • Member since
    March 2008
  • 409 posts
Posted by ba&prr on Thursday, February 6, 2020 9:58 PM

If the board you're using is set up for IR detection, I don't think you can use photocells. I use Logic Rails board. I started with the photocell one but sent in for the IR upgrade. It came with the IR emiters and detectors and a new chip. They offer a chip replacement for photocell application:  https://www.logicrailtech.com/xcart/product.php?productid=16274&cat=260&page=1  You may need this.   Joe

  • Member since
    July 2009
  • From: lavale, md
  • 4,641 posts
Posted by gregc on Friday, February 7, 2020 4:17 AM

BigCityFreight
Is my transistor guess correct

yes

the detector of the opto you have is the collector-emmitter of a phototransistor.

the opto detects a reflection off the bottom of car passing over it.   presumably, your photoresistor is detecting ambient light which is blocked when a car passes over it.

if this is correct, it's possible to replace the opto with the resistor, photo-resistor and transistor.   however, it's not clear if you can simply connect the resistor to the emmiter side of the opto circuit for voltage and if both the emmitter and detector have a common.   presumably there is a resistor in that emmiter path, one possible way shown below

   

greg - Philadelphia & Reading / Reading

  • Member since
    December 2016
  • 168 posts
Posted by speedybee on Friday, February 7, 2020 8:52 AM

You're on the right track (pun intended) with using a transistor like the 2N3904 to "flip" the signal.

As it is wired now, the circuit detects what voltage is on the collector pin of a phototransistor. Originally this was the phototransistor in the TCRT500L; now you're swapping in the LTR301. Either way, this pin is pulled up to 5V via a resistor. When light hits the phototransistor, the phototransistor conducts, and drops the pin to zero volts. When the phototransistor is in darkness, it does not conduct, and the pin remains near 5V.

 

The problem is that the circuit was designed to think that "brightness" meant reflection of IR, meant train. Now it's the opppsite. Brightness = ambient light = no train.

 

So, the pin that the board uses to detect a train needs to be inverted. This is where your 2N3904 comes in. Instead of the phototransistor (LTR301) collector being directly connected to this detector pin, connect this detector pin instead to the 2n3904 collector. Then, connect your LTR301 collector directly to the base of the 2N3904, and pull these two up to 5V via a 22k (ish) resistor. Note that you already have a source of 5V in the wires that used to go to your TCRT5000L: the one that used to power the infrared LED via a 150ohm resistor, and now does nothing. But you must insert the 22k resistor in series between the 5V and the 2N3904base + LTR301 collector, or there'll be too much current.

 

Oh and of course connect both emitters, the 2n3904 and the LTR301, to the ground pin.

 

I can explain in more detail or a drawing exactly what connects where later, if needed, but at the moment I need to get a coat of varnish on some furniture.

 

edit: also, I'm not trying to be nitpicky about names here: but since you're trying to learn about electronics, you should know that both the LTR301 and the device you're replacing with it are phototransistors, not photoresistors. A phototransistor and photoresistor can perform similar functions, but they are different devices and work differently, and should not be confused with each other.

  • Member since
    January 2016
  • 42 posts
Posted by BigCityFreight on Friday, February 7, 2020 2:10 PM

Speedy - thanks for the details (and the correction on my terminology). A diagram would be helpful, if you don't mind.

Todd

  • Member since
    December 2016
  • 168 posts
Posted by speedybee on Saturday, February 8, 2020 8:32 AM

So here are two drawings. The first one shows how I think the circuit originally works with the TCRT500L, from what I can see in the photos on the ebay listing.  The stuff in the box is on the circuit board. The point is, we don't want to have to alter anything on the circuit board if we don't have to.

 https://ibb.co/f8pnXY9

Next image is what we can plug in to the circuit board to make it detect trains properly. There's two external components: the LTR301 (collector pin labelled C, emitter pin labelled E) and the 2N3904 (base pin labelled B, collector pin labelled C, emitter pin labelled E). Again the stuff in the box, the 1kohm and 150ohm resistor, are already existing on the board. I drew them on the picture because they're relevant to how the circuit will work.

 https://ibb.co/PWPy86M

But in my pictures, I drew the three pins on the plug as 5V at the top, train detection in the middle, and GND at the bottom. I did that only to make the drawing easier to draw and read. That's probably not the order they're actually in. I can't really tell from the photos, but it'll be easy for you to figure out.

In the original wiring that came with the circuit, the "5V" external wire (in quotations because it goes through a 150ohm resistor) goes to only to the infrared LED (the blue dome in the TCRT5000L). The train detection wire goes to only the infrared phototransistor (the black dome in the TCRT5000L). The GND wire goes to both.

Or, you can use a multimeter measuring. The train detection wire and the 5V wire should be connected via 1.15kohm resistance. The 5V wire should be directly connected to one of the ends of the 150ohm resistor on the bottom of the board near the plug that goes to the phototransistor. The train detection wire is directly connected to one end of the 1k resistor. The GND wire is directly connected to GND somewhere else on the board, eg, the GND pin of that L7805 regulator.

In this drawing I put a 33k ohm resistor going to the collector of the LTR301, whereas before I said 22k ohm. Basically, a higher resistance value means that the LTR301 needs less light to function. 33k ohm is probably a good guess to start with. But you find that it's not sensitive enough to light, so that you have to shine a light directly at the LTR301 to turn off the crossing signal, that'll be pretty easy to fix, but we'll cross that bridge if we come to it.

  • Member since
    January 2016
  • 42 posts
Posted by BigCityFreight on Saturday, February 8, 2020 9:31 AM

Speedy - thanks for the detailed explanation and the drawings - very helpful! Between my "studies" and your explanation, I have a much better idea of what's going on. I have the parts I need on order and am looking forward to wiring this up.

Thanks for taking the time - much appreciated.

Todd

  • Member since
    December 2016
  • 168 posts
Posted by speedybee on Saturday, February 8, 2020 9:06 PM

Have fun! and as always, have your datasheets handy and assemble on a breadboard first to make sure it works, before commiting to solder.

If you have a 100k potentiometer hanging around, you could use that instead of the fixed resistor, and adjust it to whatever works well. My guess is that something in the range of 22k to 68k would be fine.

  • Member since
    January 2016
  • 42 posts
Posted by BigCityFreight on Monday, February 10, 2020 10:31 AM

Update: Got it working! Did up a test rig and it works fine with the 33k resistors. I'm now in the process of changing over my six IR detectors to these phototransistor ones.

For anyone looking at this in the future, the second image has the pins mislabeled for the transistor - the base (B) is the middle pin, so switch the C and B labels on the sketch and it works fine.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!