Ok, I'm new to arduino, for my first project(the reason i got into arduino) was to have a Parallax PIR tell the arduino 328 to send a sequence of pulses(you will see in code) to a 5v reed relay that opens and closes a switch on a little camera i pulled out of a DVR pen. I have an led that indicates when the board is pulsing and triggers the relay from pin 13. PIR is in digital 3 and was working with a regular "blink when movement test".
I would like if upon movement the switch was to be triggered in sequence to turn on(3sec), switch to video mode(2sec), start recording(.25sec) for a few minutes then if no movement, stop recording(.25sec), then power off(4sec).
With the modded code i was able to get the PIR to warm up and calibrate, then it automatically runs the sequence (without motion) then upon completion the board/PIR send random pulses which screws everything up when i want it to turn off and wait for more movement.
I got this code from ladyada.com, chopping it up and butchering it. I realize yall cant do it for me but a few pointers would be great even if its pointing out some good sources for me to learn the code.
kinda a big roject for a beginner :
/////////////////////////////
//VARS
int calibrationTime = 30; //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
long unsigned int lowIn; //the time when the sensor outputs a low impulse
long unsigned int pause = 5000; //the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 3; //the digital pin connected to the PIR sensor's output
int ledPin = 13;
/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
Serial.print("calibrating sensor "); //give the sensor some time to calibrate
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
}
////////////////////////////
//LOOP
void loop(){
if(digitalRead(pirPin) == HIGH){ //recording sequence
digitalWrite(ledPin, HIGH);
delay(3000); //On
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(2000); //video mode
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(250); //start recording
digitalWrite(ledPin, LOW);
delay(120000); //record
digitalWrite(pirPin, LOW);
if(lockLow){
lockLow = false; //makes sure we wait for a transition to LOW before any further output is made:
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
delay(250); //stop record
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(4000); //off
digitalWrite(ledPin,LOW);
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(!lockLow && millis() - lowIn > pause){ //if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
lockLow = true; //makes sure this block of code is only executed again after a new motion sequence has been detected
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}
Thanks for putting up with my crap :-/