Issues using HC_SR04 Ultrasonic Sensors on a mobile Robot

I’ve built a small mobile robot with 3 SR04 sensors looking front, front left and front right. It works well, except that occasionally the Ultrasonic sensors either get a ghost echo with no object present, or no echo when an object is present. I’ve done some bench testing and here are my results:

• When stationary, the sensors are very consistent. I’m not overly concerned with accuracy because I want them to sense a minimum distance while the robot is moving. • Moving in general seem to be an issue. As soon as the platform moves the sensor start giving some errors. This is not a motor RFI/EMI issue, I have tested with the motors off and moving the platform by hand. • The sensors are very sensitive to angle. Moving them a few degrees off perpendicular to the target starts giving “no echo” responses. No echo return beyond a 45 degree angle. • The sensors are very sensitive to the size of the target. The smaller the target, the closer you need to be to sense it. Chair legs are a particular problem. • The sensors are very sensitive to the material of the target. You need to be much closer to a cloth sofa than a hard wall to sense it. I’m using the Newping library and I’ve tried between 1 and an averaging up to 10 pulses with ping_median(). I also have an IR sensor on the front that I use for “danger close” sensing and will add contact switches to the front, but I was hoping to avoid that.

Has anyone else experienced this? If so how have you worked around it? Are there any sensing and avoidance algorithms people have used successfully to make up for deficiencies of the sensors?

Hi,

I made a robot some years ago using different sensor as your doing.

My experience with the SR04 sensors is that if they are too low (close to floor) then they
will give false reading.

If you have 3 SR04 in front, maybe the echo of 1 interfere with the other. Personnaly I use 1 in front and 1 in back.

If the robot move in a corridor (2 walls parallèles, 3foot distance), the echo will bounce many times
on the 2 walls and give max distance.

I think for small objects, sonar is to be monted on a Micro servo that turn often.

In general IR sensor are good for small distance (<15cm) and help to avoid contact with object (if the robot is not too fast).

I think I will start again playing with my robot!!

Have fun with your project; you certainly will invest many hours in it.!!!

Nota:please excuse my english

Your English is fine, thanks for the reply.

I have seen the bounced echo case in close corridors, but it's usually not an issue, because I'm trying to avoid the walls anyway.

I've tried testing with the robot mounted up off the floor with the same results. One sensor misses as many echos as all three running at the same time.

I'm thinking that instead of just reacting to a ping, I'll keep an "object probability" map based on previous pings and avoid those locations.

What is the approx. speed (max.) of your robot?

Hi,

One sensor misses as many echos as all three running at the same time.

What do you mean by "running at the same time". I hope you ping and wait for echo, then ping the next and wait for echo, then ping the last and wait for echo.

Pinging them all at once will only produce echos that will cause confusing results. As a ping emitted by one unit will probably cause an echo that is received by a completely different unit.

Tom... :)

The robot runs at about walking speed, but the sensor problem happens at much slower speeds when I'm just moving it forward by hand.

I am pinging each sensor individually and waiting for an echo. The problem is the same using 1 or all three sensors in sequence.

I'm sure I'm not the only one to notice this with these sensors.

Can you show us the section of your program that concern the sensor?

I’m pretty sure it’s the sensors not the code. For bench testing, I’m using the NewPing example code with a single trigger/echo ping:

#include <NewPing.h>

#define TRIGGER_PIN 12
#define ECHO_PIN 12
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
Serial.begin(115200);
}

void loop() {
delay(50);
int uS = sonar.ping();
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM);
Serial.println(“cm”);
}

Did I just get a bad set of sensors (10), or are others seeing this problem? Has anyone else bench tested these sensors?

Is the problem using the single pin for trigger/echo?

I just found a comment by Tim Eckel in another thread stating "Using a single pin is a bit of a hack and doesn't always work on all situations."

I'll retest with two pins and see if that improves the SR04 performance.

I've also seen some statements that you should put a small cap between trigger and echo if you are using a single pin. Has anyone tried this?

I always use 2 digital pins when I work with those sonar and everything is ok.

I also use the following lines of code in Arduino:

int HCecho=12; int HCtrig=13;

pinMode(HCtrig, OUTPUT); pinMode(HCecho,INPUT);

digitalWrite(URTRIG, LOW); // a low pull on pin COMP/TRIG triggering a sensor reading delayMicroseconds(2);

digitalWrite(URTRIG, HIGH); // reading Pin PWM will output pulses delayMicroseconds(10);

unsigned long DistanceMeasured=pulseIn(URPWM,LOW);

Hoping that this can help you...

Thanks Duino_nano. I used similar code when I was using pulsein(). I've found the Newping library to be much more stable.

Has anyone else had problems using 1 pin with the Newping library?

Hi,

I've tried testing with the robot mounted up off the floor with the same results. One sensor misses as many echos as all three running at the same time.

and

The robot runs at about walking speed, but the sensor problem happens at much slower speeds when I'm just moving it forward by hand.

The problem happens when?

Tom.... :o

I thought I was clear in the original post. The SR04 misses echos when it is moving and at angles. I bench tested the sensors to eliminate as many variables as possible. This happens with multiple different sensors.

I'm left to assume I'm the only one seeing this problem with the sensors and it must be the use of single pin trigger/echo with the Newping library.