Cording error i don't know how to fix this ...someone can help me?


Help me please

Posting pictures of code is a waste of time and you don't even say what the problem is

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

Semicolons do not belong at the end of an "if" like you have

But yeah, post text, not pictures; we are not Ancient Egyptians

Although I also hate screenshots of code and errors, the error message gives you a hint. Did you read the error message or just dump the screenshot here without looking at it?

This is the cording.. the error in if(cm<50)

void setup()
{
Serial.begin(9600);
pinMode(buzzer,OUTPUT);
}

void loop()
{
//measure the ping time in cm
cm = 0.01723 * readUltrasonicDistance(7, 7);
//convert to inches by dividing by 2.54
inches = (cm / 2.54);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.printIn("cm");
delay(100); //Wait for 100 millisecond(s)

if (cm<50);
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);
}

}

I see that you decide to ignore the advice about using code tags when posting code and that you also did not post the complete sketch or full error message

There is a semicolon here that should be removed:

if (cm<50);
1 Like

See reply #3, from 2 hours ago :neutral_face:

If that's your complete code, there is no surprise. To begin with, you have no variables or constants with global scope. There is also no function readUltrasonicDistance defined in your code.

The full list of errors and warnings

Arduino: 1.8.5 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_115289\sketch_may19a.ino: In function 'void setup()':

sketch_may19a:4: error: 'buzzer' was not declared in this scope

   pinMode(buzzer, OUTPUT);

           ^~~~~~

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_115289\sketch_may19a.ino: In function 'void loop()':

sketch_may19a:10: error: 'cm' was not declared in this scope

   cm = 0.01723 * readUltrasonicDistance(7, 7);

   ^~

sketch_may19a:10: error: 'readUltrasonicDistance' was not declared in this scope

   cm = 0.01723 * readUltrasonicDistance(7, 7);

                  ^~~~~~~~~~~~~~~~~~~~~~

sketch_may19a:12: error: 'inches' was not declared in this scope

   inches = (cm / 2.54);

   ^~~~~~

sketch_may19a:16: error: 'class HardwareSerial' has no member named 'printIn'; did you mean 'println'?

   Serial.printIn("cm");

          ^~~~~~~

          println

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_115289\sketch_may19a.ino:19:15: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]

   if (cm < 50);

               ^

sketch_may19a:21: error: 'buzzer' was not declared in this scope

     digitalWrite(buzzer, HIGH);

                  ^~~~~~

exit status 1
'buzzer' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

So how i fix this?

Have you posted the complete sketch that you are trying to compile ?

Maybe you could point us at the site you got the sketch from

I refer from this link

Did you type in all of the code that was shown on the screen ? If so, then you have not posted it here

Yes i type all the code but I don't know why still error at if(cm<50)

Then why haven't you posted all of your code ?

Just want confirmation

Confirmation of what ?

This all code
Just help me to fix thi error at if(cm<50)

#define buzzer 10
int inches = 0;
int cm = 0;

long readUltrasonicDistance (int triggerPin, int echoPin)
{
pinMode (triggerPin, OUTPUT) ; //Clear the trigger
// Sets the trigger pin to HIGH state for 10microseconds
digitalWrite (triggerPin, High);
delayMicroseconds(10);
digitalWrite (triggerPin, LOW);
pinMode (echoPin, HIGH);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);
pinMode(buzzer,OUTPUT);
}
void loop()
{
//measure the ping time in cm
cm = 0.01723 * readUltrasonicDistance(7, 7);
//convert to inches by dividing by 2.54
inches = (cm / 2.54);
Serial.print (inches);
Serial.print ("in, ");
Serial.print (cm);
Serial.printIn("cm");
delay(100); //Wait for 100 millisecond(s)

if(cm<50)
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);
}

}

  digitalWrite (triggerPin, High);

should be

  digitalWrite (triggerPin, HIGH);
  Serial.printIn("cm");

should be

  Serial.println("cm");  //letter l for (line) not I for (India)

With those changes the code compiles