These three lights in this circuit turn on one by one, as long as the ultrasonic sensor detects a sharp change of distance within 1 second.
So, if you put your hand in front of the ultrasonic sensor, the red light lights up. If you move your hand within 1 second, the blue light lights up. If you move it again within another second, the green light lights up. If you don’t move your hand within a second, all lights turn off.

The code is a little long and I had some trouble pasting it onto this post, so I have no idea why some parts of it are highlighted. But anyway, here it is:

// ================================================================================
// Define constant values
#define TRIG_PIN 8
#define ECHO_PIN 9
#define LEDPIN_RED 3
#define LEDPIN_BLUE 4
#define LEDPIN_GREEN 5

// The rated distance limit of the sensor, in cm.
#define MAX_DISTANCE 200

// A typical speed of sound, specified in cm/sec.
#define SOUND_SPEED 34000

// Determine the maximum time to wait for an echo. The maximum rated distance is
// 4.5 meters; if no echo is received within the duration representing this
// round-trip distance, stop measuring. The timeout is specified in
// microseconds.
#define TIMEOUT (2 * MAX_DISTANCE * 1000000)/SOUND_SPEED

// ================================================================================
// Configure the hardware once after booting up. This runs once after pressing
// reset or powering up the board.

void setup()
{
// Initialize the serial UART at 9600 bits per second.
Serial.begin(9600);

// Initialize the trigger pin for output.
pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);

// Initialize the echo pin for input.
pinMode(ECHO_PIN, INPUT);

// Initialize LED pins
pinMode(LEDPIN_RED, OUTPUT);
pinMode(LEDPIN_BLUE, OUTPUT);
pinMode(LEDPIN_GREEN, OUTPUT);

//Turn LEDs off for starting
// digitalWrite(LEDPIN_RED, HIGH);
// digitalWrite(LEDPIN_BLUE, HIGH);
// digitalWrite(LEDPIN_GREEN, HIGH);
}
// ================================================================================
// Ping function to run one measurement cycle using the sonar. Returns a ping
// travel duration in microseconds, or 0 if no echo was observed.

float sonar_distance(void)
{
// Generate a short trigger pulse.
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);

// Measure the pulse length
// long duration = pulseIn(ECHO_PIN, HIGH, TIMEOUT);
// return (duration * 1e-6 * SOUND_SPEED) / 2;
long time=pulseIn(ECHO_PIN,HIGH);
return time*340/20000;
}

bool detect_change(unsigned long howLong=750)
{
// delay(200);
float startDistance = sonar_distance();
unsigned long startedAt = millis();
while(millis() - startedAt 30 && difference 10) {
if (detect_change()) {
delay(200);
digitalWrite(LEDPIN_RED, HIGH);

if (detect_change()) {
digitalWrite(LEDPIN_BLUE, HIGH);

if (detect_change()) {
digitalWrite(LEDPIN_GREEN, HIGH);
delay(1000);
lights_out();
}
else {
lights_out();
}
}
else {
lights_out();
}
}
}
}