Final Project- Motion Sensor Tie

 

ALS_Blog_LogoMotion Sensor Tie

what is this project? This is a project that involve 2 bracelet and 2 persons team project. One part of the project is design as the input and the other part of the bracelet is output.My original design of the project is one person wearing bracelet on their arm, has an Adafruit flora, a motion sensor (flora accelerometer) and jumper wire and the other person arm would have led light, however we change it led light will be put inside of a tie and glove will have inside the accelerometer and the flora mainboard. When one teammate with the motion sensor tilt his/her arm(glove), the other teammate would wear a tie that would be output for led light display.

This project is a different for various reason first the name is different, second the older project was bracelets and they use processor. We use a glove and inserted the accelerometer and flora atmega and put RGB led light inside of a tie. The original project the designer use processor and code to make the led light go around in a circle however in my project the led light is program to random and we are only using arduino software.

Material needed

jumper wire red,yellow and black, wire stripper, wire cutterusb cable, a tie and glove (any of your choice), a hot gun, tape, a knife (look at collage below for more details and visual image)

  • Microcontroller/main device

Adafruit flora v1.0a with Atmega32u4 chip (micro processor)  

  • Input devices                                                                  

Adaruit Flora accelerometer/compass sensor   version lsm 303 DLHC

  • Output device

Adafruit Flora RGB NeoPixel v2 in this project use only 6

project name is formally known as motion light sensor change to Motion Sensor Tie

unnamed (1)

3D paper image of the project                         Project  develop that we was going to use:

  unnamed                     download bracelet

we change our project to a tie and glove presentation because we ran out of time to purchase two bracelets.

Testing the adafruit flora mainboard and adafruit flora RGB Neo Pixel v2  and Adaruit Flora accelerometer/compass sensor using alligator cables. The adafruit floara neo pixel is very bright

Step 1: Research details on materials to develop this project

Adafruit flora1.0a Atmega32u4 chip is similar to arduino uno but it is designed as wearable electronics platform and small enough to put anywhere for creative interactions. The device use microprocessor called Atmega32u4. Flora is 1.75 diameter.Flora mainboard is the main piece of the puzzle to make this project come to life. It has large pads to connect premium stainless steel thread. The pad are layout to make it easy to connect flora various components like sensors, ultimate gps, motion sensor (accelerometer/compass), flora light sensor ir+visible lux sensor or flora led neopixel. Flora has built in usb HID support and can act act like a keyboard or mouse. Flora is perfect for designing your own expressive and functional electronic fashion Arduino software v1.0.5 has included flora driver, libraries and examples. This version of flora use mini b connector.

flora_pinout     

   Quick Breakdown

small reset button to reset the system

one side of the board is used for input like for example the accelerometer (type of sensor) will go onto the side label scl/sda/gnd/3.3v/

the other label 3.3v/d10/d6/d9 use for output like the flora RGB neopixel (type of actuator)

Ground (no power). there is 2 GNDs for a reason

Simple connector last PWM  SCI (clockline) is the i2c clock pin – its required to talk to the acelerometer
Pulse Width Modulation (PWM) rapidly change the output pin high to low over fixed period of time depending on how the code is design.On flora main board D9, D10, D6 are pwn pins

Digital pins is use for connection of the flora RGB neopixel

Serial data analyzer SDA (data line) is the i2c data pin – its required to talk to the accelerometer

Scl and sda are like brother and sister. It is used to communicate with 12c/ two wire interface (twi) device like for example lcd screens

Rx and Tx- Recieve data and Transfer data to serial monitor using code

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  
  Serial.println("Hello world!");  // prints hello with ending line break 
}

3.3 volt: pulls current of 100mA max to the board

Vbatt: is used when you want to power something like Neopixels or a servo, a device that require more than the 150mA available from the on board regular.

flora is mainly powered through jst connector (usb connection). JST input (button) (on&off switch) is polarity protected. Vbatt control by using data Rx and Tx for motion sensors different type of control of power. Do not use vbatt as an input because it might damage your battery if you also plug in the usb connector to a computer.

Important note for beginner

It is difficult to destroy the Adafruit flora v1.0a (Atmega32u4) by connecting a battery backward polarized connectors and protection diodes. The power supply designed to be flexible. flora is fabric friendly. There is 2 on board japan solder less terminal connectors with protection diodes for the external battery packs from 3.5v to 9v DC. It can run on 3v but 3.5v-5v or higher if you trying to add something more powerful. In addition, can use Lilon/LiPoly, LiFe, Alkaline or rechargeable NiMh/NiCad batteries of any size. for more information visit https://learn.adafruit.com/getting-started-with-flora/overview

Definitions: Japan solder less terminal (jst) battery connector is white electrical connectors mounted onto the printed circuit board (pcb) (flora).

