Is there a mistake in these if statements with multiple conditions?

I am writing code to check if the distance that is being measured by an ultrasonic sensor is changing dramatically or staying stable. While doing that I was using if statements with multiple conditions, but I don't get any output from these Serial prints I used. There aren't any error messages but it just does not work.
Here is the code:

#define echoPin 7
#define trigPin 8

long duration;
long distance;

int distance1;
int timer;
int currentMillis;
int startMillis;
  int measure_function(){
   
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  
  //Distance in cm pog
  distance = duration/58.2;
  
  Serial.println(distance);

  delay(1000);
  }
void setup() {
  //startMillis = millis();
  Serial.begin(9600);
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
  timer = 0;
  }



void loop() {
  measure_function();
  distance1=distance;
  measure_function();
  if(distance > 1000); {
    return;
  }
  if(distance1<distance-10 || distance1<distance+10 || distance1==distance);{
    Serial.print("joemamama");
    return;
  }
  if(distance1>distance-10 || distance1>distance+10);{
    Serial.print("joemomo");
  }

}

Is there anything I did wrong that could've caused this? Any help is appreciated! Thanks in advance for any help!!! :))

if statements should not have a semicolon on the end.

1 Like

Thank you so much! That actually fixed it! Thanks :)))

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