Este proyecto consiste en la manipulación del eje de un servomotor desde un navegador, para ser controlado requiere de una señal PWM, existen librerías que fueron desarrolladas para controlar el servomotor a diferntes grados.
/*
Creado: Luis Alvarez (edualv1723@gmail.com)
https://alvelectronics.com
*/
#include <WiFi.h>
#include <WebServer.h>
#include <ESP32Servo.h>
const char* ssid = "TuSSID";
const char* password = "TuPassword";
WebServer server(80);
Servo servo;
const int servoPin = 14;
int angulo = 90; // Posición inicial
void handleRoot() {
String html = "Control Servo ";
html += "Control de Servomotor - ESP32
";
html += "";
html += "Ángulo: " + String(angulo) + "°
";
html += "";
server.send(200, "text/html", html);
}
void handleSet() {
if (server.hasArg("value")) {
angulo = server.arg("value").toInt();
servo.write(angulo);
Serial.printf("Ángulo: %d°\n", angulo);
}
server.send(200, "text/plain", "OK");
}
void setup() {
Serial.begin(115200);
servo.attach(servoPin);
servo.write(angulo);
WiFi.begin(ssid, password);
Serial.print("Conectando a WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Conectado, IP: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/set", handleSet);
server.begin();
Serial.println("Servidor HTTP iniciado");
}
void loop() {
server.handleClient();
}