Go Down

Topic: HC-SR04 Ultrasonic Sensor dead? (Read 759 times) previous topic - next topic

ScienceGuy3

Hi, I have been trying to get my HC-SR04 sensor to work using the newping 1.5 library and no matter what I do it just gives readings of 0cm and then 1149cm randomly.  I have tried pins 11 and 12, 12 and 13, and 5 and 6 and nothing seems to work.  I even tried changing the baudrate and that just did the same thing.  Do you think my brand new sensor is faulty?

joe mcd

I am not sure what you mean by 'baud rate'.  These devices are not using serial comm.


ScienceGuy3

Well, I have it plugged into an arduino which is communicating over serial the distances, so thats why I need to set the baud rate.

joe mcd

Your arrangement is not clear to me.  The baud rate from your computer to the Arduino has no effect on the sensor connection.
Perhaps you should attach a diagram as well as your code.

Do you have a 2nd sensor you can try?

kenschiele

I'm in the same boat - with a HC-SR04 sensor that appears to be dead.

FYI - my situation:  The "duration" between trigger and echo is a fairly consistent 23ms, no matter what the sensor is pointing at - my hand or the wall across the room.  The 23ms is the duration between send/receive - it gets rounded down to 0cm, 0inches for every sketch example I've seen, it wasn't until I added:

  Serial.print(duration);
  Serial.print("ms, ");

to my print commands that I saw was getting some non-zero values, but they don't move (at all).  So ... I think the sensor is dead.   

Has anyone else seen this?

Forgive me if the answer is in here - I'm new to the forums, looked around a bit, and this was the only forum topic that seemed to address it....

Thanks - KS

kenschiele

ScienceGuy - did you get yours from Amazon (their crazy-cheap add-on deal?).

I saw a few bad reviews, saying theirs didn't work.  Maybe there's a bunch of bad ones out there.  If it IS in fact dead --- It's almost too bad it was so cheap ... it's probably not worth the time/effort to return it.


pmlapl

Use the following code for a test. It doesn't use the new ping library.

Code: [Select]
/*
* HCSR04Ultrasonic/examples/UltrasonicDemo/UltrasonicDemo.pde
*
* SVN Keywords
* ----------------------------------
* $Author: cnobile $
* $Date: 2011-09-17 02:43:12 -0400 (Sat, 17 Sep 2011) $
* $Revision: 29 $
* ----------------------------------
*/

#include <Ultrasonic.h>

#define TRIGGER_PIN  12
#define ECHO_PIN     13

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);

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

void loop()
  {
  float cmMsec, inMsec;
  long microsec = ultrasonic.timing();

  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
  inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
  Serial.print("MS: ");
  Serial.print(microsec);
  Serial.print(", CM: ");
  Serial.print(cmMsec);
  Serial.print(", IN: ");
  Serial.println(inMsec);
  delay(1000);
  }


Select your own pins instead of 12 and 13 if you need to.
If you don't get some good output, the sensor must be bad.
Good luck.

kenschiele

Ok - I've fiddled enough and learned enough to decide that I've got a dead sensor (I guess a $5 ultrasonic sensor is too good to be true!).

pmlapl - Thanks for the sample code to try!  I found similar code on-line which I re-read, re-typed and read through it again until I understood it all. and while occasionally the sensor seems to have signs of life (can hear it 'chirping' sometimes) - the output is a consistent 23-24ms.

Oh well - I picked up a PIR sensor, and have some halloween decoration special effects automation in the works - a great 1st project, IMO - fun getting my feet wet.  The PIR triggers glowing eyes on a spider, along with ... piezo buzzer noises and maybe even a motor to make it wiggle.  Just the glowing LED eyes so far....




Go Up