Expected un-qualified id before { token

Hi thinkers!
I am getting "expected unqualified-id before ‘{’ token " ERROR… :confused:

plz help me since I have to submit my project in 18 hours…

int LDR =A0;
int led1 =13;
int led2 =12;
int led3 =13;

void setup ()
{
analogReference(DEFAULT);

pinMode (led1,OUTPUT);
pinMode (led2,OUTPUT);
pinMode (led3,OUTPUT);
}
void loop ()
{
int val = analogRead(LDR);
}

{
{
if(val < 15);
digitalWrite(led1 ,HIGH);
digitalWrite(led2 ,LOW );
digitalWrite(led3 ,LOW );
}
{
else-if(val < 10);
digitalWrite(led1 ,LOW );
digitalWrite(led2 ,HIGH);
digitalWrite(led3 ,LOW );
}
{
else(val < 5);
digitalWrite(led1 ,LOW );
digitalWrite(led2 ,LOW );
digitalWrite(led3 ,HIGH);
}
}

Waiting for any positive response…
thanx! :confused:

void loop ()
{
  int val = analogRead(LDR);
}

How many lines of code are there in your loop() function ?

   if (val < 15);
    digitalWrite(led1 , HIGH);
    digitalWrite(led2 , LOW );
    digitalWrite(led3 , LOW );

Which lines of code will be executed, if any, if the test returns true ?

   else - if (val < 10);

What is that minus sign doing there and note my previous comment.

   else(val < 5);
    digitalWrite(led1 , LOW );
    digitalWrite(led2 , LOW );
    digitalWrite(led3 , HIGH);

Again, which lines of code will be executed and is the test right anyway ?

Your braces are a mess - at the moment the only thing that's inside the main loop is the statement.

int val = analogRead(LDR);

Then you need to read up on the syntax for those if / else statements.

There’s a couple of problems with your code:

  1. Lines 18-39 are outside of the loop function. This is the cause of the compilation error.
  2. Your if / else syntax is not correct. The correct syntax would be:
void loop() {
  if(<condition 1>) {
    // code if condition 1 is true
  } else if(<condition 2>) {
    // code if condition 1 is false, and condition 2 is true
  } else {
    // code if conditions 1 and 2 are both false
  }
}
  1. analogReference(DEFAULT); is a bit pointless, since it already has the default value when the program starts.

Finally, please read How to use this forum, use the IDE’s auto format function (CTRL+T) and make use of [code][/code] tags (</>) when posting code.

Pieter

int LDR =A0;
int led1 =13;
int led2 =12;
int led3 =13;

Two LEDs on the same pin?

Are you planning on changing the pin assignments, or having negative pin numbers?
No?
So why not "const byte LDR = A0;" ?