ultrasonic sensor max distance behavior min max unstable? hc-sr04

I can't imagine why it is so difficult for you to print the value from pulseIn() WITHOUT doing anything with it. If you did, you just MIGHT get whacked with a clue by four.

I don't know how pulseIn() is used or works

can you give me the exact code you want me to run? thanks

PaulS:
I can't imagine why it is so difficult for you to print the value from pulseIn() WITHOUT doing anything with it. If you did, you just MIGHT get whacked with a clue by four.

I don't know how pulseIn() is used or works

Then you shouldn't be using it.

The call to the function says what kind of change to wait for, measuring the time from when the call happens to when the desired change happens.

The function is measuring, correctly or incorrectly, the time that it takes the pulse that the sensor generates to travel out, hit something, and be reflected back. By dividing by the speed of the pulse, you get the distance that the pulse traveled. Since it made a round trip, the object that it hit is half that distance away.

Now, what happens if the pulse doesn't hit anything and get reflected back? The time taken would be infinite. Since you don't want the Arduino to wait forever, you supply a time limit to wait. You are assuming that ANY time returned by pulseIn() is a measure of distance. If the time is how long it took to time out, that is NOT a measure of distance.

So, quit using compound statements. Put one statement per line, and use intermediate variables as needed.

   long pulseTime = pulseIn(echoPin, HIGH);
   if(pulseTime > 0)
   {
      // The time is a function of distance, so calculate the distance
   }
   else
   {
      Serial.println("The pulse never hit anything...");
   }

oh...I shouldn't be using it?

...and to think this forum is to try learn new things and how to code arduino...

or is it just a place to ask for help to then have guys like you put me down because they think they earned the right to be rude by trying to help.

hey look if you cant help without an attitude don't bother, ye/

g43q654wutrjh:
I don't know how pulseIn() is used or works

Thankfully, the founders provided this.

RTFM early, RTFM often.

(Sorry about the typo earlier. Though, given your ridiculous attitude thus far, not very sorry at all. Whoops)

Edit: @g43q654wutrjh I just reviewed some of your earlier posts - it seems that not providing full code, and then berating others for not helping with exact solutions, (along with an unwillingness on your part to apply any effort or learning, as well as childish name-calling) seems to be your standard modus operandi.
Well, you'll get your wish - I won't be intruding on your threads any longer.

PaulS:
Since there wasn't a need to wait, uselessly, for as long, didn't that result in a decreased cycle time?

Oops. I meant "cycle rate".

maybe you have a learning difficulty.. because the "full code" was linked in the FIRST POST
and that fact was repeated multiple times.

I am more then able to look up the arduino reference myself

and thank you for excluding yourself :slight_smile:

TolpuddleSartre:
Thankfully, the founders provided this.

RTFM early, RTFM often.

(Sorry about the typo earlier. Though, given your ridiculous attitude thus far, not very sorry at all. Whoops)

Edit: @g43q654wutrjh I just reviewed some of your earlier posts - it seems that not providing full code, and then berating others for not helping with exact solutions, (along with an unwillingness on your part to apply any effort or learning, as well as childish name-calling) seems to be your standard modus operandi.
Well, you'll get your wish - I won't be intruding on your threads any longer.

I had this code saved just in case...

float distancia;
float tiempo;
int trigger=2;
int eco=3;

void setup() {
 Serial.begin(9600);
 pinMode(2,OUTPUT);
 pinMode(3,INPUT);
}

void loop() {
 digitalWrite(trigger,LOW);
 delayMicroseconds(5);
 digitalWrite(trigger,HIGH);
 delayMicroseconds(10);
 tiempo=pulseIn(eco,HIGH);
 distancia=(0.017*tiempo);
 Serial.print("Distancia: ");
 if (distancia>500){
  Serial.print("?");
 }
 else{
  Serial.print(distancia,5);
 }
 Serial.println(" Cm");
 delay(500);
}

@g43q654wutrjh is enjoying another well-earned forum timeout.