Good day! I would like to ask some help and guidance in making our project work.
our project is composed of 5 PIR sensors which are connected to pin 0 to 4 and pin 8 to 12 as output.
The idea is when a sensor detects movement the output will be delayed for a certain period of time.
For example, if sensor1 detected motion, output1 will "on" after 5 seconds.
The problem I'm getting my code is during this scenario:
i set the delay for 5 seconds. Then I triggered 1 sensor, then after 3 seconds I triggered another. The output delay with the first sensor is working but for the other sensor it seems it inherited the delay of the first sensor. What happened is both output turned on after 5 seconds. The second output suppose to turn on after 3 seconds after the output of the 1st sensor.
Here is my code
long runtime,Tdiff,prev = 0;
char set[32] ={
0x00,
0x01,
0x02,
0x03,
0x04,
0x05,
0x06,
0x07,
0x08,
0x09,
0x0A,
0x0B,
0x0C,
0x0D,
0x0E,
0x0F,
0x10,
0x11,
0x12,
0x13,
0x14,
0x15,
0x16,
0x17,
0x18,
0x19,
0x1A,
0x1B,
0x1C,
0x1D,
0x1E,
0x1F
};
int count = 0;
void setup() {
for(int ledPin1 = 0; ledPin1 <5; ++ledPin1){
pinMode(ledPin1, INPUT);
}
for(int ledPin = 8; ledPin <13; ++ledPin){
pinMode(ledPin, OUTPUT);
}
}
void loop() {
for(int x = 0x00; x <=31; x++){
if(PIND >= x ){
bilang();
if(count >=5){
count = 0;
PORTB = ~set[ x ];
}
}
}
}
void bilang()
{
runtime = millis();
Tdiff = runtime-prev;
if (Tdiff>1000)
{
count++;
prev = runtime;
}
}
sorry for the long post ![]()
thank you ![]()