Although I like the answer Riva gave, you never use the loop if there never is a pulse from a sensor. or if you ever get a pulse, you enable the loop.
I am not sure if this idea will work, but you might be able to add a small capacitor
set the pin to output, charge the cap
set the pin to input. pull-down will drain the cap.
no physical device connected means no cap and the input will be zero when you change the pin state.
if there is a cap, the voltage will be high until the cap drains, meaning a time lag from the charge.
I am wearing my big target shirt. Anyone who wants can shoot holes in this idea.