Pages: 1 [2]   Go Down
Author Topic: How to control a video  (Read 1209 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

SERIAL MONITOR output
Code:
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
...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, I'm sorry, i wrote:
Code:
void loop(){
 
  //digitalWrite(ledPin, HIGH);
  Serial.println(digitalRead(pirPin), DEC);
  if(digitalRead(pirPin) == HIGH){
...


SERIAL MONITOR OUTPUT
Code:
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
...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this code:
Code:
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
PIR just went HIGH  ---- static without motions
PIR just went LOW   ---- 1 motion
PIR just went HIGH ----- static
Right?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
      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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Output:
Code:
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

Logged

Pages: 1 [2]   Go Up
Jump to: