Skip to content

Instantly share code, notes, and snippets.

@igrr
Last active January 9, 2023 23:35
Show Gist options
  • Save igrr/9ef4d5c74355503e3b1f to your computer and use it in GitHub Desktop.
Save igrr/9ef4d5c74355503e3b1f to your computer and use it in GitHub Desktop.
#include <Servo.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "your-ssid";
const char* pass = "your-password";
ESP8266WebServer server(80);
Servo myservo;
void setup(void){
Serial.begin(115200);
Serial.println("");
WiFi.begin(ssid, pass);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", [](){
server.send(200, "text/plain", "Open /servo?value=90 to control servo");
});
server.on("/servo", [](){
String sval = server.arg("value");
int ival = sval.toInt();
Serial.print("Servo: ");
Serial.println(ival);
myservo.write(ival);
server.send(200, "text/plain", String(ival, DEC));
});
server.begin();
Serial.println("HTTP server started");
myservo.attach(D5); // Servo attached to D5 pin on NodeMCU board
myservo.write(0);
}
void loop(void){
server.handleClient();
}
@baol
Copy link

baol commented Oct 31, 2017

@jtheires you need to disinstall the Servo library, and use the one built-in the Arduino SDK for ESP8266.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment