Multiple libraries were found servo.h
error. Please help to fix.
I am getting this error:
Error:
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
servo.attach(2); // attaches the servo on GPIO2 to the servo object
^
Multiple libraries were found for "Servo.h"
Used: C:\Users\Deepak\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\Servo
Not used: C:\Program Files (x86)\Arduino\libraries\Servo
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Deepak\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\ESP8266WiFi
Using library Servo at version 1.0.2 in folder: C:\Users\Deepak\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\Servo
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 suggestions.