View Full Version : Pull-up Resistor for phototransistor

05-02-2007, 06:46 AM

I'm using an optical switch (a packaged LED and a phototransistor) connected to a BS1. I'm still a novice, so I don't completely understand the difference between using a pull-up resistor and a pull-down resistor. Which one should I use? When is the other used? See attached diagram.

Also, some diagrams have a 220 ohm resistor right before the stamp's input pin. What is this for?

How to choose the value of the pull-up resistor?

At full light, the phototransistor measures 2mA (taken from the datasheet)

So for the pull-up resistor, I calculated a value of 2.2k-Ohms. Is this right? This is how I calculated it:
The stamp reads from high to low @ 1.4v. To play it safe, I assume 0.4V. That leaves .4v across the transistor and 4.6V across the pull-up resistor. R=V/I, so the Pull-up resistor is R=4.4V/.002A = 2.2kOhms

For the pull-down resistor, I calculated a value of 2.2k-Ohms. Is this right? This is how I calculated it
The stamp reads from low to high @ 1.4v. To play it safe, I assume 4.4V. That leaves .6v across the transistor and 4.4V across the pull-up resistor. R=V/I, so the Pull-up resistor is R=4.4V/.002A = 2.2k Ohms


Thank you very much for your help! I am so confused!


05-02-2007, 07:11 AM
I prefer the resistor at the high side, at the top of the xsistor. Then if the xsistor turns on due to the light, it will sink current
and move your input to the BS1 toward GND. or a logic low.

I think you should consider that varying amounts of light will cause a variable current sink and may not turn on enough
to change the input to the BS1 to a valid state.

The link you posted did not work, so I don't know about the photo xsistor.

I usually use the Atmel uP chips but come here every so often. I did experiment with a photo xsistor but it
was interface to the ADC input of the chip. Because the different levels of light, you will not get an absolute digital
on/off signal. Are you planning on using the ADC input?
Hope that offers some help ?

05-02-2007, 07:47 AM
Thanks for the advice. It is actually being used as an optical slotted switch (i.e. something blocks the path between the LED and photoxister).

So is both doable, just a matter of putting current into or out of the stamp?

Here's the link

www-personal.umich.edu/~bobden/panasonic_on1111_photo_interrupter.pdf (http://www-personal.umich.edu/~bobden/panasonic_on1111_photo_interrupter.pdf)

Bill Chennault
05-02-2007, 08:00 AM

Take a look at the FREE downloadable text from Parallax; What's A Microcontroller (http://www.parallax.com/dl/docs/books/edu/wamv2_2.pdf). Specifically, turn to page 189 and all your questions will be answered I think.

I downloaded the text so I would always have it handy on my tablet PC AND bought the book. It is very good.

Have fun!


You are what you write.

05-02-2007, 09:42 AM
Hello Bill,

Thanks for the helpful text, but I am still confused. I am using a photo transistor (not photoresistor), and I'm not sure if either of the circuits are correct?

Chris Savage
05-02-2007, 09:46 AM

The Process Control Guide makes use of a phototransistor. Perhaps a quick look through there will offer you some suggestions. Take care.


Chris Savage
Parallax Tech Support

PJ Allen
05-02-2007, 09:49 AM
Correct for what?
The pull-up circuits·use the photo-transistor as a switch, the "output" has two states [on, off.]
The "pull down" (sic) circuits result a variable voltage across the resistor·correlating to the illumination of the photo-transistor (the base bias.)

Post Edited (PJ Allen) : 5/2/2007 2:54:32 AM GMT

Chris Savage
05-02-2007, 09:51 AM
The only thing I would change about the original circuits you posted is the 6V should be 5V...

Chris Savage
Parallax Tech Support

Phil Pilgrim (PhiPi)
05-02-2007, 11:40 AM

Both circuits (assuming Chris's 5V admonition is adhered to) are fine. Each will produce an output voltage that varies with the amount of light present. What you need to ascertain is whether the Stamp will switch at the light level you want it to. In my experience with phototransistors, no amount of pre-calculation will be adequate to tell you what size resistor to use. You just have to experiment until you find one that yields the correct behavior over the temperature range you'll be encountering. Chances are, if you're using enough LED current and an opaque vane to interrupt the light, the value won't be terribly critical.

I don't know how you're planning to use this device; but if you need very high switching speeds, the simple circuits you've posted may not be adequate. This is due to the Miller Effect, which results from charging and discharging the optotransistor's junction capacitance. There is a way to overcome this, if you need it. But experiment with your circuits first. That's the absolute best way to see how (or if) they work. And if you have problems, the Forum is always here to help.


05-02-2007, 11:01 PM
Thanks for all your help!!!

I just spoke with Chris from Tech Support. From what I gathered, either circuit is plausible, although conventionally, the NPN transistor's emitter is typically connected to ground (while on a PNP the emitter is connected directly to Vs).

As for the size of the resistor, Chris recommended 10kOhm if the transistor was being used as a switch.

My Second Attempt at calculating the Pull-Up resistor (Do I have any idea what I am doing?!)
Looking back I made a mistake about the phototransistor Ic current. I was looking at a graph of LED current If vs Ic phototransistor current (with a test condition of Vce = 10V). My Vce won't get close to 10V, so wrong graph.

I think the right graph to look at shows Ic vs. Vce (test condition: LED current If = 20mA). Saturation occurs at about Ic = 0.8mA, Vce>0.5V. (See Attached Graph)

Then using the graph and the equations:
Vs = Vr + Vce (assumes that Ie~Ic)
Vs = Ic*R + Vce
5V = .0008A*R + 0.5V
R = 4.5V / .0008A
R = 5625 Ohm (~5.6kOhm)

What do you think? Am I totally off-base?

Here's my calculations for a 10kOhm resistor:
Vs = Vr + Vce (assumes that Ie~Ic)
Vs = Ic*R + Vce
5V = Ic*10,000 + Vce

Then, plugging in numbers from the chart for Ic and Vce to see what works...
From the chart, If Ic = .475mA, then Vce ~ .25V

5V = .000475*10000 + .25

This would place the transistor in the saturation zone. Maybe this is better, since it can transition faster?

Chris Savage
05-02-2007, 11:42 PM

In our conversation you indicated you needed only a switched (on/off) detection. But I never asked what was controlling the LED. If the device is always on/off you can determine the correct resistor for 20mA through the LED by using the following formula. I hope this helps. Take care.

(VDD – VFLED) / .020 = R So (5V – VFLED) / .020 gives you the resistor value in ohms, assuming a VDD of 5V.·

Chris Savage
Parallax Tech Support

Post Edited (Chris Savage (Parallax)) : 5/2/2007 4:47:11 PM GMT

05-03-2007, 12:05 AM
Thanks, Chris,

I'm familiar with selecting a limiting resistor for an LED. I was looking at the phototransistor, and just trying to understand electrically what was happening with the 10k Ohm pull-up resistor.

I assumed the graph from the phototransistor datasheet shows the effect of its companion LED (current of If=20mA) on the Vce and Ic of the phototransistor.

Not sure if I am calculating this right though...


05-03-2007, 07:16 AM

This may also help. Please see the attachment.

05-03-2007, 08:47 AM
Thanks. I think I am starting to get it now. Not sure how you arrived at the 10k resistor in the word doc though. In your example, do you take the squareroot of Rmax vs Rmin because of the squared nature of luminosity vs resistance? And the 10k because you want it to be on average a half and half voltage divider at mid-luminosity?


Post Edited (erk1313) : 5/3/2007 4:38:05 PM GMT

05-03-2007, 11:14 AM
The value of the resistor will depend upon the resistance range of your sensor and the luminosity you want to be the trigger-point.

Sometimes it is easier to do a little experimenting to get the value you need- substituting resistors of different values while the sensor is exposed to the target luminosity.