NEED HELP PLEASE! error: expected unqualified-id before '{' token

So this is a program that uses an Arduino Nano to detect distance, lumens, and utilizes an RF transmitter and receiver. The distance and lumens code works, but I cant figure out how to get the "remote" feature to work. I keep getting the error "error: expected unqualified-id before '{' token" on line 38 (Which I have marked for you). If you guys could help me with this error or reformat the code so everything works smoothly, it would be greatly appreciated since I am new to this! Thank you very much in advance :slight_smile:
P.S. I know I suck for leaving out comments ill add them at the end

#define trigPin 3
#define echoPin 2
#define buzzer 12
#define ldrPin A0
#define Remote A1

long time_taken;
int Signal;
int Intens;
//int similar_count;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(ldrPin, INPUT);

}

void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
time_taken = pulseIn(echoPin, HIGH);
distance=time_taken0.034/2;
{
if (distance>300)
distance=300;
}
}
**//line38--> {[/u]
if (distance<75)
[u]
{[/u]
Serial.print(distance); Serial.println(" Object Alert");
digitalWrite(buzzer,HIGH);
for (int i=distance; i>0; i--)
tone(buzzer,700);
delay(10);
digitalWrite(buzzer,LOW);
for (int i=distance; i>0; i--)
delay(5);
noTone(buzzer);
[u]
}[/u]
[u]
{[/u]
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <= 100)
[u]
{[/u]
digitalWrite(buzzer, HIGH);
tone(buzzer,900);
delay(200);
tone(buzzer,800);
delay(200);
tone(buzzer,700);
delay(200);
Serial.println(ldrStatus);
Serial.print(" lumens detected, it's too dark! \n\n");
[u]
}[/u]
else
[u]
{[/u]
digitalWrite(buzzer, LOW);
noTone(buzzer);
[u]
}[/u]
if (ldrStatus >= 700) {
digitalWrite(buzzer, HIGH);
tone(buzzer,1100);
delay(200);
tone(buzzer,1000);
delay(200);
tone(buzzer,900);
delay(200);
Serial.println(ldrStatus);
Serial.print(" lumens detected, it's too bright! \n\n");
[u]
}[/u]
else {
digitalWrite(buzzer, LOW);
noTone(buzzer);}
[u]
}[/u]
[u]
//Check if Remote is pressed**[/u]
int temp = analogRead(Remote);
int similar_count=0;
while (Signal==temp)
{
Signal = analogRead(Remote);
similar_count++;
}
//If remote pressed
if (similar_count<100)
{
Serial.print(similar_count); Serial.println(" Remote Pressed");
digitalWrite(buzzer,HIGH);delay(3000);digitalWrite(buzzer,LOW);
/*tone(buzzer,700);
delay(100);
tone(buzzer,600);
delay(100);
tone(buzzer,500);
delay(100);
tone(buzzer,600);
delay(100);
tone(buzzer,700);
delay(100);
noTone(buzzer);
digitalWrite(buzzer,LOW);
[u]__noTone(buzzer);
/__[/u]
}
else {
return 0;
}
}

Line 37 has a closing brace that ends your loop function which I doubt was your intention.

When I remove the closing brace I get this error now...

In function 'void loop()':
error: expected '}' at end of input

You need to format ( tools/autoformat) your code and check that each opening bracket has a corresponding closing bracket - that is almost certainly the issue .

You don't need a code block here:

  {
    if (distance > 300)
      distance = 300;
  }

Or here:

{
    int ldrStatus = analogRead(ldrPin);

    if (ldrStatus <= 100)
    {

      digitalWrite(buzzer, HIGH);
      tone(buzzer, 900);
      delay(200);
      tone(buzzer, 800);
      delay(200);
      tone(buzzer, 700);
      delay(200);

      Serial.println(ldrStatus);
      Serial.print(" lumens detected, it's too dark! \n\n");
    }
    else
    {
      digitalWrite(buzzer, LOW);
      noTone(buzzer);
    }

    if (ldrStatus >= 700) {

      digitalWrite(buzzer, HIGH);
      tone(buzzer, 1100);
      delay(200);
      tone(buzzer, 1000);
      delay(200);
      tone(buzzer, 900);
      delay(200);

      Serial.println(ldrStatus);
      Serial.print(" lumens detected, it's too bright! \n\n");

    }
    else {

      digitalWrite(buzzer, LOW);
      noTone(buzzer);
    }
  }

This return does nothing because you are returning from loop() which will get called again anyway. Besides loop() is void so there is no reason to return a 0:

  else {
    return 0;
  }

Thank you guys!!