Project Untuk Kelompok 7
Komponen yang dibutuhkan :
- Arduino (Versi apapun) >> 1 Buah.
- Sensor PIR (passive infrared) HC-SR501 >> 1 Buah.
- Buzzer >> 1 Buah.
- Led >> 1 Buah.
- Resistor 1K >> 1 Buah.
- Kabel >> Seperlunya.
/*
* Generated Code by Kang Kamal
* kangkamal.blogspot.com
*/
int pinLed = 13;
int buzzer = 8;
int pinPIR = 7;
int terdeteksi;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(pinLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(pinPIR, INPUT);
digitalWrite(pinLed, LOW); //Matikan Led
digitalWrite(buzzer, LOW); //Matikan Buzzer
}
void loop() {
// put your main code here, to run repeatedly:
terdeteksi = digitalRead(pinPIR);
if (terdeteksi == HIGH){ //Jika terdeteksi objek bergerak
digitalWrite(pinLed, HIGH); //Nyalakan Led
digitalWrite(buzzer, HIGH); //Nyalakan Buzzer
delay(2000);
digitalWrite(pinLed, LOW); //Matikan Led
digitalWrite(buzzer, LOW); //Matikan Buzzer
}
else{
digitalWrite(pinLed, LOW); //Matikan Led
digitalWrite(buzzer, LOW); //Matikan Buzzer
}
}
0 comments:
Post a Comment