# Why am I an idiot and IR transistors...

Here's the encoder part http://www.sparkfun.com/datasheets/Sensors/QRB1114.pdf

This should be simple... resistor pulls the input pin high, transistor clicks and pulls it to ground.

What am I missing?!?!?

## Comment viewing options

Frits you are a very competent person!

Hello CTC,

We might do this as an exercise (no offence intended), these can be difficult devices to work with as they have such a small signal output (1-2ma).

First let’s look at the emitter, basically an IR LED, it needs less than max current of 50ma

If we look at the data sheet the Forward Voltage for the emitter is 1.7V, this is at 40ma, so this is the Voltage across the emitter (i.e. between the anode and cathode). To calculate the resistor (R1) required we:-

R1 = (Vs – Ev)/If

Where R1 is the value of the resistor we need

Vs is the supply Voltage

Ev is the IR LED forward Voltage and

If it the current flowing through the IR LED

So R1 = (5 – 1.7)/4x10e-2

R1 = 82.5 Ω

330Ω will give you about 10ma so this is safe but will probably reduce your detection range, rather the sensitivity, if you look at table 2 this is the relationship between the current through the IR LED (If) and the sensor (Ic)

Now let us look at the sensor:

It is a NPN silicon phototransistor with a saturation voltage of 0.4v and a dark current of almost noting (100na).

I would set this up as an Emitter Coupled Transistor, so the Collector goes directly to supply (+5V) and the emitter goes to the resistor, the resistor to ground, thus when it is dark (ie nothing detected) you will see a low voltage at the Emitter and when an reflective object is detected you will see a higher one.

So from the data sheet we have a saturated forward voltage of 0.4V and say 4ma (see fig 2)

So R2 = (Vs –Vf)/Ic

Where R2 is the Sensor bias resistor

Vs is the supply Voltage

Vf is the Sensor forward Voltage and

Ic it the current flowing through the Sensor (when object is detected)

So R2 = 1152 Ω

This should give you a dark voltage 115mV and a reflective object at 150mils voltage of 2.3 Volts.

Now noise, I doubt you will ever see 115mV, the back ground IR noise will mean you never have a dark environment.

There are a lot of IR signals around, you get it from the Fluro lights etc, you may need to shield the sensors and you may need to put a capacitor to deck to shunt the High Freq noise off.

To make thinks easier for your self I would consider an OPAMP to condition the signal.

Last thing if you put the LED resistor on the ground side you can tie Pins 1 and 4 together to +5V

I do love an expert - praticularly one that shares. 10/10 cwignell

Hello CTC,

I forgot to ask what are you using the IR Sensor for?, Motor Encoder, line following, limit switching?; it just that the range of this devices is only around a half inch, with the peak response at around 125Mils or 1/8th inch.

The reason I ask is an an encoder it should be sweet but as wall detection might not be great.

Funny story, my sumo robot uses IR for detecting the edge of the ring, worked great on my bench but would run off the ring almost all the time, I discovered that the black paint I used was almost transparent to the IR and the primer underneath had a similar response to the white paint marking the edge of the ring, so there was only a 250mV difference whereas the test slide I used generated a 2V difference. So I have had my troubles with IR too.

Oh, just a hint get a hold of LTSpice IV, it's free reasonably easy to use and you can play around with this stuff.

Hello Mike,

Thank you for the complement, I am not really an expert, but the reason these types of groups grow is everyone has something to add, if we are all willing to share it becomes a collective inteligence.

Lets see if it works for CTC.

So much to go through... (and it is early morning now, I have not tested any of this yet.)

Yes, Frits nailed it with the test with ADC thng.

Rik is funnier

Frit's suggested a way to test, rik suggested a tool to test with -points to each of you.

Frits is a very competent person

cwignell is a electronics math guru.

Now, stuff I learned:

These are encoders for walter's wheels -White and black stripes on the edge of he wheels. Now that I have it down to a 35k pull-up and it is on the edge of usability, yes, the bright sun or flo. lights might just throw a wrench (spanner) into the works. I reread cwignells math a few times and I think I actually have it in my head now. One major thing he mentioned (which before I didn't know how to calculate) is the current limit resistor on the LED. His math puts it down below 100R instead of 330R. I like this a lot... I would like to think that a brighter LED would do wonders in terms of triggering the transistor, this will one of the first things I will try. Second, he mentioned running + into the collector and adding the resistor and output to the pic on the emitter side. I though this was a no-no with a NPN. Actually, I have "switched positive" with other NPN encoders before and remember being told not to but it seemed to work then. I will try this on the next pair I play with, I etched the PCB's last night and don't want to again --they are etched with the set-up described at the begining of the post. I can change resistor values when I solder them up but not the wiring. I am curious though, about the performance difference between each set-up.

The bottom line and where I sit now: I think I am basically going to get the LED brighter, retest (using ADC and a pot) with the brighter LED and see if I can get the pull-up's a little lower in value. This should give me a wider window so when I do run into bright sun or flo. lights, I will have a better chance of being in that window.

Thank you all for your help and consideration, I feel less like an idiot now, we are all competent, you are all loved!

In the words of Rodney King...

"Can't we all just get along?"  :)

I was probably bothered about the connection of the collector to a positive source, resistor off the emitter, might have asked you about it long ago. It didn't seem right ot me, but couldn't think of a good reason why.  So I mentioned, "what the heck, if it works, might as well", or something like that.

Final numbers...

Current limiting resistors on LED emitters: 100R

Pull-up resistor on input pin (Digital): 22K

I have awesome sensitivity with this set-up. The unit is triggered starting at about 3/4" away using white printer paper. When this is installed on Walter, it will be about 1/4" away so I feel I have a pretty good safety margin.

Word, yo.

In a shoutbox... What a shame that would have been...

;-)

All this WAS in the shout-box...      ...and it WAS a shame...

Hey Chris,

I forgot to mention, you’re not an idiot, they are not found building robots, therefore simple logic dictates that Chris ≠ Idiot.

I forgot to compliment your drawing above, very nice, does your wife mind when you draw on the wall? Or is that where the Idiot part came in? ;-) Sorry I jest.

We are of course all momentary idiots, I have many situations where something I have done has let the magic smoke out of some component, decimal points and polarity are pesky things.

On a serious note, one thing you might consider, I am not sure what processor you are using but some Microcontrollers have ports which can be setup up as Comparators, usually with an internal reference voltage or an external one, a Comparator (for completeness) out puts a high when the voltage is above the reference voltage and a low when below. There are comparator chips and the market but it is easy to build on from an OPAMP just a few resistors, this would mean no ADC, and you could run the sensor off an interrupt if you wanted to.

all the best from Down under