#include <Servo.h>
Servo myServo;
const int buttonPin = 2; // Push button ke pin 2 Arduino
int buttonState = 0;
void setup() {
myServo.attach(9); // Servo di pin 9
pinMode(buttonPin, INPUT_PULLUP); // Menggunakan pull-up internal
}
void loop() {
buttonState = digitalRead(buttonPin); // Membaca status tombol
if (buttonState == LOW) { // Jika tombol ditekan
myServo.write(90); // Servo bergerak ke 90 derajat
} else {
myServo.write(0); // Servo kembali ke 0 derajat
}
delay(10); // Delay kecil untuk stabilitas
}