Created
January 31, 2021 15:47
-
-
Save syukron-al/c329a77a1528c4889b582866f1ceb604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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