NEED HELP FOR CODING MY PROJECT

I used PIR, servo, water sensor, ultrasonic, buzzer, lm35 and relay in my project. There is too much errors when its complied. Any body help me please.

#include <Servo.h>
Servo myservo;
  
#define servo position
#define ldrPin A3
#define ledPin 6

int deger;

int pwm;

int const waterSens = A4;

int const trigPin = 4;

int const echoPin = 3;

int const buzzPin = 5;

int role=1;
       
int lm35=A5;

int pos = 0;

int inputPin = 7;

int pirState = LOW;

int val = 0;

void setup() {
//Servo, fan, su sensörü,ldr, ultrasonic, buzzer
  Serial.begin(9600); 
  myservo.attach(2);
  analogReference(INTERNAL);   
  pinMode(role,OUTPUT);      
  pinMode(ledPin, OUTPUT);
  pinMode(ldrPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzPin, OUTPUT);
  pinMode(inputPin, INPUT); 
}

void loop()
//Sıcaklık sensörü ve fan
{
  int okunanDeger = analogRead(A0);       
  float derece = okunanDeger / 9.31;      
  Serial.println(derece);                 
  delay(1000);

  if(derece >25)
    digitalWrite(role,HIGH);         
    else
    digitalWrite(role,LOW);               

    //Servo
int sensorValue = analogRead(waterSens);      
  sensorValue = map(sensorValue, 0, 1023, 0, 180); 
     if (sensorValue >= 50) {
        for (pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(15);
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }     
     }  
else{
    myservo.write(0);
}
  Serial.println(sensorValue);
  delay(20);        
}

//Ldr ve led

deger = analogRead(ldrPin); 
  pwm = map(deger,700,1023,255,0);
  Serial.print("LDR Degeri = ");
  Serial.print(deger);
  Serial.print(" PWM Degeri = ");
  Serial.println(pwm);
  analogWrite(ledPin,pwm);
}

//Ultrasonic

int duration, distance;

digitalWrite(trigPin, HIGH); 

  delay(1);
  
digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  
distance = (duration/2) / 29.1;
     
if (distance <= 50 && distance >= 0) 
{
      
      
digitalWrite(buzzPin, HIGH);
    
}
 else
 {
      
      
digitalWrite(buzzPin, LOW);

   }
 
    delay(60);

}

//PIR hırsız sensörü

pinMode(buzzPin, OUTPUT);

if (pirState == LOW) 
{
    Serial.println("Alarm aktif!");
      
      pirState = HIGH;
    }
  }
  else {
      playTone(0, 0);
      delay(300);    
      if (pirState == HIGH){
      Serial.println("Alarm deaktif!");
      pirState = LOW;
    }
  }
}
void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(buzzPin,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(buzzPin, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}

And that’s my error page

Arduino:1.8.5 (Windows 10), Kart:"Arduino/Genuino Uno"

Proje:81: error: 'deger' does not name a type

 deger = analogRead(ldrPin); 

 ^

Proje:82: error: 'pwm' does not name a type

   pwm = map(deger,700,1023,255,0);

   ^

Proje:83: error: 'Serial' does not name a type

   Serial.print("LDR Degeri = ");

   ^

Proje:84: error: 'Serial' does not name a type

   Serial.print(deger);

   ^

Proje:85: error: 'Serial' does not name a type

   Serial.print(" PWM Degeri = ");

   ^

Proje:86: error: 'Serial' does not name a type

   Serial.println(pwm);

   ^

Proje:87: error: expected constructor, destructor, or type conversion before '(' token

   analogWrite(ledPin,pwm);

              ^

Proje:88: error: expected declaration before '}' token

 }

 ^

exit status 1
'deger' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is my school project and very important for me.

Do this:

  • Tools > Auto Format
  • Now check the automatic indentation to see whether it matches your intended program structure.

Do you see the problem?

You brace management needs improvement. Because of that you have an extra curly brace (likely close brace } ) in loop() which is causing the compiler to think you are declaring deger and pwm instead of assigning the value.

As for Serial does not name a type, you have declared it. Check out the serial examples to see how to declare it.

Correct those and post back your new code.

pert:
Do this:

  • Tools > Auto Format
  • Now check the automatic indentation to see whether it matches your intended program structure.

Do you see the problem?

Nothing is changed :frowning:

Instead of throwing a big mess into the IDE, how about actually doing a piece of the project at a time and get it working before adding another piece?

Is that a novel idea or what?

.

uzaybakici:
Nothing is changed :frowning:

Wrong. The code you posted has terrible formatting. When you do Auto Format the formatting will automatically be fixed. This will make it easy for you to see the problems in your code.

Now if you were expecting Auto Format to magically fix your code then I guess you didn't read my last reply carefully.

adwsystems:
You brace management needs improvement. Because of that you have an extra curly brace (likely close brace } ) in loop() which is causing the compiler to think you are declaring deger and pwm instead of assigning the value.

As for Serial does not name a type, you have declared it. Check out the serial examples to see how to declare it.

Correct those and post back your new code.

Thanks for all for the help. I solved first error message and looking for other errors. I will post back when i finish all errors.