2
#define pingTrig 6 
#define pingEcho 7 

#include 

Servo myservo;

void setup()
{
pinMode(pingTrig, OUTPUT);
pinMode(pingEcho, INPUT);
myservo.attach(9);
}

void loop()
{
long duration, inches, cm;

digitalWrite(pingTrig, LOW);
digitalWrite(pingTrig, HIGH);
delayMicroseconds(10);
digitalWrite(pingTrig, LOW);

duration = pulseIn(pingEcho, HIGH);

cm = duration / 29 / 2;

if(cm < 10 ){
myservo.write(90);
delay(100);
}else{
myservo.write(0);
}
delay(2000);
} 
Stavro Isho
  • 21
  • 1
  • 1
  • 3

1 Answers1

3

Your include statement seems to be incomplete; add "Servo.h" to your include to make it look like this:

#include "Servo.h"

Without including "Servo.h", the compiler doesn't know what a servo is, and thus "Servo does not name a type".

BrettFolkins
  • 4,431
  • 1
  • 13
  • 26