Velleman HC-SR05 Ultrasound sensor not measuring beyond 5 cm

Hi there,

I just received the HC-SR05 and wanted to try it using one of the many examples found on the internet.

I output the duration of the echo pin plus the calculated distance, but it never reaches above 6 cm. Under this distance it seems to be fine, the results get actually shorter.

Any idea what the reason could be? I verified the pins, I measured the voltage to make sure it's 5V.

My code is the following:

// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration / 29 / 2;

// Prints the distance on the Serial Monitor
Serial.print("Afstand: ");
Serial.print("(");
Serial.print(duration);
Serial.print(") = ");
Serial.print(distance);
Serial.println(" cm.");

delay(2000);
}

try to make the math all floating point.

integer math trucates values

I don't think that would help me. I also print out the duration, and that remains constant as well, no matter how much space there is between the sensor and whatever object I put in front of it. Unless I come really close (under 5cm), than it starts becoming lower.

I'm wondering if perhaps my USB port doesn't give enough power to the board, and the sound burst is too weak?

Does the module contain a pot, for sensitivity adjustment?

Make sure there's nothing else in view of the sensor - it has a rather wide cone.

No, nothing was in front of it, I'm sure. And none of the samples had a pot if I remember correctly. Where should that go? The sensor has both the speaker and the microphone on one circuit.

I have the same issue. Did you ever find out the root cause of this issue?

jcbkrsthmr:
I have the same issue. Did you ever find out the root cause of this issue?

Looking at the published specs, I see up to 40ma pulse to get it to work. So, how do you have the device connected?

Paul

Paul_KD7HB:
Looking at the published specs, I see up to 40ma pulse to get it to work. So, how do you have the device connected?

Paul

I power it directly with 3xAA batteries from an external pack.

I'm trying to use it with a micro:bit instead and it's connected like this (using
a voltage divider on the echo pin to make sure its 3.3V) http://www.teachwithict.com/uploads/5/5/8/2/5582303/hc-sr04-5v-voltage_orig.png

I also tried power it with 4xAA and a 5v linear regulator, but it didn't make a difference.

The issue seems identical to OP's issue with correct readings below 5cm, then nothing.