Hello,
I am very new to programming and using Arduino uno. I am doing a home project as a hobby. I have two PIR sensors that I want to use to control a relay to turn on and off a 12v LED array.
Objective:
1st senerio:
If PIR1 is triggered turn on Relay, if then PIR2 is triggered turn off relay.
2nd Senerio
If PIR2 is triggered turn on Relay, if then PIR1 is triggered turn off relay.
I have the code below but it doesn't work. Any assistance would be really appreciated.
int Relay1 = 2;
int Relay2 = 3;
int PIR1 = 8;
int PIR2 = 9;
int PIR3 = 10;
int PIR4 = 11;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pins.
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(PIR1, INPUT);
pinMode(PIR2, INPUT);
pinMode(PIR3, INPUT);
pinMode(PIR4, INPUT);
}
// the loop function runs over and over again forever
void loop() {
if (digitalRead (PIR1) == HIGH)
{
digitalWrite (Relay1, HIGH);
digitalRead (PIR2);
if (PIR2 == HIGH)
{
digitalWrite (Relay1, LOW);
}
}
if (digitalRead (PIR2) == HIGH)
{
digitalWrite (Relay1, HIGH);
digitalRead (PIR1);
if (PIR1 == HIGH)
{
digitalWrite (Relay1, LOW);
}
}
if (digitalRead (Relay1) == HIGH >= 60000)
{
digitalWrite (Relay1, LOW);
}
}