#include <IRremote.h>
#include <Servo.h>
#define IR_PIN 8
#define SERVO_PIN 7
IRrecv irrecv(IR_PIN);
Servo servo;
int currentAngle = 90; // Sudut awal servo
void setup() {
Serial.begin(9600); // Inisialisasi Serial Monitor
irrecv.enableIRIn();
servo.attach(SERVO_PIN);
servo.write(currentAngle);
}
void loop() {
if (irrecv.decode()) {
switch (irrecv.decodedIRData.command) {
case 2: // Kode tombol +
currentAngle += 1;
if (currentAngle > 180) {
currentAngle = 180;
}
servo.write(currentAngle);
Serial.print("Sudut Servo: ");
Serial.println(currentAngle);
break;
case 152: // Kode tombol -
currentAngle -= 1;
if (currentAngle < 0) {
currentAngle = 0;
}
servo.write(currentAngle);
Serial.print("Sudut Servo: ");
Serial.println(currentAngle);
break;
}
irrecv.resume();
}
}