Ultrasonic sensor is responding too slow

Hello there ! i’m currently working on my school project which involve obstacle avoiding using three ultrasonic sensor and vacuum cleaning. However sometime the ultrasonic sensor does not detect the obstacle as it <=20. I would very much appreciate all the help i can get :frowning: :frowning:

sketch_oct21a.ino (5.53 KB)

Which model of the ultrasonic distance sensor are you using?

The HC-SR04 will work down to ~2cm, whereas the single-transducer JSN-SR04T can't read below ~20cm.

Also, your title is misleading; not getting a proper reading is not the same thing as "responding too slow".

Williamsccz:
Hello there ! i’m currently working on my school project which involve obstacle avoiding using three ultrasonic sensor and vacuum cleaning. However sometime the ultrasonic sensor does not detect the obstacle as it <=20. I would very much appreciate all the help i can get :frowning: :frowning:

Have you thought about us not being able to see what three sensors you are using are, nor how you have them wired, nor how you have them physically mounted. Nor do we know anything about the vacuum, nor how much and what type of noise it makes. And we can’t see what the shape of your obstacle is, nor the material it is made of.

Can you help us help you?

Paul

sorry in advance, im new to Arduino coding.
Hello there i am using 3 Ultrasonic sensor HC-SR04 and im using the coding below to detect obstacle from middle left and right

Void loop()
{
long Lduration, Ldistance; // start the scan
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
Lduration = pulseIn(echoPin1, HIGH);
Ldistance = (Lduration/2) / 29.1;

long Mduration, Mdistance;
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
Mduration = pulseIn(echoPin2, HIGH);
Mdistance = (Mduration/2) / 29.1;

long Rduration, Rdistance;
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
Rduration = pulseIn(echoPin3, HIGH);
Rdistance = (Rduration/2) / 29.1;

then i uses coding below to compare between all 3 ultrasonic sensor

if(Mdistance <= 20 && Ldistance <= 20 && Rdistance <=20)
{
moveStop();
delay(300);
moveBackward();
delay(400);
moveStop();
delay(300);
turnLeft();

}
if(Mdistance <= 20 && Ldistance >= 20 && Rdistance <=20)
{
moveStop();
delay(300);
turnLeft();
}

if(Mdistance <= 20 && Ldistance <= 20 && Rdistance >=20)
{
moveStop();
delay(300);
turnRight();
}

if(Mdistance >= 20 && Ldistance <= 20 && Rdistance <=20)
{
moveForward();
}

if(Mdistance <= 20 && Ldistance >= 20 && Rdistance >=20)
{
moveStop();
delay(300);
turnLeft();
}

if(Mdistance >= 20 && Ldistance <= 20 && Rdistance >=20)
{
moveForward();
}

if(Mdistance >= 20 && Ldistance >= 20 && Rdistance <=20)
{
moveForward();
}
if (Mdistance >= 20 && Ldistance >= 20 && Rdistance >=20)
{
moveForward();
}

}

@Williamsccz

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Please READ THIS POST to help you get the best out of the forum.

Bob.

Williamsccz:
However sometime the ultrasonic sensor does not detect the obstacle as it <=20.

That’s ambiguous.

Does that mean that:

  • whenever the obstacle is <=20 it is never detected, or
  • sometimes an object <=20 is detected and sometimes an object <=20 is not detected?

The first thing you need to do is to put some Serial prints in so you know exactly what distance readings you are getting. Then you will be able to tell if the problem is that the sensors are not performing or if the problem is with the rest of your code.

One odd thing I note. You have global variables for the durations and distances and then you keep creating new local versions of them all in loop(). Why ?

Steve

If that “object” is your clothed legs, that’s very likely to be missed indeed as clothing does not give good reflections. A wall will be detected much better. A small object like a table leg is also likely to be missed with ultrasound.