Pages: 1 [2]   Go Down
Author Topic: Programming logic using 2 ultrasonic sensor hc-sr04  (Read 1852 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im, sorry how to print raw result?
i only know how to use serial.print.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24424
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i only know how to use serial.print.
So, use that to print the values returned by the rangefinders, before you make any decisions based on those values.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Edison Member
*
Karma: 20
Posts: 2115
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

instead of "out of range" post the reading .... ie what's the value..

Code:
 if (distance >= 3 && distance <= 50)
  {
  
    Serial.print(distance);
    Serial.println(" cm");
  
    digitalWrite(LED, HIGH);
  }
  
   if (bdistance >= 3 && bdistance <= 50)
  {
 
  
    digitalWrite(LED2, HIGH);
  }
  
  else {
     Serial.println("Out of range");
     Serial.print(bdistance);
     Serial.println(" cm");

     digitalWrite(LED, LOW);
     digitalWrite(LED2, LOW);
  }
  delay(500);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i use "else if" right now and i use the delay. it seems to work fine..
thank you for all your help guys..  smiley-grin
Logged

NE Wisconsin
Offline Offline
Full Member
***
Karma: 0
Posts: 195
Arduino is the Better Stamp!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you list your current code that works?
I just purchased one of these sensors on ebay and need some help figuring out the code for it. I thought this module would be the same as the Ping))). I was wrong, but hope to get it to work just as well.

Thank you.
Logged

Pages: 1 [2]   Go Up
Jump to: