Need help ignoring first reading from sensors HC_SR04 im a noobie

Hello

I got a project that uses 3 sensors but the sensors have wrong readings the first time. Is there a way to ignore these first reading so that my robot ignores them. As you can see in the serial monitor the first reading is incorrect. How can we fix this?

This is my code for the program:

#define trigPinR 3
#define echoPinR 2

#define trigPinL 13
#define echoPinL 12

#define trigPinV 11
#define echoPinV 10

long duurR, cmR;
long duurL, cmL;
long duurV, cmV;


void setup() {
  // put your setup code here, to run once:
pinMode(echoPinR, INPUT);
pinMode(trigPinR, OUTPUT);
pinMode(echoPinL, INPUT);
pinMode(trigPinL, OUTPUT);
pinMode(echoPinV, INPUT);
pinMode(trigPinV, OUTPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(trigPinR, LOW);
delayMicroseconds(5);
digitalWrite(trigPinR, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinR, LOW);
pinMode(echoPinR, INPUT);
duurR = pulseIn(echoPinR, HIGH);

cmR = duurR/2 * 0.0343;


digitalWrite(trigPinL, LOW);
delayMicroseconds(5);
digitalWrite(trigPinL, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinL, LOW);

pinMode(echoPinL, INPUT);
duurL = pulseIn(echoPinL, HIGH);

cmL = duurL/2 * 0.0343;

digitalWrite(trigPinV, LOW);
delayMicroseconds(5);
digitalWrite(trigPinV, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinV, LOW);
pinMode(echoPinV, INPUT);
duurV = pulseIn(echoPinV, HIGH);

cmV = duurV/2 * 0.0343;

Serial.print(cmR);
Serial.print("cmR");
Serial.println();
Serial.print(cmL);
Serial.print("cmL");
Serial.println();
Serial.print(cmV);
Serial.print("cmV");
Serial.println();
delay(125);

This is my serial monitor:

494c2cmL
44cmV
493cmR
2244cmL
44cmV
493cmR
2244cmL
44cmV
mL
44cmV
494cmR
200cmL
44cmV

simples!

just add a global variable (could be boolean)

in setup set it as FALSE

then enclose all the printout in loop in an IF statement to check the said variable.

at end of loop set variable to TRUE

did I leave enough crumbs for you to code it? ... :stuck_out_tongue_winking_eye:

Is there a way to ignore these first reading

Yes. Read the sensor twice. Don't use the first value.

Serial.print(cmR);
Serial.print("cmR");
Serial.println();

Intelligentpeaopleusespacesnowandthen.

There is no reason to use three statements to output two pieces of data.

Serial.print(cmR);
Serial.println(" cm on Right");

[quote]As you can see in the serial monitor the first reading is incorrect.[/quote]
Actually, I can't see that. If you printed something BEFORE the first value, maybe YOU would see that the value IS correct.

[code]Serial.print("Right: ");
Serial.print(cmR);
Serial.println(" cm");

[/code]