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);
}
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
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.
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
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
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.