#include // Define the servo pin const int servoPin = D0; // Cambia este pin según tu configuración // Create a servo object Servo myServo; int position = 90; // Inicializar el ángulo en el centro void setup() { // Initialize serial communication Serial.begin(115200); // Attach the servo to the pin myServo.attach(servoPin); // Initialize the servo to the center position myServo.write(position); // Print instructions Serial.println("Ingrese un angulo entre 0 y 180 grados:"); } void loop() { // Check if data is available to read if (Serial.available() > 0) { // Read the incoming value String input = Serial.readStringUntil('\n'); input.trim(); // Eliminar espacios en blanco if (input == "R") { position = 180; } else if (input == "L") { position = 0; } else { int newPosition = input.toInt(); if (newPosition >= 0 && newPosition <= 180) { position = newPosition; } } myServo.write(position); Serial.print("Servo movido a: "); Serial.println(position); } }