Go Down

Topic: How to control a video (Read 1 time) previous topic - next topic

PaulS

What's with the lockLow stuff? Verify that you can read the PIR status correctly, all the time, every time, before trying to take any action based on that status.

bettola

I put
Code: [Select]

void loop(){
  //digitalWrite(ledPin, HIGH);
  //Serial.println(digitalRead(pirPin), DEC);
  Serial.println(lockLow, DEC);
...


SERIAL MONITOR output
Code: [Select]

calibrating sensor .. done
SENSOR ACTIVE
1
---
motion detected at 2 sec
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

PaulS

Code: [Select]
Serial.println(lockLow, DEC);
Why? Do you care what value lockLow has? It seems to me that you want to print the value of digitalRead(pirPin).

bettola

Oh, I'm sorry, i wrote:
Code: [Select]

void loop(){
 
  //digitalWrite(ledPin, HIGH);
  Serial.println(digitalRead(pirPin), DEC);
  if(digitalRead(pirPin) == HIGH){
...



SERIAL MONITOR OUTPUT
Code: [Select]

calibrating sensor ... done
SENSOR ACTIVE
1
---
motion detected at 3 sec
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...a lot  of 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1      HERE, THERE IS ONE MOVEMENT AND LED BLINKS
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
1
1
1
1
...

PaulS

Try this code:
Code: [Select]
int currPirState = LOW;
int prevPirState = LOW;

void loop()
{
   currPirState = digitalRead(pirPin);
   if(currPirState != prevPirState)
   {
      // A change occurred
      if(currPirState == LOW)
      {
         Serial.println("PIR just went LOW");
      }
      else
      {
         Serial.println("PIR just went HIGH");
      }
   }
   prevPirState = currPirState;
}


Does it print the messages at the right time, and only the right time?

bettola

Code: [Select]

calibrating sensor ... done
SENSOR ACTIVE
PIR just went HIGH  ---- static without motions
PIR just went LOW   ---- 1 motion
PIR just went HIGH  ----
PIR just went LOW  -----
PIR just went HIGH ----- static



I think it doesn't print right messages, if there is only one movement, it should print:
Code: [Select]

PIR just went HIGH  ---- static without motions
PIR just went LOW   ---- 1 motion
PIR just went HIGH ----- static

Right?

PaulS

Quote
I think it doesn't print right messages, if there is only one movement, it should print:
<snip>
Right?

I think that I agree with you. So, the next question is how far apart are the messages, with respect to the motion. Make some changes to the code.

Code: [Select]
      if(currPirState == LOW)
      {
         Serial.print("PIR just went LOW at ");
         Serial.println(millis());
      }
      else
      {
         Serial.print("PIR just went HIGH at ");
         Serial.println(millis());
      }


Let's see whether the PIR switch needs debouncing. I wouldn't think so, but maybe it does.

bettola

Output:
Code: [Select]

calibrating sensor ... done
SENSOR ACTIVE
PIR just went HIGH at 3109
PIR just went LOW at 6784
PIR just went HIGH at 6816
PIR just went LOW at 6863
PIR just went HIGH at 7110
PIR just went LOW at 7181
PIR just went HIGH at 7698


Go Up