Hi guys. I'm facing a problem with my programming.
Project objective: Smart lighting. 5 Lamp-post with infrared sensors and led.
Right now i'm able to light up the LED to 100% once motion is detected. However the problem now is once lamp 1 detected motion, it light up for 5secs. if in between the 5sec, lamp 2 detected motion, it does not override the code of lamp 1.
Any kind soul is able to guide me one this?
if(FC1==0)
{
schedule1(); //
FC1=2;
}
if(FC2==0)
{
schedule2();
FC2=2;
}
if(FC3==0)
{
schedule3();
FC3=2;
}
if(FC4==0)
{
schedule4();
FC4=2;
}
if(FC5==0)
{
schedule5();
FC5=2;
}
if(sensor1==LOW && a==0) //motion detected when sensor1 is LOW
{
analogWrite(LED2,255);
analogWrite(LED1,255);
a=1;FC1=1;FC2=1;timeElapsed1=0;
}
if(sensor2==LOW && b==0)
{
analogWrite(LED2,255);
analogWrite(LED1,255);
analogWrite(LED3,255);
b=1; bitch=1; FC1=1; FC2=1; FC3=1;timeElapsed2=0;
}
if(sensor3==LOW && c==0)
{
analogWrite(LED2,255);
analogWrite(LED3,255);
analogWrite(LED4,255);
c=1;FC2=1; FC3=1; FC4=1;
}
if(sensor4==LOW )
{
analogWrite(LED3,255);
analogWrite(LED4,255);
analogWrite(LED5,255);
d=1; FC3=1; FC4=1; FC5=1;
}
if(sensor5==LOW )
{
analogWrite(LED4,255);
analogWrite(LED5,255);
e=0; FC4=1; FC5=1;
}
///////////////////////////////////////////////////////////////
if (sensor1==HIGH && a==1 && && sensor2==HIGH && b==0)
{
//timeElapsed1=0; //timer function
a=0;
if(sensor1==HIGH && b==0 && sensor2==HIGH)
{
FC1=0;FC2=0;
}
}
///////////////////////////////////////////////////////////////
if (sensor2==HIGH && b==1 && (timeElapsed2 >=5000) ) //no motion detected after detected
{
//timeElapsed2=0;
b=0;
if(sensor1==HIGH && sensor2==HIGH && sensor3==HIGH)
{
FC2=0;FC1=0;FC3=0;
}
}
//////////////////////////////////////////////////////////////
if (sensor3==HIGH && c==1 && timeElapsed3 >=5000)
{
timeElapsed3=0;
c=0;FC2=0;FC3=0;FC4=0;
}
///////////////////////////////////////////////////////////////
if (sensor4==HIGH && d==1 && timeElapsed4 >=5000)
{
timeElapsed4=0;
d=0;FC3=0;FC4=0;FC5=0;
}
///////////////////////////////////////////////////////////////////
if (sensor5==HIGH&& e==1 && timeElapsed5 >=5000)
{
timeElapsed5=0;
e=0;FC3=0;FC4=0;FC5=0;
}
void schedule1()
{
if(t.hour == 19 && t.min >= 0) //
{
analogWrite(LED1, map(70,20,100,0,255));
}
else if(t.hour == 20 && t.min >= 0)
{
analogWrite(LED1, map(90,20,100,0,255));
}
else if(t.hour == 21 && t.min >= 0)
{
analogWrite(LED1, map(25,20,100,0,255));
}
else if(t.hour == 22 && t.min >= 0)
{
analogWrite(LED1, map(70,20,100,0,255));
}
else if(t.hour == 23 && t.min >= 0)
{
analogWrite(LED1, map(60,20,100,0,255));
}
else if(t.hour == 00 && t.min >= 0)
{
analogWrite(LED1, map(40,20,100,0,255));
}
else if(t.hour == 01 && t.min >= 0)
{
analogWrite(LED1, map(30,20,100,0,255));
}
else if(t.hour == 02 && t.min >= 0)
{
analogWrite(LED1, map(30,20,100,0,255));
}
else if(t.hour == 03 && t.min >= 0)
{
analogWrite(LED1, map(30,20,100,0,255));
}
else if(t.hour == 04 && t.min >= 0)
{
analogWrite(LED1, map(40,20,100,0,255));
}
else if(t.hour == 05 && t.min >= 0)
{
analogWrite(LED1, map(80,20,100,0,255));
}
else if(t.hour == 06 && t.min >= 0)
{
analogWrite(LED1, map(80,20,100,0,255));
}
}