How to fix " Compilation error: expected primary-expression before '<=' token " error in my code

Hey everyone, I'm new to coding on Arduino and just can't figure out an error occurring in my code. I am getting an Compilation error: expected primary-expression before '<=' token

Below is my entire code:

#include <Servo.h>

Servo myservo;  


int pos = 0;    

//www.elegoo.com
//2016.12.08
#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;

void setup() {
  Serial.begin(9600);
  myservo.attach(9);  
  Serial.begin(9600);
   delay(1000);
}

void loop() {
  a=sr04.Distance();
   Serial.print(a);
   Serial.println("cm");
   delay(1000);
  if (a)<= 40;
  
   for (pos = 0; pos <= 180; pos += 1) { 
    // in steps of 1 degree
    myservo.write(pos);             
    delay(1);                       
  }
  for (pos = 180; pos >= 0; pos -= 1) { 
    myservo.write(pos);             
    delay(1);                       
  }
 
}

PLS PLS PLS help!!

Welcome to the forum

  if (a) <= 40;

That is not how you write an if statement in C

Did you perhaps mean

  if (a <= 40)

It will not cause an error but why

  Serial.begin(9600);

twice ?

Sir, you are a HERO!! ty

noted boss ty

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