#include Servo myServo; const int SERVO_PIN = D5; // GPIO7 — signal wire const int BUTTON_180 = D0; // GPIO2 — press to go to 180 degrees const int BUTTON_0 = D1; // GPIO3 — press to go to 0 degrees int currentAngle = 0; void setup() { Serial.begin(115200); // Internal pull-up: pin reads HIGH normally, LOW when button pressed pinMode(BUTTON_180, INPUT_PULLUP); pinMode(BUTTON_0, INPUT_PULLUP); myServo.attach(SERVO_PIN, 500, 2500); myServo.write(currentAngle); delay(1000); Serial.println("Ready. Press a button."); } void loop() { // Button pressed = pin goes LOW (because other leg is GND) if (digitalRead(BUTTON_180) == LOW) { if (currentAngle != 180) { currentAngle = 180; myServo.write(currentAngle); Serial.println("Moving to 180 degrees."); } delay(200); // Debounce } if (digitalRead(BUTTON_0) == LOW) { if (currentAngle != 0) { currentAngle = 0; myServo.write(currentAngle); Serial.println("Moving to 0 degrees."); } delay(200); // Debounce } }