Pages: [1]   Go Down
Author Topic: Help with project - financial reward!  (Read 1268 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I posted a week or two back about a DIY camera trap I am building.

http://forum.arduino.cc/index.php?topic=165646.0

 The unit has two PIR sensors mounted at the front of the enclosure  and an  LDR sensor all connected to Arduino UNO board and a Sony Handycam DCR-35SR  camera. The  LANC controlle coder uses a REC command to start and the same   command  to stop recording.

 The aim of the unit is to check the PIR sensors (2 off) and when either is activated, record for a period of time until the sensors are no longer active. The camera has a nightshot mode which has to be physically switched. I have a servo which completes this function based upon LDR readings.  With the kind help of fellow Arduino forum users I have some ideas for improving the LDR code however it does function at present.  

My issue is with the record and stop recording process.  I can read the PIR sensors (trigger = HIGH) and activate RECORD, however I cannot get the unit to stop recording when the signal from the PIR is low. I have spend many hours playing with while loops, if loops etc to monitor PIR and change values. I think the problem stems from the apparent  lack of LANC code to read current camera State?.  

I had thoughts on maybe adding one to a variable each time RECORD function  is triggered, assuming then that if the variable is  odd number then means its recording and even not recording.(based upon the variable being reset to 0 upon the whole unit powering up).

I have considered a timer function of say 30 seconds from initial RECORD instruction, said period of time being reset if the PIR sensor triggers HIGH. However all to no avail.

 I have spent in excess of 14 hours now "fighting" this problem and for the sake of my sanity am now hoping i can "purchase" some help! (assuming this is not breaking any forum rules?) . I am proposing a payment (by paypal only) of £15 (I would image for 20 mintues work for the right person!) for the first person who can provide me with functioning code to achieve my goals as stated above (I know this seems a cop out but I really cant afford to spend another 14 hours trying to get this right). I hope to learn and understand the functioning from the code provided.

I am happy to provide any info needed on the arduino pins etc. I would of course try the submitted code and if it works make the payments stated. I am happy to donate it to a charity if that is so desired :-)  The code would be posted in reply to me or to my email address hecmac@o2.co.uk

I hope this is not in violation of any forum rules,

kind regards

Hec


Moderator edit: session ID removed
« Last Edit: May 18, 2013, 02:08:09 am by Coding Badly » Logged

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

my current code is

Code:


#define cmdPin 9
#define lancPin 11
#include <Servo.h>
Servo nightservo;

int cmdRepeatCount;
int bitDuration = 104; //Duration of one LANC bit in microseconds.
int ldrpin = A0;    //analog pin to which LDR is connected
int ldr_value =0;  //variable to store LDR values

int pirvalue1;      //variable to store Pirvalue
int pirvalue2;     //variable to store pir 2 value

int oldpir1value;   //variable to store old pirvalue
int oldpir2value;   //variable to store old pirvalue 2

int pir1 = 7;
int pir2 = 8;

int recordstate = LOW;


boolean REC[] = {LOW,LOW,LOW,HIGH,HIGH,LOW,LOW,LOW,   LOW,LOW,HIGH,HIGH,LOW,LOW,HIGH,HIGH}; //18 33
boolean FOCUS_AUTO[] = {LOW,LOW,HIGH,LOW,HIGH,LOW,LOW,LOW,   LOW,HIGH,LOW,LOW,LOW,LOW,LOW,HIGH}; //28 41
boolean POWER_OFF[] = {LOW,HIGH,LOW,HIGH,HIGH,HIGH,HIGH,LOW,   LOW,HIGH,LOW,HIGH,HIGH,HIGH,HIGH,LOW}; //18 5E


void setup() {

  nightservo.attach(2);                                           //Servo to switch on Night Shot
  nightservo.write(27);                                         // Set servo to base position
 
 pinMode(lancPin, INPUT);                                       //listens to the LANC line
 pinMode(cmdPin, OUTPUT);                                       //writes to the LANC line

        digitalWrite(cmdPin, LOW); //set LANC line to +5V
        delay(5000); //Wait for camera to power up completly
        bitDuration = bitDuration - 8; //Writing to the digital port takes about 8 microseconds so only 96 microseconds are left for each bit


recordstate == LOW;

 
}

void loop()

