Hi all. I am trying to make an Arduino program to make a noise when my cat jumps onto the counter (a regular problem). I got the code for the PIR motion sensor I have (parallax #910-28027). I tried to get an LED to light first so that I could test my code. It didn't work. Here is the code:
const int motion_1 = 2;
const int light_1 = 13;
const int LED = 10;
int val = 0;
int old_val = 0;
int state = 0;
void setup(){
pinMode (motion_1,INPUT);
pinMode (light_1, OUTPUT);
}
void loop (){
digitalWrite (light_1,LOW);
delay(1000); //this delay is to let the sensor settle down before taking a reading
int sensor_1 = digitalRead(motion_1);\
if (sensor_1 == HIGH){
digitalWrite(light_1,HIGH);
delay(500);
digitalWrite(light_1,LOW);
delay(500);
}
val = digitalRead(light_1);
if ((val==HIGH) && (old_val==LOW)){
state = 1 - state;
delay(10);
}
old_val = val;
if (state == 1) {
digitalWrite(LED,HIGH);
} else {
digitalWrite(LED,LOW);
}
}
Can you give me a bit of help? Thanks in advanced.