I have attached a digital camera to an Arduino Mini.
4 wires from the camera are attached to the Arduino
-Ground
-"Power on"
-"Focus"
-"Shutter"
4N35 relays make the various connections to ground in order to get the camera to "do what it do."
A PIR detector is attached to an input pin.
I am trying to complete the sequence of events as shown in the comments on the sketch.
The problem is what to do when I "break" out of the "while."
I want it to turn the camera off and wait for more motion, but it doesn't seem to take another reading from the PIR within the "while", even though I think I am telling it to.
Help please?
const int pirPin = 8;
const int powerPin = 9;
const int focusPin = 7;
const int shutterPin = 4;
void setup (){
pinMode(pirPin, INPUT);
pinMode(powerPin, OUTPUT);
pinMode(focusPin, OUTPUT);
pinMode(shutterPin, OUTPUT);
delay(30000); // Allow time for the PIR to power up and calibrate, around 30 seconds.
}
void loop (){ // Do nothing until motion is detected from the PIR.
int val = digitalRead(pirPin);
if (val == HIGH) // If motion is detected, turn the camera on.
{
digitalWrite(powerPin, HIGH);
delay(500);
digitalWrite(powerPin, LOW);
delay(2000); // Wait 2 seconds.
}
while (val == HIGH) // While motion is detected, leave the camera on and take pictures, see below.
{
if (val == LOW) // If no motion is detected,
{
digitalWrite(powerPin, HIGH); // turn the camera off
delay(500);
digitalWrite(powerPin, LOW);
delay(2000); // Wait 2 seconds.
break; // break out of the "while" and return to the beginning of the loop.
}
digitalWrite(focusPin, HIGH); // focus
delay(1500);
digitalWrite(shutterPin, HIGH); // snap a picture
delay(500);
digitalWrite(focusPin, LOW); // release the focus
digitalWrite(shutterPin, LOW); // and shutter
delay(5000); // wait 5 seconds and return to the beginning of the while to check for more motion
}
}