HELP with Infrared emitter + sensor problems

delay(.5);

What makes you think you can delay 500 microseconds like that?