IR Photodiode values


I build a circuit on my arduino with 1 IR-Led and 1 IR-Phtodiode. I attached the circuit to this message. (The red led in the circuit is the IR-led, I forgot to change that.)

This is the code I used:

void setup()
  digitalWrite(2, HIGH);
void loop()
  int val = analogRead(0);

This works, but not correctly. When it detects an obstacle, the value rises (this is what I want it to do). But when the program runs for a longer time, the default value when no obstacle is detected gets higher.
Does someone have an explanation for this?

And when I disconnect the IR-LED, the value still rises when it detects an obstacle.


I would reduce the 1M R to 10k to 47k.

And I think the diode is wrong way around.


Is your IR photodiode filtered or clear?

I would reduce the 1M R to 10k to 47k.

And I think the diode is wrong way around.

Photodiodes can be operated in photoconductive mode, as he is using it.

The IR Photodiode is filtered, it is black.

When reduce the 1M resistor, the photodiode gives a value of 1023.

Is it possible that sunlight affects the values?

Yes. Look at the data sheet for wavelength response. There is IR light in sunlight.

The photodiode circuit is basically correct, but you might try an even higher value for R1.

For best obstacle detection, you need to prevent external light from reaching the photodiode. Placing it in a narrow tube will help.

Save yourself a lot of trouble and use a TSL250 type of device (can't remember the exact number for IR) - straightforward set up, built-in amp, 3-25 volt supply, analogue output.