0
int LDR_deger = 0;

int Ledpin1 = 12;
int Ledpin2 = 11;
int Ledpin3 = 10;
int Ledpin4 = 9;
int Ledpin5 = 8;

int LDR_pin = 0;

void setup()
{

  Serial.begin(9600);
  pinMode(Ledpin1, OUTPUT);
  pinMode(Ledpin2, OUTPUT);
  pinMode(Ledpin3, OUTPUT);
  pinMode(Ledpin4, OUTPUT);
  pinMode(Ledpin5, OUTPUT);
}
void loop()

{
  LDR_deger = analogRead(LDR_pin);
digitalWrite(Ledpin1,HIGH);
digitalWrite(Ledpin2,HIGH);
digitalWrite(Ledpin3,HIGH);
digitalWrite(Ledpin4,HIGH);
digitalWrite(Ledpin5,HIGH);

if (LDR_deger <= 80 && LDR_deger> 30) {
  digitalWrite(Ledpin1, LOW);
} else{
  digitalWrite(Ledpin1, HIGH);
  if (LDR_deger<= 150 && LDR_deger > 80){
  digitalWrite(Ledpin2, LOW);
  digitalWrite(Ledpin1, LOW);
  }else{
    digitalWrite(Ledpin1, HIGH);
    digitalWrite(Ledpin2, HIGH);
    if (LDR_deger  <= 200 && LDR_deger> 150){
      digitalWrite(Ledpin2, LOW);
      digitalWrite(Ledpin1, LOW);
      digitalWrite(Ledpin3, LOW);
     }else{
      digitalWrite(Ledpin1, HIGH);
      digitalWrite(Ledpin2, HIGH);
      digitalWrite(Ledpin3, HIGH);
      if (LDR_deger <= 1000 && LDR_deger> 300){
      digitalWrite(Ledpin2, LOW);
      digitalWrite(Ledpin1, LOW);
      digitalWrite(Ledpin3, LOW);
      digitalWrite(Ledpin4, LOW);
      digitalWrite(Ledpin5, LOW);
     }else{
      digitalWrite(Ledpin1, HIGH);
      digitalWrite(Ledpin2, HIGH);
      digitalWrite(Ledpin3, HIGH);
      digitalWrite(Ledpin4, HIGH);
      digitalWrite(Ledpin5, HIGH);
     }
       }
     }
   } 
  }
Serial.print("LDR Deger: ");
Serial.print(LDR_deger);
Serial.println(" ");
delay(500);
}
1
  • Don't simply post code and expect us to guess what is the problem. Also give some explanation of what you have tried
    – MichaelT
    Dec 1, 2019 at 23:55

2 Answers 2

1

One reason you are receiving the compile error, is due to the code outside of a function. When you write nice, neat, properly formatted code, these errors are easy to spot. The Arduino IDE has a built in feature that will "highlight" a matching curly bracket (or curly brace?).

enter image description here

enter image description here

1
  • Maybe the Auto Format (CTRL+T) feature should be mentioned too. It gets so obvious after using it.
    – KIIV
    Dec 2, 2019 at 14:47
0

VE7JRO already has answered your question. Below is not an answer to the question but a better way to program something like you have.

In your case, you need to set 5 pins according. I assume the following lines are just for initialization (and not needed when you set them afterwards to FALSE), as I do not see any delay.

digitalWrite(Ledpin1,HIGH);
digitalWrite(Ledpin2,HIGH);
digitalWrite(Ledpin3,HIGH);
digitalWrite(Ledpin4,HIGH);
digitalWrite(Ledpin5,HIGH);

It is much easier for each pin to set the conditions direction; this will reduce all the if statements and make it very clear for each pin what the value should be.

First we make some variables to prevent duplication. Actually I normally like using bool but it is not a predefined type. Also I like to have the low range on the left and the high range on the right, and using parenthesis. I added the range 200-300, and lower/upper range:

int LDR_deger_min_inf_30 =  (LDR_deger <= 30);
int LDR_deger_30_80      = ((LDR_deger >  30) && (LDR_deger <=   80)); 
int LDR_deger_80_150     = ((LDR_deger >  80) && (LDR_deger <=  150));
int LDR_deger_150_200    = ((LDR_deger > 150) && (LDR_deger <=  200));
int LDR_deger_200_300    = ((LDR_deger > 200) && (LDR_deger <=  300));
int LDR_deger_300_1000   = ((LDR_deger > 300) && (LDR_deger <= 1000));
int LDR_deger_1000_inf   =  (LDR_deger > 1000);

Now you can create a table for each pin (which makes great documentation and a clear overview); I would add it in a comment (if you have no other documentation way):

// pin min_inf_30 30_80 80_150 150_200 200_300 300_1000 1000_inf
//  1     HIGH     LOW    LOW     LOW   HIGH      LOW     HIGH 
//  2     .. (fill in yourself)
//  3     .. (fill in yourself)
//  4     .. (fill in yourself)
//  5     .. (fill in yourself)

Now you can write the pins one by one (I only did the first as example):

digitalWrite(Ledpin1, LDR_deger_min_inf || LDR_deger_200_300 || LDR_deger_1000_inf ? HIGH : LOW);
digitalWrite(Ledpin2, …);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.