Main Site Documentation

PIR Module motion detection firing randomly!


#1

Hi,

I have a FEZ Spider mainboard and a PIR Motion tracker module (http://www.ghielectronics.com/catalog/product/357) attached to it.

What im trying to do, is to place it in a quiet room - and when i walk in to it - i want it to respond to that event.

When i run it, the event and the event handler below seems to fire randomly (like it doesnt matter if i stand in front of it and make movements).

void motion_Sensor_Motion_Sensed(Motion_Sensor sender, Motion_Sensor.Motion_SensorState state)
{
Debug.Print(“Motion sensed”);
}

I have tried to adjust the two screws on the module, as described here for time delay and distance (http://www.elecfreaks.com/398.html) but i cant really make it fire the event when a human enters the room (it just fires randomly it seems)

I have attached some images of the sensor.

Is it faulty hardware? Does anyone know how to best adjust it? :slight_smile:

/Anders


#2

@ andypanda - Welcome to the forum :slight_smile:

There have been a few threads on this issue with no definitive answer.

After it fires does it fire at a constant rate - say every 6 seconds?


#3

Hi Andypanda and welcome to the community.
I have two different PIR modules and one fires every 6 seconds but on a different mainboard (cerberus) and works fine on the spider but the other one works fine with both. Very strange and i havent got to the bottom of it.
I presuime you have tried different sockets etc.
If you do a search of the forum you will find lots of references to similar problems. There has to be a simple reason but im stumped if i can find it.


#4

@ Justin - yes, its like almost every 6 seconds randomly… sometimes 4-5 and sometimes 7-8 seconds…


#5

@ HughB and than you :slight_smile: - Ive tried with all sockets available for the module…but still the same behaviour… Im gonna look more around for answers in the forum… but it looks like my solution would be to buy another one?


#6

@ andypanda - what i have done in a project is create my own driver.
all it is is an interrupt on pin 3. When if fires i immediately disable the interrupt pin, do the code it runs, wait a bit then enable the interrupt on the pin.
seems to do the trick…


#7

@ Justin - that sounds awesome - but I have no idea how to do it!

Do you have some code you could share with me? :slight_smile:


#8

@ andypanda - more than happy to, but i only have my phone at the moment as i left lappie at the office…
So unless one of the other rocket scientists posts some code i cant help for another 12 hours or so…


#9

@ Justin - lol, thats cool - I can wait for that :slight_smile: Thanks!


#10

@ Justin - Did you have that code driver for the motion detection?

That would really help me out :slight_smile:


#11

@ andypanda - Sorry - forgot all about it…

Just hooked up a Spider with a PIR on socket 5 and tested the below ok - no random firing…

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.Interfaces;

namespace SpiderPirTest
{
    public partial class Program
    {
        private static Microsoft.SPOT.Hardware.InterruptPort _pirPin;

        void ProgramStarted()
        {
            GT.Socket socketPir = GT.Socket.GetSocket(5, true, null, null);
            _pirPin = new InterruptPort(socketPir.CpuPins[3], true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            _pirPin.OnInterrupt += new NativeEventHandler(pirPin_OnInterrupt);
        }
        void pirPin_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            _pirPin.DisableInterrupt();
            Debug.Print("Motion at: " + DateTime.Now.ToString());
            Thread.Sleep(10000);
            _pirPin.EnableInterrupt();
        }
    }
}

#12

@ Justin - the code you sent me… and this is probably a silly question, (but here it goes)

Will “pirPin_OnInterrupt” event fire every time there is an interruption (and not a motion)?

How can i detect a motion with this code?


#13

@ andypanda - motion will cause the interrupt to fire.


#14

@ Justin - okay - when i run your code (without your timeout) it fires like before… every 6 seconds…

Maybe its not my pin3 that causes the error? it has a value of 23, whatever that means…! :slight_smile:


#15

@ andypanda - have you taken out the thread sleep?
that is just to mimic some operation and to allow the pir to settle.
taking it out will cause the 6 sec issue to continue


#16

@ andypanda - 23 will be the cpu pin id i guess…


#17

@ Justin - When i run my code; I usually run InitializeModules() and initialize the motion sensor.

First i new up the motion sensor:
motion_Sensor = new GTM.GHIElectronics.Motion_Sensor(5);

and then i hook up the motion sensed event:
motion_Sensor.Motion_Sensed += new Motion_Sensor.Motion_SensorEventHandler(motion_Sensor_Motion_Sensed);

Where should i run your code, after this? Or should i skip it?

I dont get the part how to use your code as a driver… :confused:


#18

@ andypanda - its not a designer driver, use as is and don’t add the pir to the designer


#19

@ Justin - running your code gives me this output:

Motion at: 06/01/2011 00:03:51
Motion at: 06/01/2011 00:04:10
Motion at: 06/01/2011 00:04:30
Motion at: 06/01/2011 00:04:45
Motion at: 06/01/2011 00:05:11
Motion at: 06/01/2011 00:05:24
Motion at: 06/01/2011 00:05:36
Motion at: 06/01/2011 00:05:48
Motion at: 06/01/2011 00:06:00
…
…
.

So as i understand it:

  • It still fires randomly like before
  • The only difference is that it happens less often because of the thread sleep?

I dont quite get how i can detect motions with your code, to me it stills seems random.

(And thank you so much for your help so far - and sorry if im slow in getting this!!)

/A


#20

@ andypanda - when the module detects motion/heat it pulls the pin high which causes the interrupt to fire.

how are you testing it, are you walking into the room or just sitting there twiddling your thumbs?