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?!?!?

 

Walter_Autodrive_007.jpg

stumped
I am.

Nice drawing!Numbas and all,

Nice drawing!

Numbas and all, nice :slight_smile:

Have you tried an analouge in? Your level should be altering around 127.

It all looks right, only I would not know the size of the resistor, hence the analoge testing…

 

PS: I think in fact I have only READ that this should work, I never tried to have an "analoge" signal like this in a devider set up to to a digital in. It SHOULD work, but since I can never find the right resistor, I always use analoge in for this kind.

brilliant

Just experiment until the right R value is known.

Hook it up like Frits suggests. Replace the 10 kOhm with a pot. Debug in your code. Twiddledee twiddledum on the pot until you find the setting that turns the circuit into a “digital” or rather “binary” thingey. Disassemble. Read the pot’s value. Substitute with nearest fixxed value in your tackle box. Back to digital input again.

And Frits is your uncle!

I think rik might get a gold star…
I like the way you think, kid! And if 2 guys suggested pretty much the same thing, it is probably right!

It’s right when I suggest

It’s right when I suggest it. That matters alone.

rik should just make legs!

legworker
Frits actually has a point here!

I hate to admit it.
Both frits and rik were right. In the end it took about 50k (or a little more) to + to work.

I take that back…
With a little more testing it seems a little more like 35k pull-up to get it going. And I have to admit, running it into a ADC channel did help a lot. And frits is still a punk…

Hello CTC, We might do this

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).

<o:p> </o:p>First let’s look at the emitter, basically an IR LED, it needs less than max current of 50ma<o:p></o:p><o:p> </o:p>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:-<o:p></o:p><o:p> </o:p>R1 = (Vs – Ev)/If<o:p></o:p><o:p> </o:p>Where R1 is the value of the resistor we need<o:p></o:p>Vs is the supply Voltage<o:p></o:p>Ev is the IR LED forward Voltage and<o:p></o:p>If it the current flowing through the IR LED<o:p></o:p><o:p> </o:p>So R1 = (5 – 1.7)/4x10e-2<o:p></o:p><o:p> </o:p>R1 = 82.5 Ω<o:p></o:p><o:p> </o:p>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) <o:p></o:p><o:p> </o:p>Now let us look at the sensor:<o:p></o:p><o:p> </o:p>It is a NPN silicon phototransistor with a saturation voltage of 0.4v and a dark current of almost noting (100na).<o:p></o:p><o:p> </o:p>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.<o:p></o:p><o:p> </o:p>So from the data sheet we have a saturated forward voltage of 0.4V and say 4ma (see fig 2)<o:p></o:p><o:p> </o:p>So R2 = (Vs –Vf)/Ic<o:p></o:p><o:p> </o:p>Where R2 is the Sensor bias resistor<o:p></o:p>Vs is the supply Voltage<o:p></o:p>Vf is the Sensor forward Voltage and<o:p></o:p>Ic it the current flowing through the Sensor (when object is detected)<o:p></o:p><o:p> </o:p>So R2 = 1152 Ω<o:p></o:p><o:p> </o:p>This should give you a dark voltage 115mV and a reflective object at 150mils voltage of 2.3 Volts.<o:p></o:p><o:p> </o:p>Now noise, I doubt you will ever see 115mV, the back ground IR noise will mean you never have a dark environment.<o:p></o:p><o:p> </o:p>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.<o:p></o:p><o:p> </o:p>

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 -
I do love an expert - praticularly one that shares. 10/10 cwignell

IR Sensor

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.

 

Comment viewing options

Threaded list dude! Threaded list!

 

(And for Pete’s sake: what is that unreadible url in the bottom left corner of you notes?!)

Then when you test in

Then when you test in daylight, your bot will be banging the wall or whatever.

ADC + self calibrating code isnumba one.

PS: I am so tired of this; All the time I come up with the right answer, and people like rik gets "Oh, THANK YOU RIK for"… yes, for what? It is always my tips that works; Hot glue, double sided tape and ADC!

Frits you are a very
Frits you are a very competent person!

Uff-da…

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?” :slight_smile:

Whew…

Alright ladies and germs…

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.

Walter_Autodrive_010.jpg

Word, yo.

Imagine all this

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

:wink:

rik… it was…
All this WAS in the shout-box… …and it WAS a shame…

IR Sensor, an not an Idiot

Hey Chris,

I forgot to mention, you’re not an idiot, they are not found building robots, therefore simple logic dictates that Chris ≠ Idiot.<o:p></o:p>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? :wink: Sorry I jest.<o:p></o:p>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.<o:p></o:p>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.<o:p></o:p>

all the best from Down under