polarized:restrict the vibration of transverse wave or partially to one direction

The accelerometer and flora mainboard has a 12C (sda/scl) interface it is also known as 12c bus used to interact with real-time clocks, digital potentiometers, temperature sensors, digital compasses, memory chips, FM radio circuits, I/O expanders, LCD controllers, amplifiers

on arduino uno the 12C Bus is analogs A4(SDA) and A5(SCL)

Please note: must download the drivers and specific libraries. when first plug in the flora mainboard make sure serial port and board is adafruit flora is correct. 

download the arduino ide v1.05 software with flora installed not the new verizon v1.06 why? Because it does not have flora board installed.
https://learn.adafruit.com/getting-started-with-flora/download-software

analysis this pdf for steps to install driver because for windows the serial port would not work properly unless the driver was installed correctly
https://learn.adafruit.com/downloads/pdf/getting-started-with-flora.pdf

steps to install a library on windows, mac, linux
https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use/installing-a-library

websites to download the libraries
adafruit accelerometer
https://learn.adafruit.com/flora-accelerometer/programming
https://github.com/adafruit/Adafruit_LSM303
adafruit neopixel
https://github.com/adafruit/Adafruit_NeoPixel

In addition when plug in mini usb the circuit will light up green. Before uploading any code whether it manually structured or an example from arduino built in verify for any error in the code then upload to the code to the board. When the code upload the board when light up red and will see Transfer data (Tx) and recieve (Rx) data light flicker on.

For insurance that the adafruit flora mainboard working properly input the code into arduino software and plug in the flora check the serial port and board is correct then upload the program to flora. you should see on board blinking led.

  1. // Pin D7 has an LED connected on FLORA .
  2. // give it a name:
  3. int led = 7;
  4.  
  5. // the setup routine runs once when you press reset:
  6. void setup() {
  7. // initialize the digital pin as an output.
  8. pinMode(led, OUTPUT);
  9. }
  10.  
  11. // the loop routine runs over and over again forever:
  12. void loop() {
  13. digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
  14. delay(1000); // wait for a second
  15. digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
  16. delay(1000); // wait for a second
  17. }

 

6 standtest to test flora neopixel

Step 2: connection and layout

unnamed

Adafruit flora mainboard connect to adaruit flora accelerometer/compass sensor 4 connections

mainboard (GND) jumper wire connect to accelerometer (GND)

mainboard (scl) jumper wire connect to accelerometer (scl)

mainboard (sda) jumper wire connect to accelerometer (sda)

mainboard (3.3v) jumper wire connect to accelerometer (3.3v)

Adafruit flora mainboard connect to adaruit flora RGB Neo Pixel v2 3 connections

Adafruit flora mainboard (Vbatt) jumper wire connect to flora RGB Neo (+)

Adafruit flora mainboard (D6) jumper wire connect to flora RGB Neo (arrow pointing toward led light)

Adafruit flora mainboard (GND) jumper wire connect to flora RGB Neo(bottom of led light)

wire connection

Red wire for power (+)

Black wire for Ground (gnd)( – )

Yellow wire for signal (–>)

Adaruit flora RGB Neo Pixel v2 3 connections

PLEASE NOTE: connection the RGB Neo led lights depend on how many led you will be using for your project. For more infomation visit  https://learn.adafruit.com/flora-pixel-brooch/overview.The diagram below good exampleflora_PB282306

 Step 3: The code, toubleshooting & debug=successful project

key note the code has to match with the circuit. for example: on the flora you connect the flora RGB led lights to D6 then in the code it has to be D6. move_thershold number was change because the higher the higher the number the lower the sensitivity in the accelerometer.

  • Motion Sensor Tie code

#include <Wire.h>                              //library to connect TWI/12c like sda/scl on the board
#include <Adafruit_LSM303.h>      //library for accelerometer/motion sensor
#include <Adafruit_NeoPixel.h>     //library for flora neopixel

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, 12, NEO_GRB + NEO_KHZ800);

//set neopixel to D12 on the flora mainboard
Adafruit_LSM303 lsm;

// Here is where you can put in your favorite colors that will appear!
// just add new {nnn, nnn, nnn}, lines. They will be picked out randomly
//R    G    B
unit8_t myFavoriteColors[][3] = {{200, 0, 200}, // purple
{200, 0, 0}, // red
{200, 200, 200}, // white
{ 0, 200, 0}, // green
{ 0, 0, 200}, // blue
};
// don’t edit the line below
#define FAVCOLORS sizeof(myFavoriteColors) / 3

// mess with this number to adjust TWINklitude 🙂
// lower number = more sensitive
#define MOVE_THRESHOLD 45

void setup()                          //set up the program to do specific action
{
Serial.begin(9600);           //command serial monitor to activate

// Try to initialize and warn if we couldn’t detect the chip
if (!lsm.begin())                    //if library is detect start serial monitor
{
Serial.println(“Oops … unable to initialize the LSM303. Check your wiring!”);
while (1);                //if library not detected go to turn off strips
}
strip.begin();         //
strip.show(); // Initialize all pixels to ‘off’
}

void loop()                    //if the accelerometer library is detected continue on to void loop
{
// Take a reading of accellerometer data
lsm.read();
Serial.print(“Accel X: “); Serial.print(lsm.accelData.x); Serial.print(” “);
Serial.print(“Y: “); Serial.print(lsm.accelData.y); Serial.print(” “);
Serial.print(“Z: “); Serial.print(lsm.accelData.z); Serial.print(” “);

// Get the magnitude (length) of the 3 axis vector
// http://en.wikipedia.org/wiki/Euclidean_vector#Length
double storedVector = lsm.accelData.x*lsm.accelData.x;
storedVector += lsm.accelData.y*lsm.accelData.y;
storedVector += lsm.accelData.z*lsm.accelData.z;
storedVector = sqrt(storedVector);
Serial.print(“Len: “); Serial.println(storedVector);

// wait a bit
delay(100);

// get new data!
lsm.read();                  //Retrieve Rx and Transfer new data
double newVector = lsm.accelData.x*lsm.accelData.x;
newVector += lsm.accelData.y*lsm.accelData.y;
newVector += lsm.accelData.z*lsm.accelData.z;
newVector = sqrt(newVector);
Serial.print(“New Len: “); Serial.println(newVector);

// are we moving
if (abs(newVector – storedVector) > MOVE_THRESHOLD) {
Serial.println(“Twinkle!”);
flashRandom(5, 1); // first number is ‘wait’ delay, shorter num == shorter twinkle
flashRandom(5, 3); // second number is how many neopixels to simultaneously light up
flashRandom(5, 2);
}
}

void flashRandom(int wait, uint8_t howmany) {

for(uint16_t i=0; i<howmany; i++) {
// pick a random favorite color!
int c = random(FAVCOLORS);              //different variable for different colors
int red = myFavoriteColors[c][0];
int green = myFavoriteColors[c][1];
int blue = myFavoriteColors[c][2];

// get a random pixel from the list
int j = random(strip.numPixels());
//Serial.print(“Lighting up “); Serial.println(j);

// now we will ‘fade’ it in 5 steps
for (int x=0; x < 5; x++) {
int r = red * (x+1); r /= 5;
int g = green * (x+1); g /= 5;
int b = blue * (x+1); b /= 5;

strip.setPixelColor(j, strip.Color(r, g, b));
strip.show();
delay(wait);
}
// & fade out in 5 steps
for (int x=5; x >= 0; x–) {            //set the direction of digital pins
int r = red * x; r /= 5;
int g = green * x; g /= 5;
int b = blue * x; b /= 5;

strip.setPixelColor(j, strip.Color(r, g, b));
strip.show();
delay(wait);
}
}
// LEDs will be off when done (they are faded to 0)
}

Once code is upload to flora and the device is properly connected. Open the serial monitor to see accelerometer working with movement. Also in the code it is program to send signal to serial monitor.

accelerometer_test

Issue and troubleshooting why?

I wanted to connected six RGB LED light and the code wasn’t working. me and my team partner decide to take apart the project and start over just to make sure the connection is secure first and then work on the code.

When I connected all six neopixels together and tested on a strand test they all worked fine. When switched to the code that uses the accelorometer only two pixels light up. When I checked the volts they were all working fine. They worked according to the strandtest. So I took off two NeoPixels making it down to four and the strand test worked.

I wanted to connected six RGB LED light and the code wasn’t working. me and my team partner decide to take apart the project and start over just to make sure the connection is secure first and then work on the code.

me and my team partner had  a weak connection when we decide to strip the jumper wire and tie them to the components. it show that it was a shortage in the pixels communication.

Multimeter Testing:

To check for power,  I set meter to 20 volts DC. [EXPLAIN HOW I CHECKED CONTINUITY FROM POINT TO POINT.] [FOR SIGNAL CHECKED FROM PIXEL TO PIXEL. FOR GND AND POWER CHECKED FROM FLORA TO PIXEL]

all issue was resolve when we soldered all components. It is a very secure connection. Further analysis the code to make sure it match the connection and as a result it was a successful project.

New project have red glove with flora mainboard and accelerometer hot gun with tape

The tie has 6 flora neopixel hot gun in with tape and red,yellow and black jumper wire soldered on to maintain great connection no shortage.

unnamed (1)

fun fact section

The software and devices is compatible with Mac, Linux and windows

For different connections can also use conductive fabric, conductive paint, alligator clips

For different type of micro controller boards similar to Arduino and Flora there is mainboard called lilypad, gemma and trinket

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s