Infrared sensor behavior
Try waiting longer - one second or one and a half. And you were using the ultrasonic sensor but in the program you use infrared sensor block.

You can switch to port view prior to running your program to verify that your sensor is of the expected type and works.