Hi guys, so in this project I have 2 PIR motion sensors (A2,A4 pins), one photo resistor (A0 pin) and 8 smd LEDs (D4-D11). Logic is next:
If no light = true,
if there is motion on PIR1 or PIR2 =true
turn LEDs ON
My main problem is with PIR sensors, they are turning on without motion. I don't know why, and need your help. This code is working fine without functions for turning on SMD LEDs. But..when I'm implementing this functions code is going crazy.
I did testing without LEDs, and everything is working perfect..
#define PIR1 A4
#define PIR2 A2
#define photoR A0
int i, val1 = 0, val2 = 0, brojac;
void setup() {
for (i = 4; i <= 11; i++) {
pinMode(i, OUTPUT);
}
pinMode(photoR, INPUT);
Serial.begin(9600);
}
void paljenjeSvijetlaGore() {
for (brojac = 4; brojac <= 11; brojac++) {
digitalWrite(brojac, HIGH);
delay(250);
}
delay(5000);
for (brojac = 4; brojac <= 11; brojac++) {
digitalWrite(brojac, LOW);
delay(250);
}
}
void paljenjeSvijetlaDolje() {
for (brojac = 11; brojac >= 4; brojac--) {
digitalWrite(brojac, HIGH);
delay(250);
}
delay(5000);
for (brojac = 11; brojac >= 4; brojac--) {
digitalWrite(brojac, LOW);
delay(250);
}
}
void loop() {
val1 = analogRead(PIR1);
val2 = analogRead(PIR2);
if (analogRead(photoR) > 800) {
Serial.println("Uso je u petlju FOTO");
if (val1 > 0) {
paljenjeSvijetlaGore();
delay(1500);
} else if (val2 > 0) {
paljenjeSvijetlaDolje();
delay(1500);
}
val1 = LOW;
val2 = LOW;
delay(400);
}
}