halo agan2 yg hobi dgn arduino,update lg nih...
Kemarin lusa ada kawan nyuruh buat sensor gerak utk ngawasi
gudang ,klau ada yg masuk lgsung bunyi loudspeaker di kmr nya
jd saya gunakan PIR(Passive Infrared Receiver) yg sebgai pendetek gerakan
oke..lgsng aja ke skemanya
di skema saya pake Buzzer aja,buzzer bs di ganti dgn led,kamera,jg perangkat lain
ini sketch nya:
int Buzzer_Pin = 2;//pin buzzer di pin 2 arduino
int Pir_pin = 3;
int Var_Pir = LOW;//nilai awal pir sensor
int val = 0;
void setup(){
pinMode(Buzzer_Pin, OUTPUT);
pinMode(Pir_pin, INPUT);
Serial.begin(9600);
}
//untuk beep
void Beep(long durasi, int freq){
durasi *=1000;
int period = (1.0 / freq) * 1000000;
long elapsed_time = 0;
while (elapsed_time < durasi) {
digitalWrite(Buzzer_Pin,HIGH);
delayMicroseconds(period / 2);
digitalWrite(Buzzer_Pin, LOW);
delayMicroseconds(period / 2);
elapsed_time += (period);
}
}
void loop(){
val = digitalRead(Pir_pin); //baca nilai pir sensor ke val
if (val == HIGH) { // jika nilai HIGH
Beep(300, 160);
delay(150);
//jika terdetek
if (Pir_pin == LOW) {
SerialPrintln("terdetek");
Pir_pin = HIGH;
}
} else {
Beep(0, 0);
delay(300);
if (Pir_pin == HIGH){
SerialPrintln("Kosong");
Pir_pin = LOW;
}
}
}
trus upload ke board arduino,liat hasilnya...oke sekian dulu tentang pir sensor nya
..