{
 
  ldr_value = analogRead(ldrpin);                  //read LDR value
 
  if (ldr_value >300) {
      nightservo.write(27);                        // IE dark , tell servo to go to position 27
      } else {
      nightservo.write(5);
 
      }
 
  pirvalue1 = digitalRead(pir1);  //read pirvalue
  pirvalue2 = digitalRead(pir2);

 
 
 
   
 
 
   



 }
 
  }
 
    { /code]
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 72
Posts: 3761
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the logic in loop that I think will do what you want. I don't see anything in your code that commands the camera, but you say you've managed to get it into record mode so I've assumed a function that does it.

Code:
void loop()
{
static bool Recording=false; // Is the camera recording?
ldr_value = analogRead(ldrpin);                  //read LDR value
 
if (ldr_value >300)
  {
  nightservo.write(27);                        // IE dark , tell servo to go to position 27
  }
else
  {
  nightservo.write(5);
  }
 
pirvalue1 = digitalRead(pir1);  //read pirvalue
pirvalue2 = digitalRead(pir2);
if(pirvalue1==HIGH || pirvalue2==HIGH)
  {
  if(!Recording)
    {
    Recording=true;
    SendRecCommand();  // Start recording
    }
  }
else
  {
  if(Recording)
    {
    Recording=false;
    SendRecCommand();  // Stop recording
    }
  }
}
Logged

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

Here's the logic in loop that I think will do what you want. I don't see anything in your code that commands the camera, but you say you've managed to get it into record mode so I've assumed a function that does it.

Code:
void loop()
{
static bool Recording=false; // Is the camera recording?
ldr_value = analogRead(ldrpin);                  //read LDR value
 
if (ldr_value >300)
  {
  nightservo.write(27);                        // IE dark , tell servo to go to position 27
  }
else
  {
  nightservo.write(5);
  }
 
pirvalue1 = digitalRead(pir1);  //read pirvalue
pirvalue2 = digitalRead(pir2);
if(pirvalue1==HIGH || pirvalue2==HIGH)
  {
  if(!Recording)
    {
    Recording=true;
    SendRecCommand();  // Start recording
    }
  }
else
  {
  if(Recording)
    {
    Recording=false;
    SendRecCommand();  // Stop recording
    }
  }
}


thanks for taking the time to reply. The command  "  lancCommand(REC) " activates the record functions.  Can you guide me through your code a little so I can understand its function,?

Kind Regards

Hec
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 72
Posts: 3761
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It uses a static boolean local variable  (a global would work too) to keep track of whether the camera is recording or not.

Every time loop executes, it checks to see if either of the pirs are detecting anything. If one or both of them is detecting, it checks to see whether the camera is already recording. If it is, the code does nothing, if it isn't, it sends the REC command to start recording.

If neither pir sees anything, it checks to see whether the camera is recording. If it is, send REC to turn it off; if it's not, do nothing.
Logged

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

It uses a static boolean local variable  (a global would work too) to keep track of whether the camera is recording or not.

Every time loop executes, it checks to see if either of the pirs are detecting anything. If one or both of them is detecting, it checks to see whether the camera is already recording. If it is, the code does nothing, if it isn't, it sends the REC command to start recording.

If neither pir sees anything, it checks to see whether the camera is recording. If it is, send REC to turn it off; if it's not, do nothing.

Thanks, the bit I am struggling to get my head round is how it knows if the camera is recording, based onthe code above?
Logged

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

Or a better way of wording this,

is m,y understanding then that in you code, Recording is a variable, blank prior to the first activation of the record function?

The record command is "  lancCommand(REC) ". Could I trouble you to place that command in the appropriate part of the code you submitted? I put it where I thought was correct but Arduino doesnt seem to like the static Bool Recording = false
statement.

thanks

Hec
Logged

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

Cancel cancel cancel, your code works well ! I am  delighted after struggling for hours! and its fairly easy to understand when broken down!,

Can you send me your paypal address and I shall send you the money. Thanks so much :-)
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 72
Posts: 3761
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad it worked - you would likely have got the same advice for free in the programming forum, so keep the cash  smiley
Logged

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

Well I am very grateful indeed, and if your still adamant then  I will happily make a donation to a worthy charity instead.

I am going to play with the code now and see if I can put the camera into sleep mode upon until its told to record.

many thanks,

Hec
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What a great community!  Thanks for everyone's help in the past and our future projects!
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Pages: [1]   Go Up
Jump to: