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()
{
Serial.begin(9600);
digitalWrite(2, HIGH);
}
void loop()
{
int val = analogRead(0);
Serial.println(val);
delay(200);
}
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.
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.