// MADE BY CAKRA YP :)
// Sensor Pendeteksi Pergerakan.
// PIR Motion Sensor
#define InputPIR 8
// LED RGB
#define Led_RED 7
#define Led_GREEN 6
#define Led_BLUE 5
// LED Protect from PIR
#define Led_1 4
#define Led_2 3
int pirState = LOW;
// Main
void setup() {
Serial.begin(9600);
Serial.println("<Arduio UNO is ready>");
// PIR Motion Sensor
pinMode(InputPIR, INPUT);
// PIN LED RGB
pinMode(Led_RED, OUTPUT);
pinMode(Led_GREEN, OUTPUT);
pinMode(Led_BLUE, OUTPUT);
// PIN LED Protect from PIR
pinMode(Led_1, OUTPUT); // RED
pinMode(Led_2, OUTPUT); // Green
}
// Loop for repeatedly the programs.
void loop() {
int isDetectedPIR = digitalRead(InputPIR); // For motion sensor.
// The PIR has 2 functions, namely 0 and 1
// HIGH = 1
// LOW = 0
// Let's Setup the PIR
if (isDetectedPIR == HIGH) {
digitalWrite(Led_RED, LOW);
digitalWrite(Led_GREEN, LOW);
digitalWrite(Led_BLUE, HIGH);
digitalWrite(Led_1, LOW);
digitalWrite(Led_2, HIGH);
if (pirState == LOW) {
Serial.print("[PIR]: ");
Serial.println("Motion detected!");
pirState = HIGH;
}
} else {
digitalWrite(Led_RED, HIGH);
digitalWrite(Led_GREEN, HIGH);
digitalWrite(Led_BLUE, LOW);
digitalWrite(Led_1, HIGH);
digitalWrite(Led_2, LOW);
if (pirState == HIGH) {
Serial.print("[PIR]: ");
Serial.println("Motion Ended!");
pirState = LOW;
}
}
}