How to stop detected after 5 seconds using ultrasonic sensor

It would be helpful if you posted your code using code tags. I'm not exactly sure what you are asking help with so if you provide more details we may be able to help.