1

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.

dda
  • 6,030
  • 2
  • 25
  • 34
  • Keep only 1 library for servo and remove all other libraries. **use this library** : *https://github.com/arduino-libraries/Servo* hope this will help you !!!! – Aamir Attar Apr 07 '18 at 09:02
  • I am designing smart door lock using nodemcu and android application.so, for that I have to use an esp8266 library to connect nodemcu to wifi or please give me any suggestions through which I can establish a communication between nodemcu and android application – krishnapriya neema Apr 07 '18 at 12:28
  • 1
    Also asked at: http://forum.arduino.cc/index.php?topic=540207 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. – per1234 Apr 08 '18 at 12:18

0 Answers0