PIR sensor to Canon

Hey guys…
so basically i’ve been following this tutorial:

http://luckylarry.co.uk/arduino-projects/arduino-motion-triggered-camera/

but the led does not blink when there is motion im not even sure if the motion is detected in the PIR

Thanks a lot

Without your code and knowing that the PIR is correctly connected, we cannot tell what is happening.

Weedpharma

sorry about that and thanks for replying!

int currentState = 0;                                   // set a variable to store a count.
int pinPIR = 4;                                         // digital pin 4 for PIR
int pinLED = 9;                                         // digital pin 9 for LED
int pinIRLED = 13;                                      // assign the Infrared emitter/ diode to pin 13

void setup() {
  pinMode(pinIRLED, OUTPUT);                            // set the pin as an output
  pinMode(pinLED, OUTPUT);                              // set the LED pin as ouput
  pinMode(pinPIR, INPUT);                               // set the PIR pin as an input
}

// sets the pulse of the IR signal.
void pulseON(int pulseTime) {
  unsigned long endPulse = micros() + pulseTime;        // create the microseconds to pulse for
  while( micros() < endPulse) {
    digitalWrite(pinIRLED, HIGH);                       // turn IR on
    delayMicroseconds(13);                              // half the clock cycle for 38Khz (26.32×10-6s) - e.g. the 'on' part of our wave
    digitalWrite(pinIRLED, LOW);                        // turn IR off
    delayMicroseconds(13);                              // delay for the other half of the cycle to generate wave/ oscillation
  }

}

void pulseOFF(unsigned long startDelay) {
  unsigned long endDelay = micros() + startDelay;       // create the microseconds to delay for
  while(micros() < endDelay);
}

void takePicture() {
  for (int i=0; i < 2; i++) {
    pulseON(2000);                                      // pulse for 2000 uS (Microseconds)
    pulseOFF(27850);                                    // turn pulse off for 27850 us
    pulseON(390);                                       // and so on
    pulseOFF(1580);
    pulseON(410);
    pulseOFF(3580);
    pulseON(400);
    pulseOFF(63200);
  }                                                     // loop the signal twice.
}

void loop() {
   // read the input pin:
 int pinPIR = digitalRead(pinPIR);
 // print out the state of the button:
 Serial.println(pinPIR);
 delay(1);  // delay in between reads for stability
}

You need to learn how to put your code in its own window as seen in other posts. This can be done by placing     [code] and [/code]  around the code. This makes it easier for others to read.

Break your code into smaller sections. Test the PIR section on its own then add more.

You appear to also have all the program in setup() rather than loop().

Setup is just that, setup the basics. Put the program in loop()

Weedpharma

Continuing the theme of "break it into sections"...

At the end of the day, all the PIR is doing is "pushing a button". Replace the part done by the PIR with an actual button, see if the rest of your "take a picture" system DOES take a picture when you press a button. If not, work on the rest. If so, go back to why the PIR isn't taking the place of the button.

weedpharma:
You appear to also have all the program in setup() rather than loop().

There is a loop(), right at the bottom after the other functions, but all it does is read the PIR's pin.... nothing in there to do with output.

Thanks everyone for your help!

I’m trying this code now:

int currentState = 0;                                   // set a variable to store a count.
int pinPIR = 4;                                         // digital pin 4 for PIR
int pinLED = 9;                                         // digital pin 9 for LED
int pinIRLED = 13;                                      // assign the Infrared emitter/ diode to pin 13

void setup() {
  pinMode(pinIRLED, OUTPUT);                            // set the pin as an output
  pinMode(pinLED, OUTPUT);                              // set the LED pin as ouput
  pinMode(pinPIR, INPUT);                               // set the PIR pin as an input
}

// sets the pulse of the IR signal.
void pulseON(int pulseTime) {
  unsigned long endPulse = micros() + pulseTime;        // create the microseconds to pulse for
  while( micros() < endPulse) {
    digitalWrite(pinIRLED, HIGH);                       // turn IR on
    delayMicroseconds(13);                              // half the clock cycle for 38Khz (26.32×10-6s) - e.g. the 'on' part of our wave
    digitalWrite(pinIRLED, LOW);                        // turn IR off
    delayMicroseconds(13);                              // delay for the other half of the cycle to generate wave/ oscillation
  }

}

void pulseOFF(unsigned long startDelay) {
  unsigned long endDelay = micros() + startDelay;       // create the microseconds to delay for
  while(micros() < endDelay);
}

void takePicture() {
  for (int i=0; i < 2; i++) {
    pulseON(2000);                                      // pulse for 2000 uS (Microseconds)
    pulseOFF(27850);                                    // turn pulse off for 27850 us
    pulseON(390);                                       // and so on
    pulseOFF(1580);
    pulseON(410);
    pulseOFF(3580);
    pulseON(400);
    pulseOFF(63200);
  }                                                     // loop the signal twice.
}

void loop() {

  if ((digitalRead(pinPIR) == LOW) && (currentState <= 2)) { // count to limit the taking of photos
    takePicture();                                      // take the picture
    digitalWrite(pinLED, HIGH);                         // turn LED on
  } else {
    digitalWrite(pinLED, LOW);
    currentState = 0;                                   //reset the count when the PIR is off.
  }

  currentState++;
  delay(2000);                                          // delay for 2 seconds - 2 seconds between taking photos if the PIR is active for more than 2 seconds.
}

I feel like my circuit might be wrong,
. I’ve tried only the PIR sensor and the signal seemed to be working, /

I cannot make out what is connected to what in the pictures.

Make a CLEAR circuit drawing on a sheet of paper and then take a CLEAR IN FOCUS picture. Attach to a post.

Weedpharma

At adafruit they also make a carrier of f=38kHz (T= 26us) here: note that the delays there are not 2x13us like yours to give the required 26us, but 2x10us. That's because the digitialWrite() commands use up 2x3us so there's 6us of the 26us accounted for before you start.

With 2x3us and 2x13us you have a total of 32us, so your carrier will be about 1/32 = 31kHz: that may or may not be within the range your camera will accept as a nominal 38kHz.

In my attachment to this thread, I experimented with the TSOP IR receiver of nominal 38kHz. It worked with a 35kHz carrier but not 30kHz; I didn't home in any closer. Your 31kHz pulse might be too low for a detector expecting 38kHz.

If you have a 'scope you can adjust the "13" and measure the actual frequency, but you'll almost certainly get closer to 38kHz with "10".

Hey guys, thanks for all the help.
After some consideration I decided to test out the sensor first and then build from there.
I got this code from Adafruit

int pirPin = 7;

int minSecsBetweenEmails = 30; // 1 min

long lastSend = -minSecsBetweenEmails * 500l;

void setup()
{
  pinMode(pirPin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  long now = millis();
  if (digitalRead(pirPin) == HIGH)
  {
    if (now > (lastSend + minSecsBetweenEmails * 500))
    {
      Serial.println("MOVEMENT");
      lastSend = now;
    }
    else
    {
      Serial.println("Too soon");
    }
  }
  delay(500);
}

and the circuit looks like this (attached)

However, while looking at Serial, and experimenting with moving the wires, I noticed that at the end, it didnt even matter if the sensor was plugged in. I unplugged all the wires from the breadboard from the sensor and it kept reading MOVEMENT every few seconds… what gives?

Maybe a loose wire where it connects to PIR module?

Try connecting things as in your diagram, but UN-plug the yellow wire from the Arduino, and connect that to one side of a voltmeter. Connect the other side of the voltmeter to your system's ground (zero volts... where the black wire goes.) You should see near zero some of the time, near your Vcc otherwise.

====
Hmmm... are you using a 5v PIR ith a 3v3 Arduino, maybe?

====
In you CODE you say the PIR pin is 4, but in your DIAGRAM you've plugged it into D7.

But could be plenty of other things, too.

tkbyd:
Maybe a loose wire where it connects to PIR module?

Try connecting things as in your diagram, but UN-plug the yellow wire from the Arduino, and connect that to one side of a voltmeter. Connect the other side of the voltmeter to your system's ground (zero volts... where the black wire goes.) You should see near zero some of the time, near your Vcc otherwise.

====
Hmmm... are you using a 5v PIR ith a 3v3 Arduino, maybe?

====
In you CODE you say the PIR pin is 4, but in your DIAGRAM you've plugged it into D7.

But could be plenty of other things, too.

Hi ! thanks for your reply.

The last post I wrote I used a different code from the one that I have in the one I wrote first. This one does have the PIR pin at 7,
the problem here is that when I unplug the entire sensor, the power, ground and signal wires... the serial still reads as "Movement"

that's getting me very confused, since the PIR is not at all connected. Very confusing...

An input with NOTHING connected "floats", and will, more or less randomly, give "0" or "1".

Oddly enough, I've just been working on stuff arising from...

... which has stuff which may enlighten, or help.

Assuming you are using the "modern" Arduino software, and that your PIRs output is going to connect to input D7 of the Arduino... on setup(), include...

pinMode(7, INPUT_PULLUP);

This "connects" a resistor between the input and Vcc. So if PIR is acting like open switch at some point, the input to the Arduino isn't "floating". It assumes that the circuit in the PIR can "pull the line down", which I think it can. Voltmeter will tell you.

Thanks again Tkbyd,

I did just as you said and the Voltmeter told stated 0.01 ... and added pinMode(7, INPUT_PULLUP);

To begin with, the serial now does not

int pirPin = 7;

int minSecsBetweenEmails = 30; // 1 min

long lastSend = -minSecsBetweenEmails * 500l;

void setup()
{
  pinMode(7, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop()
{
  long now = millis();
  if (digitalRead(pirPin) == HIGH)
  {
    if (now > (lastSend + minSecsBetweenEmails * 500))
    {
      Serial.println("MOVEMENT");
      lastSend = now;
    }
    else
    {
      Serial.println("Too soon");
    }
  }
  delay(500);
}

now my Serial does not write MOVEMENT or Too soon....

I tried switching the yellow wire of the PIR to the pin where the black wire is... (because I've read that the Sparkfun PIR usually has the middle wire as ground and not as signal......now when I did that it wrote
"MOVEMENT
too soon
too soon
too soon
MOVEMENT
too soon
too soon
too soon
too soon
too soon
too soon
too soon
too soon
too soon
MOVEMENT" and so on... I Unpuggled the entire PIR system again and it read

"MOVEMENT
too soon
too soon
too soon
MOVEMENT
too soon
too soon
too soon
too soon
too soon
too soon
too soon
too soon
too soon
MOVEMENT"

again ....

I did just as you said and the Voltmeter told stated 0.01

... Yes... SOME of the time? It should ALSO, some of the time, have said something near your Vcc. (5v or 3v3, depending on the Arduino you are using.)

If it isn't, then it isn't detecting motion.

tkbyd:
If it isn’t, then it isn’t detecting motion.

I must be doing something really wrong,
the Voltmeter read something from 0.1 to 2.3 … tried with yet ANOTHER sensor and I had the same results… using the 5v on the arduino

Even after all of this, the serial reads as movement detected even when the PIR sensor is not plugged in.

I just simply don’t understand.

The output is digital high or low. You should have the digital input tied to 5v.

Weedpharma

Thanks everyone for your help.
It turns out my sensor wasn't working properly.
I tried with a new one and everything works just fine :slight_smile: