please help when i am compiling code i get =>exit status 1
'servo' does not name a type
my code =
#include <Servo.h>
#define buzzer 3
#define trigPin 5
#define echoPin 6
Servo servo;
int sound = 250;
void setup()
{
// put your setup code here, to run once:
Serial.begin (9600);
servo.attach (9);
servo.write(90);
}
void loop() {
// put your main code here, to run repeatedly:
long duration, distance;
digitalWrite (trigPin, LOW);
delayMicroseconds (2);
digitalWrite (trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
servo.write (115);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
servo.write(140);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
servo.write(165);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
servo.write(90);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
servo.write(75);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
servo.write(50);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
servo.write(25);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
servo.write(0);
if (distance < 10 && distance > 5)
{
Serial.println("the distance is less than 10");
digitalWrite (buzzer, HIGH);
delay(500);
}
else
{
digitalWrite (buzzer, LOW);
}
if (distance > 60 || distance <= 0)
{
Serial.println("The distance is more than 60");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
}