user28695: On door to my room there is HC-SR04 that triggers led-wave. The shorter the distance, the faster the led-wave (8 leds).
The circuit works fine in synthetic tests – moving hand or flat object towards the sensor generates gradually accelerating wave.
However, when placed on door to detect approaching persons it generates short correct (<=170 cm) impulses and the wave starts and immediately stops, again starts, etc. I guess HC-SR04 isn't good enough to detect people.
Are there any alternatives to this sensor that will correctly detect human approaching?

user4143: In general the HC-SR04 is controlled using pulseIn().
When there is nothing within range for the sensor to detect it usually has to wait for pulseIn() to time out. That can take up to a second by default.  While that is happening the rest of the sketch cannot do anything.
You can reduce the timeout in the pulseIn() function, but it's still not going to be perfect - you'll still get a delay which will interrupt your LED sequences.
The ideal way will be to create a "free running" distance sensor system - use a timer to periodically start a ping, and use the Input Capture module of the ATMega to measure the time between the start and end edges of the returning pulse. Everything will happen asynchronously to the rest of your sketch then.
I am not aware of any libraries for Arduino boards, but I have one for the PIC32 based chipKIT boards that I use. It can't ever work on AVR based boards, but you can use it to see the general concepts and how things fit together.

28695: <p>On door to my room there is <a href="https://www.sparkfun.com/products/13959" rel="nofollow noreferrer">HC-SR04</a> that triggers led-wave. The shorter the distance, the faster the led-wave (8 leds).</p>

<p>The circuit works fine in synthetic tests – moving hand or flat object towards the sensor generates gradually accelerating wave.</p>

<p>However, when placed on door to detect approaching persons it generates short correct (&lt;=170 cm) impulses and the wave starts and immediately stops, again starts, etc. I guess HC-SR04 isn't good enough to detect people.</p>

<p>Are there any alternatives to this sensor that will correctly detect human approaching?</p>
 4143: <p>In general the HC-SR04 is controlled using <code>pulseIn()</code>.</p>

<p>When there is nothing within range for the sensor to detect it usually has to wait for <code>pulseIn()</code> to time out. That can take up to a second by default.  While that is happening the rest of the sketch cannot do anything.</p>

<p>You can reduce the timeout in the <code>pulseIn()</code> function, but it's still not going to be perfect - you'll still get a delay which will interrupt your LED sequences.</p>

<p>The ideal way will be to create a "free running" distance sensor system - use a timer to periodically start a ping, and use the Input Capture module of the ATMega to measure the time between the start and end edges of the returning pulse. Everything will happen asynchronously to the rest of your sketch then.</p>

<p>I am not aware of any libraries for Arduino boards, but <a href="https://github.com/MajenkoLibraries/ICPing" rel="nofollow noreferrer">I have one for the PIC32 based chipKIT boards that I use</a>. It can't ever work on AVR based boards, but you can use it to see the general concepts and how things fit together.</p>
