Ultrasonic sensor range appears to be limited to around 100cm

Hi, I am currently using an array of 3 HC-SR04 ultrasonic sensors with an Arduino Mega to measure a distance that is 3 metres away. The sensors are placed on the ceiling and are pointed downwards to the floor, however when I test them it seems that the range they can read up to is about 100cm. I know that these are rated to go up to 400cm, so what could be some possible troubleshooting points I could follow? I've checked it's power, I've also added a delay between each sensor's activation to prevent echoing, however they are still showing this issue. Any help would be appreciated!

Hi,
Can you please post your code?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

#define trigPin1 22
#define echoPin1 23
#define trigPin2 24
#define echoPin2 25
#define trigPin3 26
#define echoPin3 27

long duration, distance, Sensor1, Sensor2, Sensor3;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
  pinMode(11, OUTPUT);
}

void loop() {
  SonarSensor(trigPin2, echoPin2);
  Sensor1 = distance;
  SonarSensor(trigPin2, echoPin2);
  Sensor2 = distance;
  SonarSensor(trigPin3, echoPin3);
  Sensor3 = distance;

  Serial.print(Sensor1);
  Serial.print(" - ");
  Serial.print(Sensor2);
  Serial.print(" - ");
  Serial.println(Sensor3);
  delay(100);
}

void SonarSensor(int trigPin,int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  delay(100);
}

Hi, here it is

code tags added. do yourself a favour and please read How to get the best out of this forum

Hi,
Try the NewPing library.
https://playground.arduino.cc/Code/NewPing/

Tom... :smiley: :+1: :coffee: :australia:

Hi, I've tried the NewPing library with a max range set to 300cm and it seems very inconsistent, where the values appear to be 0 most of the time, and when they aren't 0 they have the same problem as before where they only show up to around 100cm for the range.

What are they detecting? A person's head, for example, wouldn't reflect ultrasonic sound very well. Does it "see" the floor? Is there carpeting? Have you tried other targets? The maximum specified range is 4m.

Hi,
You seem to be firing each SR04, one immediately after the other.
Each unit could be picking up stray reflections from the previously fired unit.

To check, put a 1 second delay after each firing to make sure any stray echoes have dissipated.
Each unit cannot tell if the reflection it receives is from its Tx or one of the others.

Tom... :smiley: :+1: :coffee: :australia:

It is on the ceiling that is 2.7 metres high, and is pointed straight down at a hard flat floor. It is expected to show values of 2.7m when used but for some reason it is only showing values up to around 100cm and under-reporting the value by a lot. I have also tried turning off the other sensors in the array and only using one sensor, and this problem still occurs.

Hi,
How are you powering your project?

Thanks... Tom.... :smiley: :+1: :coffee: :australia:

I'm using an external 5V power supply for the sensors, and the arduino is running on USB power from a laptop

And are the ground (0V) rails of the 2 power supplies connected together?

There is only one power supply for the three sensors, I'm not sure what you mean here.

I'm using an external 5V power supply for the sensors, and the arduino is running on USB power from a laptop

This is 2 power supplies - external and USB

I recommend you test one sensor at a time and see if the range is still limited to 1 meter. I'm getting 2+ meters consistently with the target being a cement floor. That would make my limit > 2 meters.

Hi,

You have two power supplies, one for the sensors and one for the UNO.
Is the gnd of the UNO connected to the gnd of the sensors 5V supply?

Tom... :smiley: :+1::coffee: :australia:

Hi, I have connected the gnd of the arduino to the gnd of the power supply as suggested however there seems to be no change in the issue. I have tested these sensors individually before and they were able to give readings of up to 2.7m, which is what I require, but now that I have soldered wires onto them and connected them all up this issue has come about.

The differences between my previous test and this was that in the previous test, the sensors were placed directly onto a breadboard with short wires connecting to the arduino, however in this test the sensor leads have long wires soldered onto them. Could the length of the wires be an issue? They are around 100cm long.

Hi,

It could, are they ALL bunched together in a single cable?

Can you please post some pictures of your project?

Tom... :smiley: :coffee:



Here are a few photos, there are so many wires because there are also other sets of ultrasonic arrays in the project but they are not connected to power for now as I'm still troubleshooting the first set. The wires are not bundled up as of now, it's just a straight connection from the sensor to the breadboard to the Arduino.

The code shows a delay(100)

cable length might be an issue.

to double check you could bring an arduino close to the sensor and connect where you have the black tape on the yellow and blue cable (I assume the other 2 are power, just ensure GND are connected)