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);
} 
asked Nov 27, 2014 at 23:02

1 Answer 1

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".

answered Nov 28, 2014 at 1:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.