HC-SR04 Issue
i have several hc-sr04 ultrasonic sensors, , 2 of them stopped working. trying figure out if dead or not. bought them around 6-10 months ago, have had light use on time have owned them.
my setup:
6 hc-sr04 ultrasonic sensors
arduino mega 2560
windows 7
arduino 1.0.5
these sensors have been working past few weeks have been in on project. today 1 quit working, returns ~730 cm (works out 43 milliseconds). checked wiring, looked fine, no obvious damage sensor itself, took multimeter , poked around bit , compared working one, nothing looked different. took working 1 , swapped around non-working one. working 1 worked fine, let run 5 minutes, , still worked. bad 1 not work anywhere connected it. connected non-working sensor arduino new wiring, still did not work. 15 minutes later, 1 started doing same thing, 1 had stayed in spot whole time. repeated tests again , same, bad sensor not work anywhere, , others work in place.
here small part of code when broke:
once broke simplified down this:
i tried use newping library, return either 147cm or 0cm broken ones, , return values working ones (an occasional 0) . when did these tests swapped sensors around (working , non-working) on same port (one bad sensor originally connected to).
i'd appreciate figuring out if these sensors died or if have issue.
thanks,
tr24em
my setup:
6 hc-sr04 ultrasonic sensors
arduino mega 2560
windows 7
arduino 1.0.5
these sensors have been working past few weeks have been in on project. today 1 quit working, returns ~730 cm (works out 43 milliseconds). checked wiring, looked fine, no obvious damage sensor itself, took multimeter , poked around bit , compared working one, nothing looked different. took working 1 , swapped around non-working one. working 1 worked fine, let run 5 minutes, , still worked. bad 1 not work anywhere connected it. connected non-working sensor arduino new wiring, still did not work. 15 minutes later, 1 started doing same thing, 1 had stayed in spot whole time. repeated tests again , same, bad sensor not work anywhere, , others work in place.
here small part of code when broke:
code: [select]
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; < 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 broke simplified down this:
code: [select]
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 tried use newping library, return either 147cm or 0cm broken ones, , return values working ones (an occasional 0) . when did these tests swapped sensors around (working , non-working) on same port (one bad sensor originally connected to).
i'd appreciate figuring out if these sensors died or if have issue.
thanks,
tr24em
unfortunately looks it's broken, if google "hc-sr04 broken", you'll find quite lot of similar stories.
Arduino Forum > Using Arduino > Sensors > HC-SR04 Issue
arduino
Comments
Post a Comment