a problem with the code

i have an error in this code which i tried to solve but couldn’t…if anyone can help me here

smartdustbin.ino (1.5 KB)

What is it supposed to do?
What does it do now?

Learn to use code tags </>.

Why is this:

if (dist < 50) {
  servo.attach(servoPin);
  delay(1);
  servo.write(0);
  delay(3000)
  servo.write(150);
}

outside a function?