Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save syukron-al/c329a77a1528c4889b582866f1ceb604 to your computer and use it in GitHub Desktop.
Save syukron-al/c329a77a1528c4889b582866f1ceb604 to your computer and use it in GitHub Desktop.
#include <Servo.h> //Library untuk motor servo
Servo myservo; //Membuat object 1 buah Servo
int pinSensorLDR = 0; //Pin input untuk sensor LDR
int hasil; //Membuat variable untuk hasil sensor
void setup() {
myservo.attach(6); //Hubungkan servo pada Pin 6 Arduino
}
void loop() {
hasil = analogRead(pinSensorLDR); //hasil = input dari sensor LDR
hasil = map(hasil, 10, 800, 0, 180); //Convert hasil LDR untuk Servo
myservo.write(hasil); //Putar servo sesuai hasil LDR
delay(15); //Delay
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment