You are here: Home Documentation How-tos Make a Wireless Motion Detector
Document Actions

Make a Wireless Motion Detector


This How-to is intended for: Electronics Hackers, Desktop Developers

Create a remote motion detector with the Make Controller and a pair of XBee modules.

Problem

You'd like a wireless sensor to detect motion and report it back to the Make Controller, and possibly back to your computer.

 

Solution

Using a pair of XBee modules and a PIR sensor, we'll monitor our front door to see when there's some activity there.  In order to use the XBee modules, you'll want to check out the XBee tutorial here.  We'll go over the basics here, but that will provide more detailed info on all things XBee. 

So, we have a few things we'll need:

  • a Make Controller (no surprise here, hopefully)
  • 2 XBee modules (assembled as per the instructions in the XBee tutorial)
  • a battery pack (or other power source) for the XBee modules
  • a PIR sensor (or other motion detector)

Everything We Need
Everything we'll need.

So, once we have all our pieces we'll need to configure and connect them. 

Make Controller Kit

Be sure to have the latest firmware (at least Heavy v1.3.0) on your Make Controller so you have all the XBee stuff on there.  I'm going to set it up to autosend any xbee messages that come back, up to my computer over USB - note we only need to do this once.  To do this, open up mchelper and send the messages:

  • /system/autosend-usb 1
    This tells the autosend messages to go over USB, as opposed to Ethernet
  • /system/autosend-interval 10
    This says, "send me new messages (if there are any) every 10 milliseconds"
  • /xbee/autosend 1
    Turn XBee autosending on - you may want to turn other systems autosend (like the analogins) off, but it doesn't matter too much.

Check for more details on setting your board up to automatically send messages.

 

XBee Modules

This how-to assumes that you've already assembled your XBee modules, as described in the XBee tutorial.  What we need to do now is set them up to read the PIR sensor and send those values back automatically to our Make Controller.  One module - the one that will be receiving messages - just needs the 6-position header connected to it so we can plug it into our Make Controller.  The other one needs to have the XBee connector pack installed so we can plug the battery and sensor into it.

You'll also need to grab a battery pack.  I'm using one from Radio Shack that holds a pair of AA batteries.

Battery Pack
AA battery pack with headers on the leads.

XBee w/ Battery Pack
Battery pack plugged into V+ and GND on XBee module.

Once you have the transmitter module assembled, we need to plug it into the Make Controller to configure it.  Open up mchelper, plug your Make Controller into your computer and send the following commands to your board:

  • /xbeeconfig/packet-mode 1
    This makes sure the module is in a mode where it can respond to our config messages.
  • /xbeeconfig/io0 3
    This sets IO pin 0 to being a digital input - note we'll need to plug our sensor into AD0.
  • /xbeeconfig/atcommand SP 100
    This makes use of one of the really cool features of the XBee modules.  The XBee modules can be set in a mode where they sleep for a given amount of time, wake up & take a sample of their input pins, send a message with the sample info, and then go back to sleep.  Staying asleep as long as possible will increase the module's battery life a TON.

    The SP command sets how long to sleep before waking up and taking a sample.  The SP value is multiplied on the XBee module by 10, so we've set it to wake up once a second.
  • /xbeeconfig/at-command ST 5
    The ST (Time to Sleep) command sets how long the module will wait before going back to sleep once its been woken up.  We don't want it to wait around too long, so we'll set it to 5 milliseconds
  • /xbeeconfig/at-command SM 5
    SM is the sleep mode command - it tells the module to actually go to sleep and wake up according to the SP and ST settings.  You'll notice when it's in sleep mode it won't respond to any further commands.

Sleep Mode

Now, if you leave the module like this it will stay in sleep mode 5 until it gets rebooted, at which point it will revert to sleep mode 0 and start sucking lots of battery power again. 

If you want to set the module to always be in sleep mode, through resets and all, you'll have to send it the write message after setting the sleep mode.  However, you have a limited amount of time to do this - the module will only wait as long as the ST setting before actually going to sleep after receiving the sleep mode command.  Since ST is only 5 milliseonds, this is pretty tough, so we'll use the write-command option to set the sleep mode.  This internally sends an /xbeeconfig/write 1 command immediately after whatever you ask it to send. 

/xbeeconfig/write-command SM 5

Getting Out of Sleep Mode

If you haven't saved the board's settings after setting the sleep mode, all you need to do is plug and unplug the board, or set the RESET line to GND.  If you have saved it, it's a little tricky.  It's a bit hacky, but I've had the best luck firing the SM 0 command at the board several times repeatedly via mchelper.

 

PIR Sensor

We just need to plug the PIR sensor into AD0 on our XBee module.  I've soldered single header pins on the end of the leads of the PIR sensor so they're easier to plug into the sockets on the XBee board.  The connections should be made as follows:

  • Red lead from the PIR sensor into one of the V+ pads
  • Black lead to a GND pad
  • Yellow lead to the AD0 pad (or any other input, if you've modified these instructions along the way)

XBee w/PIR plugged in
The PIR sensor connected to V+, GND and AD0

 

Reading

Alright!  Now we're all set up and should be receiving /xbee/io16 messages back in mchelper.  If you don't see these popping up about once a second, something has gone wrong.  A sample message will look like

/xbee/io16 0 29 1023 0 0 0 0 0 0 0 0

The first 0 is the address of the module it came from and the 29 is the signal strength.  The next 9 values are the inputs on the XBee module - 1023 is the value of our PIR sensor, since we connected it to the first input on the XBee module.  So now when we see that 1023 we know there's some motion at our front door!

 

Discussion

With just a little modification to the Heavy firmware, you could set your Make Controller up to take some response itself when it sees the PIR sensor has been triggered, instead of sending an OSC message.

Or, you can connect the Make Controller to the software environment of your choice and trigger an action in there. Check the following tutorials for info on how to get set up in a variety of software environments: