#include <Servo.h>
Servo myServo; // create a servo object
int pos = 0; // variable to store the servo position
void setup() {
myServo.attach(9); // attach the servo to pin 9
Serial.begin(9600); // initialize serial communication
}
void loop() {
if (Serial.available() > 0) { // check if there is incoming serial data
char input = Serial.read(); // read the incoming byte
if (input == 'w') { // if the input is 'w'
pos = 180; // set the servo position to 180 degrees
myServo.write(pos); // move the servo to the new position
delay(500); // wait for the servo to finish moving
pos = 0; // reset the servo position to 0 degrees
myServo.write(pos); // move the servo back to the original position
}
}
}