multiple libraries were found servo.h

I am designing "Smart door lock system" using nodemcu and android application.
But During the compilation time my nodemcu returns an error that is:

Arduino: 1.8.5 (Windows 8), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (3M SPIFFS), v2 Lower Memory, Serial1, None, Only Sketch, 115200"

Smart_Door:20: error: 'servo' does not name a type

Multiple libraries were found for "Servo.h"
Used:
exit status 1
'servo' does not name a type

My Code :

#include <ESP8266WiFi.h>
#include <Servo.h>

const char* ssid = "ssid name";
const char* password = "password";

Servo servo;//create servo object to control a servo 12 servo
//object can be created on most boards

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
servo.attach(2); // attaches the servo on GPIO2 to the servo
object

//int ledPin = 13;

void setup() {
Serial.begin(115200);
delay(1000);
//connect to wifi network
Serial.println();
Serial.println();
Serial.print("Connecting to ..");
Serial.print(ssid);
WiFi.begin(ssid);
while(WiFi.status()!= WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" ");
Serial.println("Wifi Connected");
//Start Server
server.begin();
Serial.println("server started at..");
Serial.println(WiFi.localIP());
}

void loop() {
int pos; //to control servo motor
//check if a client has connected
WiFiClient client = server.available();
if(!client) {
return;
}
//wait until the client sends some data
Serial.println("new client");
while(!client.available()) {
client.setNoDelay(1);
}
//Read the first line of the request
String req = client.readStringUntil('/r');
Serial.println(req);
client.flush();
//match the request for the angle movement of the servo motor
//for door lock
if(req.indexOf("/lock/0") != -1) {
//goes from 0 degrees to 180 degrees
for(pos = 0; pos <= 180; pos += 1) {
//tell servo to go to positon in variable 'pos'
servo.write(pos);
//wait 15ms for the servo to reach the position
delay(15);
}
} else if(req.indexOf("/unlock/1") != -1) {
//for unlock
//goes from 180 degrees to 0 degrees
for(pos = 0; pos <= 180; pos -= 1) {
//tell servo to go to positon in variable 'pos'
servo.write(pos);
//wait 15ms for the servo to reach the position
delay(15);
}
} else {
Serial.println("invalid request");
client.stop();
return;
}
//return the response
client.println("HTTP/1.1 200 OK");
client.println("Content_Type: text/html");
client.println("");//do not forget this one
client.print("Door is");
if(pos == 180) {
client.print("Unlock");
} else {
client.print("lock");
}
Serial.println("client disconnected");
//the client will actually be disconnected
//when the function returns & 'client' object is destroyed
}

Please give me your suggestions.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup (such as the smiley face above), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Also posted at:

If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

Move this line:

servo.attach(2); // attaches the servo on GPIO2 to the servo object

to inside your setup() function.

BTW, the "multiple libraries found" message is just some helpful information provided to you by the Arduino IDE, not an error. You can ignore that message unless the library it shows having been used was not the library you intended to be used. In this case the correct library was used so all is well.

The error you should have focused on is:

Smart_Door:20: error: 'servo' does not name a type
 servo.attach(2); // attaches the servo on GPIO2 to the servo object 
 ^
1 Like