How to control a video

Hello everybody,
I'd like to control a video via PIR sensor.
I've just bought an Arduino 2009.
I have to show a video on a projector (PC or MAC + Projector) and i want to start playing the video when this sensor is excited.
Is it possible? Are there any softwares?
Thank you very much.

Alberto

Is it possible?

Yes.

Are there any softwares?

Possibly.

i want to start playing the video when this sensor is excited.

And stop when it is bored?

I have to show a video on a projector (PC or MAC + Projector)

First step is to define how you are going to do this. If you have existing software that is going to play the video, it might be possible to get that software to operate based on serial input.

If you don't have existing software, Processing might come in handy. It can play video, and listen to the serial port.

Thank you PaulS.
So, can Arduino send the sensor status via USB?

So, can Arduino send the sensor status via USB?

Yes, using Serial.print(), Serial.println(), or Serial.write(), depending on your needs.

Thank you,
I'm trying to read serial data using that functions, but the PIR sensor sends "00000000000001111111" series when there is not movement.
When there are motions it sends "00000000000".
Processing gets "94848494949494949494848484848484848484848484848484848494949" series.

  if ( myPort.available() > 0) { 
    val = myPort.read(); 
    print(val);  
  }

I used this code:
http://www.arduino.cc/playground/Code/PIRsense

I put Serial.print(digitalRead(pirPin)); in the loop block.
Why is this unstable?

I put Serial.print(digitalRead(pirPin)); in the loop block.
Why is this unstable?

Where you put the print statement is important. Where did you put it?

void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec"); 
         delay(50);
         }         
         takeLowTime = true;
       }

Serial.print(digitalRead(pirPin)); 

     if(digitalRead(pirPin) == LOW){  
....

I thought that it sends 1 when there is not movement, so i put that in the loop() function.
Thank you very much PaulS(I'm new)

I'm new

Then you should use every trick in the book to help you visualize what your code is doing. Put each { and } on its own line. Use Tools + Auto Format to properly line up the braces and indent all code in between the braces.

I thought that it sends 1 when there is not movement, so i put that in the loop() function.

Where do you turn the LED off? Why don't you store the value read from the PIR pin the first time, then print that. You are currently reading the pin again. The second reading may not get the same result as the first reading.

I tried this code so that i can debug the sensor output:

int calibrationTime = 5;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 2;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;

int value = 0;


/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){
  Serial.println(digitalRead(pirPin));
  }

But when there is not movement: 00000000001111111100000....
When there is: 0000000000000000000(sometime there is some 1)

I'm using Serial Monitor.

Maybe, do i need a 10khom resistor?

I tried this code so that i can debug the sensor output:

Clearly, it is time for you to get very, very specific. What sensor are you talking about?

PIR sensors generally have two states - detecting movement or not detecting movement. In general, they do not need to be "calibrated". If all you are doing is waiting for the sensor to get ready, why don't the comments reflect that? 5 seconds is a long time to wait for a PIR sensor to get ready.

How is the sensor connected to the Arduino?

I'm using this sensor:
http://www.robot-italy.com/product_info.php?products_id=1558

The site says the sensor needs 1-2 seconds.

I connected the red wire to 5V, the black one to 2nd digital pin, the brown one to GND.

The alarm pin is an open collector meaning you will need a pull up resistor on the alarm pin.

Or, you can use the built-in pullup resistor. You are currently explicitly turning the internal pullup resistor off.

Just i find the resistor, i'll keep you posted.
Thank you very much PaulS :slight_smile:

You don't need to add an external resistor. Use the internal one.

Change:

  digitalWrite(pirPin, LOW);

to:

  digitalWrite(pirPin, HIGH);

Then, the digitalRead() function should return LOW when there is motion, and HIGH when there is none.

int calibrationTime = 2;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 2;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;

int value = 0;


/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, HIGH);
  value = digitalRead(pirPin);
  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

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

  if(digitalRead(pirPin) == HIGH){
    digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
    if(lockLow){  
      //makes sure we wait for a transition to LOW before any further output is made:
      lockLow = false; 

      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec"); 

      delay(50);
    }         
    takeLowTime = true;
  }

  if(digitalRead(pirPin) == LOW){       
    digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

    if(takeLowTime){
      lowIn = millis();          //save the time of the transition from high to LOW
      takeLowTime = false;       //make sure this is only done at the start of a LOW phase
    }
    //if the sensor is low for more than the given pause, 
    //we assume that no more motion is going to happen
    if(!lockLow && millis() - lowIn > pause){  

      //makes sure this block of code is only executed again after 
      //a new motion sequence has been detected

      lockLow = true;                        
      Serial.print("motion ended at ");      //output
      Serial.print((millis() - pause)/1000);
      Serial.println(" sec");

      delay(50);
    }
  }

}

I changed that line in setup() function.
Analyzing the LED, when there is not movement, LED IS ON, where there is, it blinks.

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.

I put

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

SERIAL MONITOR output

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

Oh, I'm sorry, i wrote:

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

SERIAL MONITOR OUTPUT

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

Try this 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?