HC-SR04 Issue

I have several HC-SR04 ultrasonic sensors, and two of them stopped working. I am trying to figure out if they are dead or not. I bought them around 6-10 months ago, they have had light use over the time I have owned them.

My setup:
6 HC-SR04 ultrasonic sensors
Arduino Mega 2560
Windows 7
Arduino 1.0.5

These sensors have been working well for the past few weeks that they have been in on this project. Today the one quit working, it always returns ~730 cm (works out to about 43 milliseconds). I checked all the wiring, it looked fine, no obvious damage to the sensor itself, I took a multimeter and poked around a bit and compared it to a working one, nothing looked different. I took a working one and swapped it around with the non-working one. The working one worked fine, I let it run for about 5 minutes, and it still worked. The bad one would not work anywhere I connected it. I then connected the non-working sensor to the arduino with all new wiring, it still did not work. About 15 minutes later, another one started doing the same thing, this one had stayed in its spot the whole time. I repeated all the tests again and it was all the same, bad sensor would not work anywhere, and others would work in its place.

Here is a small part of the code from when it broke:

const int UltrasonicPins[6][2] = {
  42,43,   //LB
  44,45,   //LF
  50,51,   //RB
  52,53,   //RF
  46,47,   //FL
  48,49};  //FR

#define LBack 0
#define LFront 1
#define RBack 2
#define RFront 3
#define FLeft 4
#define FRight 5
#define Trig 0
#define Echo 1

void setupUltrasonic();
double ultrasonicCM(int UltraPin);

void setup()
{
  Serial.begin(9600);

  setupUltrasonic();
}

void loop()
{
  for(int i=0; i < 6; i++)
  {
    Serial.println(ultrasonicCM(i));

    delay(40);
  }

  Serial.println(" ");
  delay(250);
}

void setupUltrasonic()
{
  pinMode(UltrasonicPins[LBack][Trig], OUTPUT);
  pinMode(UltrasonicPins[LBack][Echo], INPUT);
  pinMode(UltrasonicPins[LFront][Trig], OUTPUT);
  pinMode(UltrasonicPins[LFront][Echo], INPUT);
  pinMode(UltrasonicPins[RBack][Trig], OUTPUT);
  pinMode(UltrasonicPins[RBack][Echo], INPUT);
  pinMode(UltrasonicPins[RFront][Trig], OUTPUT);
  pinMode(UltrasonicPins[RFront][Echo], INPUT);
  pinMode(UltrasonicPins[FLeft][Trig], OUTPUT);
  pinMode(UltrasonicPins[FLeft][Echo], INPUT);
  pinMode(UltrasonicPins[FRight][Trig], OUTPUT);
  pinMode(UltrasonicPins[FRight][Echo], INPUT);
}

double ultrasonicCM(int UltraPin)
{
  long dTime;

  digitalWrite(UltrasonicPins[UltraPin][Trig], HIGH);
  delayMicroseconds(10);
  digitalWrite(UltrasonicPins[UltraPin][Trig], LOW);
  dTime = pulseIn(UltrasonicPins[UltraPin][Echo], HIGH);
  return (dTime/2.00)*(340.29/10000.00);
}

Once they broke I simplified it down to this:

double ultrasonicCM();

void setup()
{
  Serial.begin(9600);
 
  pinMode(42, OUTPUT);
  pinMode(43, INPUT);
}

void loop()
{
  Serial.println(ultrasonicCM());
  
  delay(250);
}

double ultrasonicCM()
{
  long dTime;

  digitalWrite(42, HIGH);
  delayMicroseconds(10);
  digitalWrite(42, LOW);
  dTime = pulseIn(43, HIGH);
  return (dTime/2.00)*(340.29/10000.00);
}

I also tried to use the NewPing library, that would return either 147cm or 0cm with the broken ones, and it would return good values with the working ones (an occasional 0) . When I did these tests I swapped the sensors around (working and non-working) on the same port (one that a bad sensor was originally connected to).

I’d appreciate any help figuring out if these sensors died or if I have another issue.

Thanks,
Tr24em

Unfortunately it looks like it's broken, if you Google for "HC-SR04 Broken", you'll find quite a lot of similar stories.

That is what I was afraid of.... :( With 2 of them going out within 15 minutes of each other I thought I might be doing something wrong.

More are on the way to replace them.

Measure the 5V voltage rail, maybe there's something wrong with that and you're overloading the sensor. On the other hand if these sensors fail so quickly there must be something wrong with the design of the sensor

I forgot to mention that part. I had it initially powered from the arduino, and checked it, it was at 4.85V. I then took a regulator and powered it with that (5v up to 8A), thinking that too much current might be pulled. No mater how it is powered the "broken" ones still do not work.