element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
Get Closer Wearables Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Get Closer Wearables Design Challenge
  • More
  • Cancel
Get Closer Wearables Design Challenge
Blog Costume light interaction with LSM303 accelerometer
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: chris.carter
  • Date Created: 8 Sep 2013 1:45 AM Date Created
  • Views 827 views
  • Likes 2 likes
  • Comments 2 comments
  • get_closer_challenge
  • Wearables
  • wearable_tech
  • adafruit
  • arduino
  • get_closer
Related
Recommended

Costume light interaction with LSM303 accelerometer

chris.carter
chris.carter
8 Sep 2013

I want the light in our baby's costome to have a sort of physical property where light drops to the bottom if the baby is lifted up and light rises to the top of the baby's costume if he accelerates down.  This is a little harder than Becky's brake light motorcycle jacket at adafruit because a motorcycle has a relatively constant deceleration over a long distance as the brakes apply force slowing the rider and bike.  When throwing an older toddler/child in the air you can get half a second of acceleration up before you stop applying force and let gravity accelerate them back down.  When you rock a 3mo old you get about three up/down cycles a second.  Each up and each down have an acceleration and deceleration associated with it.  So you can get twelve significant acceleration and deceleration readings per second rocking a baby.  Initially I had envisioned the light sloshing around like water in a bathtub. But the light has to be accurately reactive to the movement but also easy on the eyes.  I sort of solved it by making an exponential relationship between the acceleration and the voltage change sent to the LEDs.  I am open to suggestions if anyone has a better way to approach it.  Code and boring video below.

 

#include <Wire.h>

#include <Adafruit_LSM303.h>

int upLed = 6; 

int downLed = 5;

Adafruit_LSM303 lsm;

 

 

void setup()

{

  Serial.begin(9600);

  pinMode(upLed, OUTPUT);

  pinMode(downLed, OUTPUT);

  // Try to initialise and warn if we couldn't detect the chip

  if (!lsm.begin())

  {

    Serial.println("Oops ... unable to initialize the LSM303. Check your wiring!");

    while (1);

  }

}

 

 

void loop()

{ int maxLight = 0;

  int upAccelerationThreshold = 1050;

  int downAccelerationThreshold = 820;

  int delaytime = 18;

 

  analogWrite(upLed, 50);  //50 is perceptually to me 50% brightness for the LED

  analogWrite(downLed, 50);  //I use 50 as the equilibrium position

  lsm.read();

  int acceleration = (int)lsm.accelData.z;

  //z acceleration seems to hover between 990 and 970

  //fast up acceleration = ~1800

  //fast down acceleration = ~50

  //Serial.print((int)lsm.accelData.z);

  if (acceleration > upAccelerationThreshold)  //upward acceleration

    {

    if(acceleration > 1500){maxLight = 50;} //limit max light to 50

    else{maxLight = (acceleration - 1010) / 9.8;} //max light goes from 0 to 50

    Serial.println(maxLight);

    for(int x = maxLight; x >= 0; x--){

      int upLedStrength = 50 - (x*x)/50;

      int downLedStrength = 50 + (x*x*4.1)/50;

      analogWrite(upLed, upLedStrength);

      analogWrite(downLed, downLedStrength);

      delay(delaytime);

      }

      Serial.println("up equilibrated");

    }

   if (acceleration < downAccelerationThreshold)  //downward acceleration

    {

    if(acceleration < 300){maxLight = 50;} //limit max light to 50

    else{maxLight = (960 - acceleration) / 13.2;} //max light goes from 0 to 50

    Serial.println(maxLight);

    for(int x = maxLight; x >= 0; x--){

      int upLedStrength = 50 + (x*x*4.1)/50;

      int downLedStrength = 50 - (x*x)/50;

      analogWrite(upLed, upLedStrength);

      analogWrite(downLed, downLedStrength);

      delay(delaytime);

      }

      Serial.println("down equilibrated");

    }

   

}

 

 

 

 

Warning:  Boring Video.  The top LED represents LEDs on the top of a costume and the bottom LED represents LEDs on the bottom of a costume. 

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply
  • chris.carter
    chris.carter over 11 years ago

    Leslie,

     

    Thanks for all the encouraging comments.  I am saving my magician's flair for the final costume reveal image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • zengirl2
    zengirl2 over 11 years ago

    Hey, a good magician never walks on stage and says his trick is boring.  There is nothing boring about seeing a computer surrounded by fabric, wires, sensors and LED's -- it's a story that is about to unfold. image  So, I gave this some thought and decided it is kind of like mime. Yes, I actually had some training in this LOL.  You know when a mime does the old "I'm stuck behind glass" peformance?  He first establishes there is a pane of glass with his hands.  Then he pounds on the glass with his hand and shouts as if he is stuck, and finally he is searching the glass to see how big it is until he finally finds a door to walk through.  If he only started his gag with the searching along the wall and finding the door, the visuals would not be as interesting or noticeable.  That is sort of the similar problem I see here.  There is not enough build to get to the change in color from one point to the next.  Is it possible that you can include a final fade until the LED's are off?  Then it would be:

     

    Baby still -  On

    Baby on upswing - starts to fade off

    Baby at hightest point - Off

    Baby on downswing - starts to fade on

    Baby lands - On

     

    Or, it might even be more fun to have it fade to a different color, rather than off.  Maybe it does mom's color when it reaches the highpoint and dad's color when it lands LOL.  It's really funny to think of this in family terms.  Anyway, I really like the direction this is headed.  Ups and downs are fun!

     

    Les

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
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