Jlawler:
Hey guys so just one more question, I have gotten my IR sensors to work, kind of. I can get the sensor to detect something but once my sensors detect something it returns to reading clear even when an object is in front of it. So for example if I wave my hand in front of it, it will say something is there and then immediately return to saying clear even while my hand is still there, to get it to say it see's something again I have to pull my hand away and return it but when I return it it will only say it saw an obstacle once. Is there a simple fix or a bigger issue?
First off, well done on getting as far as you have. I think your issue will be simple to fix.
These TSOP sensor have automatic gain control for dealing with noisy environments. Try changing this:
int irDetect(int irLedPin, int irReceiverPin, long frequency)
{
tone(irLedPin, frequency) ; // IRLED 38 kHz for at least 1 ms
delay(2); // Wait 1 ms
int ir = digitalRead(irReceiverPin); // IR receiver -> ir variable
delay(2); // Down time before recheck
return ir; // Return 1 no detect, 0 detect
}
to this:
int irDetect(int irLedPin, int irReceiverPin, long frequency)
{
tone(irLedPin, frequency) ; // IRLED 38 kHz for at least 1 ms
delay(2); // Wait 1 ms
int ir = digitalRead(irReceiverPin); // IR receiver -> ir variable
noTone(irLedPin);
delay(2); // Down time before recheck
return ir; // Return 1 no detect, 0 detect
}
and see how it goes.