I need help to my code

// defines pins numbers
const int trigPin = 11;
const int echoPin = 10;
const int relay1 = 5;
const int relay2 = 6;
// defines variables
long duration;
int distance;
long distancemm;

void setup() {
// put your setup code here, to run once:
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(relay1, OUTPUT);// Control Pin
pinMode(relay2, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}

void loop() {
// put your main code here, to run repeatedly:
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
distancemm = distance * 10 + 30;

//Control

if (distancemm > 80 && distancemm < 160)
{
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW);
}
else
{
if (distance > 160)
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, HIGH);
} else
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);

  {

  }

  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
  //Serial.print("Distance: ");
  Serial.print(distancemm);
  Serial.println("mm");
  delay(250);
}

You need to sort out your opening and closing braces.

Please remember to use code tags when posting.

Post error messages, not pictures of error messages.

What makes you think this is an installation issue?

Did you try using auto format?

Images of error message are poo!.

Use code tags when posting code.

Did you count that there is a { for every } in the correct place? Auto format would be a good bet to use to find the issue.

Hi, @mihai-carare
To add code please click this link;

Thanks. Tom... :grinning: :+1: :coffee: :australia:

Why do you have an empty block of code?

If you will properly format your code the IDE will show you which braces match so you can see if you are missing braces or have extra braces.

yes i try auto formay

It looks like you meant to write:

  if (distancemm > 80 && distancemm < 160)
  {
    digitalWrite(relay1, HIGH);
    digitalWrite(relay2, LOW);
  }
  else if (distancemm > 160)
  {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, HIGH);
  }
  else
  {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
  }