Problem : expected unqualified-id before 'if'

Hi Guys.............. I am having a problem which shows like error: expected unqualified-id before 'if'. here is my code :

int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;
int LED10 = 11;
int LED11 = 12;
const int trigPin = 9;
const int echoPin = 10;
int t = 70;

if (distance = 5cm or > 5cm) { ................................................................//here the code gets error

digitalWrite(led1, HIGH);
delay(t);
digitalWrite(led2, HIGH);
delay(t);
digitalWrite(led3, HIGH);
delay(t);
digitalWrite(led4, HIGH);
delay(t);
digitalWrite(led5, HIGH);
delay(t);
digitalWrite(led6, HIGH);
delay(t);
digitalWrite(led7, HIGH);
delay(t);
digitalWrite(led10, HIGH);
delay(t);
digitalWrite(led11, HIGH);
delay(t);
digitalWrite(led12, HIGH);
delay(t);
digitalWrite(led13, HIGH);
delay(t);
}
//single line

Well, it should be "==", and what is the "cm" doing in there?

if (distance == 5 or distance > 5)
// Or simply
if (distance >= 5)

Also, which function is that code part of?

Hi, @geochat
Welcome to the forum.

This might help with logical operators, OR and AND etc.
https://www.circuitbasics.com/using-logical-operators-in-arduino-programming/

Tom.. :smiley: :+1: :coffee: :australia:

Variable names can not start with a number.
Was this your intention?

int cm = 5;
if(distance >=cm){}

The intention is kinda moot - the code isn't in a function.

Your topic has been moved to a more suitable location on the forum.

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and the forum software will display it correctly.

Hi, @geochat
Your code is not even Arduino structured;
This may be of help;

Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.