int cahaya = 0;
int gerak = 0;
void setup(){
// put your setup code here, to run once:
pinMode(A0,INPUT);
pinMode(4, INPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your setup code here, to run once:
cahaya = analogRead(A0);
gerak = digitalRead(4);
if((cahaya > 500)&&(gerak == HIGH)) {
Serial.println(cahaya);
Serial.println("ada gerakan");
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
if((cahaya > 500)&&(gerak == LOW)) {
Serial.println(cahaya);
Serial.println("tidak ada gerakan");
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
}
if((cahaya <= 500)&&(gerak == HIGH)) {
Serial.println(cahaya);
Serial.println("ada gerakan");
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}
else {
Serial.println(cahaya);
Serial.println("tidak ada gerakan");
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
delay(1000);
}