#include Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position const int stepSize = 10; // define the step size const int maxPos = 180; // maximum servo angle const int minPos = 0; // minimum servo angle void setup() { myservo.attach(D7); // attaches the servo on pin 9 to the servo object myservo.write(pos); // set initial position Serial.begin(9600); } void loop() { if (Serial.available() > 0) { // check if data is available to read char command = Serial.read(); // read the incoming byte if (command == '1') { // if the command is '1' pos += stepSize; // increase position by stepSize if (pos > maxPos) { // if the position exceeds maxPos pos = maxPos; // set it to maxPos } myservo.write(pos); // move the servo to the new position Serial.println(pos); // print the new position } else if (command == '0') { // if the command is '0' pos -= stepSize; // decrease position by stepSize if (pos < minPos) { // if the position falls below minPos pos = minPos; // set it to minPos } myservo.write(pos); // move the servo to the new position Serial.println(pos); // print the new position } } }