Searching for algorithm range finder detection

3/ restart from 0 and repeating 3 times to get 3 averages value

/* {{{1 ULTRASONIC SENSOR CHECK */
void UltrasonCmd::sensorCheck()
{
      // ultrasonic sensor check
      SRF02::update();

      // sampling only if thing is under 100cm
      if ( checkToStartSampling() )
      {
            startSampling();
      }
      sampling();
}
bool UltrasonCmd::checkToStartSampling()
{
      if ( (_sonicSensor->read()<300)                 &&  // distance is lesser than 300cm
                  (millis() > 10000)                         &&  // it is 10 seconds that programm has started
                  ((millis() - m_lastAverageTime)> 250)          // 1 second elapsed since last average
         )
      {
            return true;
      }
      return false;
}
void UltrasonCmd::startSampling()
{
      if(!_b_startSampling)
      {
            _b_startSampling=true;
            _delayBeforeSampling=millis();
      }
}
void UltrasonCmd::reinitSamplingParam()
{
      _b_startSampling=false;
      _averageDist=0;
      _idxDistSamples=0;
}
void UltrasonCmd::sampling()
{
      if ( ( _b_startSampling==true ) && ((millis()-_delayBeforeSampling)>500) )
      {
            if ( _idxDistSamples<currentDetection->nbSamplesToCheck )
            {
                  _averageDist=_averageDist+_sonicSensor->read();
                  _idxDistSamples++;
            }
            else
            {
                  _averageDist=_averageDist/currentDetection->nbSamplesToCheck;
                  if ( _averageDist > 0 )
                  {
                        // memorize current Distance 
                        if ( b_saveCurrentDistMemo )
                        {
                              set_m_currentDistMemo(_averageDist);
                        }
                        // set current Distance
                        set_m_currentDist(_averageDist);
                        b_saveCurrentDistMemo=!b_saveCurrentDistMemo;
                  }
                  m_lastAverageTime=millis();
            }
      }
}
int UltrasonCmd::get_m_currentDist()
{
      return m_currentDist;
}

Then in my main loop I am doing that :
1/ checking each loop that value of distance then waiting for autorization to power on some electrical devices

void loop()  {

      // SENSOR
      UltraCmd.sensorCheck();
      Tracer.LcdPrintTopLineFromRightFast(convert::ToString(UltraCmd.get_m_currentDist()));

      // RELAYS ON ALL DETECTION  
      // Serial.println(UltraCmd.autorizeRelaysOn());
      if ( UltraCmd.autorizeRelaysOn() )
      {
            if ( UltraCmd.getCrOnRelays() == false )
            {
                  UltraCmd.setCrOnRelays(true);
                  PinMng.OnAll();
                  Tracer.LcdPrintTopLineFromRightFast("ONALL");
                  AlarmMng.alarmAfterNSec(10, foo);
            }
      }

      
}

Then after 10 seconds for test, power off my lines.

I am searching for elaborates algorithm that are more evolved than this one in order to detect some hand move in front of the sensor.

Those algorithm without using array, should recognized acceleration approach of hand, etc....

Have you got some links or other methods than mine.
Thank you

Imagine that you are the sensor and you should do it. Write down the steps in plain English / French what you need to do. That way you will get sort of a design how the system should work.

  1. get a reading
  2. calculate distance
  3. etc

with respect to your code:
(millis() > 10000) // it is 10 seconds that programm has started
Note that millis() will wrap around eventually.

(millis() - m_lastAverageTime)> 250) // 1 second elapsed since last average
250 sounds more like a quarter of a second to me, and as someone said on this forum: In case the code and comment disagree the code is allways right.