HC-sr04 not working straight out of the box

I recently got a HC sr04 sensor because my old one wasn't working and was overheating. The new one has no heating issues but still returns only zeros . It is connected via a bread board to my Arduino uno and the code I am using is attached below .I have checked over the code and the wiring multiple times and tested the pins on the Arduino to make sure that they are working but nothing is working and all I'm getting is zeros.

const int trigPin = 5;
const int echoPin = 6;

void setup() {
  // put your setup code here, to run once:
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
Serial.begin(9600);
}

void loop() {
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);

long duration = pulseIn(echoPin,HIGH);
float distance = (duration * .0343)/2;

Serial.print(distance);
Serial.println("cm");

delay(100);
}

Please check if you're selecting 9600 baud rate when opening the serial monitor.

Yes, I am using the 9600 baud rate for the serial monitor

Remove the breadboard.

Try printing the value in "duration" and see what is actually returned.

Tried it and still got zeros ):

Zero is normal for no reflection during the 1 second waiting time. What are you using for the sound reflector?

You will get zeroes when:

  • trig pin is disconnected
  • echo pin is disconnected
  • echo and trig are reversed
  • power pin is disconnected
  • the HC-SR04 is removed from the circuit

Therefore, your issue is hardware related.

Ok, what should I use to connect it to the arduino? , I have very limited parts and things and the breadboard is also new so it
shouldn't be the problem

Ok thanks. I'll look over it all again and try troubleshooting these specific parts of the circuit

I'm just reflecting the ultrasonic sound off of the wall or my hand if that's what you mean. My old sensor worked (before it got really hot) and it returned the distances to whatever it was I pointed it at.

I guess your test is pretty good to determine your sensor is bad.

Jumper wires.

The reason I suspect the solderless breadboard is that you tell of an over-heating device early in your topic. I suspect there was bad wiring that lead to "charring" of metal and melting of plastic. Bypass the breadboard.

I, right now, don't have a way to do that as all I have is normal jumper wires and some male header pins. I don't think I have access to soldering but I might be able to if that is the ideal solution

I will test that to see if it's the problem

Alligator clips?

Actually I think I might have a combined cable thing that ends in female endings so I could put the jumper wires through that

After bypassing the breadboard using a male-female cord and some jumper wires, the circuit works. I then proceeded to plug the sensor back into the breadboard in a different spot and that worked too. Thank you to everyone who contributed to helping solve this issue

1 Like

Between projects, with nothing connected, examine your breadboard. Look for signs of melted plastic. Vigorously clean the holes with Isopropyl Alcohol and a stiff bristle brush (electronics likes to use the "acid brush"... but a toothbrush can work). The connections inside the breadboard can be seen from the bottom/back if the protective layer is removed. Sometimes this protective layer is double-sized, foam tape, sometimes it is hard plastic. Under that protective layer are "shorting" clips that do two things: (1) conduct and (2) hold the component leg. If a larger-than-normal component leg was forced into a clip, that clip could become wider than the normal component leg, creating a non-reliable connection. Bend any deformed clip back to shape so it pinches component legs. Have fun!

p.s. A weak or dirty connection causes increased resistance and will cause electric components to overheat.

Great advice, thanks