This is your distance check (and LED off). If the object is greater than 100cm, the LED is OFF. To keep the LED ON for a prescribed time, you can call the delay() function with a delayTime of your choosing...
if (distance>100) {
delay(delayTime):
digitalWrite(Led,0);
}
Please, format your code in your IDE and paste it in a code block.
It will, of course, then be blind, so there's no reaction if they wander back into the zone. That will require a non-blocking timer running, so the timer can be reset if distance drops. Time for some headscratching for the OP - what is the real requirement?
No sorry required - I was more pointing out to our OP that we need more information - what's the goal here, a classroom exercise, or something that's truly useful? Sorry, I could have been more explicit, as well as making the usual reference to "How to...", which would also address the embedding code issue you ably pointed out.
HAND! (Have A Nice Day!)
Thx for your input, im trying to make a humidifier. My plan is to run the script on a ATtiny85. I want the unit to be left powered on, then when someone walks past the unit it would turn the humidifier on for 10 seconds then turn off.
And obviously reset the timer so that the unit would be continuously ready.
So a bit like one of those proximity air freshers.
Not my question. The scenario is: a person passes by; your timer is triggered. They leave the space, but before the timer runs down, they re-enter the space. Does the timer restart, or dumbly run to zero? Both possibilities are reasonable, it depends on intent.
The answer given by @xfpd runs to zero, then retriggers only if the person is present. If that's sufficient for you, we need go no further; if not, time to start working on some concepts.