Pages: [1] 2   Go Down
Author Topic: How to control a video  (Read 1095 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Quote
Is it possible?
Yes.

Quote
Are there any softwares?
Possibly.

Quote
i want to start playing the video when this sensor is excited.
And stop when it is bored?

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

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

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

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

Quote
So, can Arduino send the sensor status via USB?
Yes, using Serial.print(), Serial.println(), or Serial.write(), depending on your needs.
Logged

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

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

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

Quote
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?
Logged

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

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

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

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

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

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

I tried this code so that i can debug the sensor output:
Code:
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?
Logged

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

Quote
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?

Logged

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

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

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

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

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

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

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

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

Change:
Code:
  digitalWrite(pirPin, LOW);
to:
Code:
  digitalWrite(pirPin, HIGH);

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

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

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

Pages: [1] 2   Go Up
Jump to: