11 Replies Latest reply on Nov 5, 2014 10:58 AM by KC9SDO

    PIR without bread board

    Terrence_

      All examples of using a PIR sensor include a bread board.

       

      I should be able to hook my PIR up to the Edison directly shouldn't I?

      gnd into gnd, power into 5v and output into any of the digital pins on the Edison.

       

      Here is my sketch

       

       

      #include "arduino.h"

      int ledPin = 13;                // choose the pin for the LED
      int inputPin = 2;               // choose the input pin (for PIR sensor)
      int pirState = LOW;             // we start, assuming no motion detected
      int val = 0;                    // variable for reading the pin status

      void setup() {
      pinMode(ledPin, OUTPUT);      // declare LED as output
      pinMode(inputPin, INPUT);     // declare sensor as input
      Serial.begin(9600);
      }


      void loop(){

      val = digitalRead(inputPin);  // read input value
      if (val == HIGH) {            // check if the input is HIGH
        digitalWrite(ledPin, HIGH);  // turn LED ON
        if (pirState == LOW) {
         // we have just turned on
         Serial.println("Motion detected!");
         // We only want to print on the output change, not state
         pirState = HIGH;
        }
      }
      else {
        digitalWrite(ledPin, LOW); // turn LED OFF
        if (pirState == HIGH){
         // we have just turned of
         Serial.println("Motion ended!");
         // We only want to print on the output change, not state
         pirState = LOW;
        }
      }
      }

        • 1. Re: PIR without bread board
          DiegoV_Intel

          Hi Terrence_ ,

           

          I assume you are using the Arduino Expansion Board, is that correct? If that is the case then you can hook your PIR sensor to it. The breadboard is just to make the connections easier.

           

          Regards,

          Diego.

          • 2. Re: PIR without bread board
            Terrence_

            Yes I am using the Arduino Expansion board.

             

            Can't get the PIR to work for some reason.  I had it working on my Galileo board.

            • 3. Re: PIR without bread board
              DiegoV_Intel

              Hi Terrence_,

               

              I've just tried the code you posted and it worked for me. I was able to set my PIR sensor using the Galileo and the Edison on the Arduino Expansion Board. I did just one minor detail changing the #include "arduino.h" to #include "Arduino.h".

               

              Could you explain what is the issue you have? Is it a compiling error, a hardware connection?

               

              Regards,

              Diego.

              • 4. Re: PIR without bread board
                Terrence_

                Well when I debug I am not getting a hit, and the serial monitor is not displaying Motion detected and motion ended.

                 

                It compiles fine, just not getting any motion detection.  I have tried 2 different PIR devices.

                • 5. Re: PIR without bread board
                  DiegoV_Intel

                  It seems to be an issue with the PIR sensor(s). Try setting manually the input pin to HIGH with a jumper wire just to check if the code is correct.

                   

                  In order to know if the PIR sensor is sending a HIGH value, print the variable "val" on the Serial Monitor to see what is its value. Make sure you are connecting the PIR sensor correctly. You can confirm if the PIR sensor is not damaged testing this same sketch on the Galileo Board since you mentioned you had it working on the Galileo board.

                   

                  Regards,

                  Diego.

                  • 6. Re: PIR without bread board
                    KC9SDO

                    You might try using a different digital pin. When I first tried one of the Arduino PIR examples, it used digital pin 2 like your example. Not sure what the difference is but then I gave the XDK Digital Read example a try and it worked using pin 6. Here is the example that I got working.  Good luck on your project.

                     

                    /*

                    A simple node.js application intended to read data from Digital pins on the Intel based development boards such as the Intel(R) Galileo and Edison with Arduino breakout board.

                     

                    MRAA - Low Level Skeleton Library for Communication on GNU/Linux platforms

                    Library in C/C++ to interface with Galileo & other Intel platforms, in a structured and sane API with port nanmes/numbering that match boards & with bindings to javascript & python.

                     

                    Steps for installing MRAA & UPM Library on Intel IoT Platform with IoTDevKit Linux* image

                    Using a ssh client:

                    1. echo "src maa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf

                    2. opkg update

                    3. opkg upgrade

                     

                    Article: https://software.intel.com/en-us/html5/articles/intel-xdk-iot-edition-nodejs-templates

                    */

                     

                    var mraa = require('mraa'); //require mraa

                    console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console

                     

                    var startDt = new Date;

                    console.log(  startDt.toLocaleDateString() + ', ' + startDt.toLocaleTimeString() );

                     

                     

                    var myDigitalPin6 = new mraa.Gpio(6); //setup digital read on Digital pin #6 (D6)

                    myDigitalPin6.dir(mraa.DIR_IN); //set the gpio direction to input

                     

                    var myOnboardLed = new mraa.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Edison Arduino Breakout board)

                    myOnboardLed.dir(mraa.DIR_OUT); //set the gpio direction to output

                    myOnboardLed.write(0);

                     

                    periodicActivity(); //call the periodicActivity function

                     

                    function periodicActivity() //

                    {

                      var myDigitalValue =  myDigitalPin6.read(); //read the digital value of the pin

                      

                      if (myDigitalValue == 1) {

                          var d = new Date();

                          console.log(  d.toLocaleDateString() + ', ' + d.toLocaleTimeString() + ', Gpio is ' + myDigitalValue + '. MOTION DETECTED'); //write the read value out to the console

                      }

                    //  console.log('Gpio is ' + myDigitalValue); //write the read value out to the console

                    //  console.log( d.toISOString() + ', Gpio is ' + myDigitalValue + '. MOTION DETECTED'); //write the read value out to the console

                    //  console.log( d.toISOString() ); //write the read value out to the console

                      

                      myOnboardLed.write(myDigitalValue); //if ledState is true then write a '1' (high) otherwise write a '0' (low)

                      

                      setTimeout(periodicActivity,1000); //call the indicated function after 1 second (1000 milliseconds)

                    }

                    • 7. Re: PIR without bread board
                      Terrence_

                      Thanks Diego, I will give those suggestions a try.

                      • 8. Re: PIR without bread board
                        Terrence_

                        Doug, thanks for the reply.  I tried 2 and 12.  I will keep trying other pins.

                         

                        How do you like XKD?  Do you like it better than arduino?

                        • 9. Re: PIR without bread board
                          Terrence_

                          Diego and Doug, I got it working last night by changing the pin to #8.

                           

                          Thank you for your help.

                          • 10. Re: PIR without bread board
                            DiegoV_Intel

                            Great!

                            • 11. Re: PIR without bread board
                              KC9SDO

                              Terrence, Glad you got it working. The XDK is pretty nice. There were a few issues initially, but starting to work those out. It's nice to connect to the Edison via WiFi to upload programs.