IR detector - signal or not...

Hi everyone,
Am finally diving in and writing my first Arduino script, after doing a small handful of the examples/tutorials on this site.

My circuit is essentially this:

except that I'm using Pin 9 instead of 12. (Picture borrowed from an older post, circa 2009. Credit user: jerryanet)

The IR detector are side by side and facing in the same direction, rather than facing each other. When an object is put in front of them, I can detect a small difference on Pin9 as the IR is reflected back to the detector. Unubstructed reads typically 20 or 21, and reflected it jumps to 23 or 24.

The floating value at either level is driving me crazy, becuase it makes it harder to determine if the change is determined to an object present (reflection) or not. I'm guessing ambient light is a partial culprit in this!

What can I do to settle down the detection, OR increase the difference between the two states, so that I can be more certain?

Thanks in advance!

Peter

So I assume you are on a machine that has pin 9 as one of the analogue inputs.
The simplest thing you can do is to make that 10K resistor into a 100K one. That will give you a bit more range / difference. You can also try angling the emitter and detector so that they both look at a point at the distance you are interested in.

Ambient light will certainly have an effect on the reading of an IR detector. In addition to Mike's suggestions you should write your program to blink the emitter and base your detection on the difference in readings when the emitter is off vs. on.

blink the emitter and base your detection on the difference in readings when the emitter is off vs. on

Good idea but you will have to drop the current through the emitter because that resistor value will draw too much current from the output pin. Or else use a transistor to switch it.

Sorry, I should have said pin A0, instead of 9 above. (I'm using 9 as an output to drive an LED that lights when reflection is detected, and got mixed up when I glanced at the board.)

Using an Arduino Uno.

Changing to a 100K on the receiver side lowered both sets of values - 8/9 when un-obstructed, and 6/7/8 when reflection detected, so the same bouncing and difference challenge remains. Covering the pair with my hand to block ambiant light has no discernable effect as a I test it.

Update:
Went back to the 10K resister. I also seperated the emitter/detector by a few millimeters, and the un-obstructed numbers shot way up - into the 350+ range, while the lower numbers stayed in the low 20's. I think I can work with this range no problem, and ignore the small variations that happen at either extreme.

Changing to a 100K on the receiver side lowered both sets of values

No way was that a 100K resistor you used if that happened, colour for 100K is Brown, Black, Yellow.
Have you got the sensor the right way round?

Was definitely 100K, colours match your description, and I used my meter to make sure when I tried it earlier. Sensor pins are in the right way.

As I'm a rookie, help me learn - why do you suspect the 100k results?

Because the 100K will reduce the current by ten times, this will make any change in the photo current affect the voltage ten times more.

Makes sense.
Since spacing them out a bit helped so much, do you think that the 100k multiplication factor affected both the unobstructed and reflected results?

It affects the reading you get from a given amount of light no matter where it came from.