I bought some 'lucky dip' IR sensors from China, no idea what they are, but they appeared to get lost in the post so instead I bought some of these from a reputable place in the UK that come with a datasheet.
The next day, both items arrived together!
I'm trying to build a very simple proximity sensor for a robot, I built the following circuit:

simulate this circuit – Schematic created using CircuitLab
and stole this code to test it out:
#define IRledPin 8
#define D13ledPin 13
#define IRsensorPin 9
void IR38Write() {
for(int i = 0; i <= 384; i++) {
digitalWrite(IRledPin, HIGH);
delayMicroseconds(13);
digitalWrite(IRledPin, LOW);
delayMicroseconds(13);
}
}
void setup(){
pinMode(IRledPin, OUTPUT);
digitalWrite(IRledPin, LOW);
pinMode(D13ledPin, OUTPUT);
digitalWrite(D13ledPin, LOW);
}
void loop(){
IR38Write();
if (digitalRead(IRsensorPin)==LOW){
digitalWrite(D13ledPin, HIGH);
} else {
digitalWrite(D13ledPin, LOW);
}
}
If I hold my hand in front of it, nothing happens (LED on-board arduino should light up), however if I point a TV remote at it and press a button, the LED lights up. I tested 2 of the 'fancy' sensors that I got and both behaved the same.
Then I tried one of the 'lucky dip' sensors, swapped it straight in and the whole thing works perfectly - point a TV remote and the LED lights, hold my hand ~10cm in front of it and the LED lights!
So, where have I gone wrong?