element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Nico teWinkel's Blog Motion Detector
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ntewinkel
  • Date Created: 28 Aug 2011 1:10 AM Date Created
  • Views 190 views
  • Likes 1 like
  • Comments 0 comments
  • xl_star
  • motion_detector
  • accelerometer
  • summer_of_design
Related
Recommended

Motion Detector

ntewinkel
ntewinkel
28 Aug 2011

Part of my crazy countdown timer is that I want to detect if someone is moving it, so I need to work with the accelerometer.

 

So I created a new app and made it tic-toc between 2 spokes on the star LEDs. This is mainly to show that the app is still running, in case it hangs or something. It helps when debugging. This part was a continuation of the basic_led sample I had earlier, and simply turns on more LEDs.

 

Then I copied the accelerometer code from the demo, and pruned it as much as possible to take out all the modes and options that I don't want. I left it detecting just motion of any sort. At first it was a little (a lot) too sensitive - knocking lightly on the counter top beside it set it off. So I added a #define named "SENSITIVITY" at the top of the file to adjust sensitivity easily. Now it takes a drop of from about 5 mm to set it off (lifting just the far side of the board, opposite the star LEDs), or a shake.

 

I added some code to make the whole star flash when motion was detected, and it seems to all work quite nicely.

 

Attached is the code. You don't need anything more than the XL_star board to run this demo.

As usual, create a new project from scratch (following the docs), then replace the content of main.c with the content of the attached file.

Then you'll need to copy iic.c, iic.h, and mma845x.h from the demo into the source folder of your new project.

Then back in CodeWarrior right-click on sources and "add files" and choose iic.c from your project folder.

 

Build it and run it, and you'll see it alternate between lighting up one spoke, then the next, then back to the first.

If you move the board too much, the whole star will flash (ie, motion was detected).

 

Enjoy image

Attachments:
main_motion_detector.c.zip
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube