Monday, December 11, 2017

Instructable: Arduino LED DJ Helmet


  • Wire stripper
  • Drill
  • Paddle bit (3/4 inch)
  • Scissors
  • Razor Knife
  • Tape measure
  • Needle nose pliers
  • Blow Dryer
  • Sharpie

Material / Components:

  • Marshmellow Helmet (includes foaming)
  • Arduino Uno
  • Accelerometer
  • LED light strip
  • Jumper wires
  • Switch
  • Scotch Double sided tape
  • 26 guage wire
  • Stakon wire terminals
  • Heat shrink
  • Scotch Clear Tape
  • Scotch Blue Tape
  • Black Cloth
  • Breadboard
  • 2 Resistors
  • 9v Battery
  • Battery Connector for Arduino
  • USB Hook up for Arduino
  • Computer
  • Arduino Software

STEP 1 Testing:

Before you actually start, it is a good idea to test your LED and Accelerometer and make sure they are working.

To test and possibly calibrate the accelerometer use this tutorial.

Once you see that your accelerometer works, use this tutorial to test your LED.

STEP 2 Coding:

For this project, I combined coding from Adafruit Neopixel Strandtest (which can be downloaded here ) and code from this wonderful blog post (which can be found here ).

This is the code that I eventually stuck with, however, you can edit the code any way you like with whatever effects you'd like.

This is R. Godwin's mash up or MPU6050_raw and the strand test for neopixels.


 //Start the MPU_6050 important junk

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
//MPU6050 accelgyro(0x69); // <-- use for AD0 high

int16_t ax, ay, az;
int16_t gx, gy, gz;

// uncomment "OUTPUT_READABLE_ACCELGYRO" if you want to see a tab-separated
// list of the accel X/Y/Z and then gyro X/Y/Z values in decimal. Easy to read,
// not so easy to parse, and slow(er) over UART.

//END the MPU_6050 important junk

//Start Neopixel junk

#define LED_PIN 13
bool blinkState = false;

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

//End Neopixel junk

void setup() {
//MPU_6050 setup

// join I2C bus (I2Cdev library doesn't do this automatically)
        Fastwire::setup(400, true);

    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)

    // initialize device
    Serial.println("Initializing I2C devices...");

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

  // configure Arduino LED pin for output
    pinMode(LED_PIN, OUTPUT);
//End MPU_6050 setup

  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  // End of trinket special code

  strip.begin();; // Initialize all pixels to 'off'

void loop() {
   // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

    // these methods (and a few others) are also available
    //accelgyro.getAcceleration(&ax, &ay, &az);
    //accelgyro.getRotation(&gx, &gy, &gz);

        // display tab-separated accel/gyro x/y/z values
        Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("/t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");

 int redVal = ax;
 int grnVal = ay;
 int bluVal = az;

redVal = map(redVal,0,20000,0,255);
grnVal = map(grnVal,0,20000,0,255);
bluVal= map(bluVal,0,20000,0,255);

gx = map(gx,0,20000,0,255);
gy = map(gy,0,20000,0,255);
gz = map(gz,0,20000,0,255);

    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);

//  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(gx, gy, gz), 5); // g vals
//  colorWipe(strip.Color(0, 255, 0), 50); // Green
//  colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(redVal, grnVal, bluVal), 3); // White RGBW
  // Send a theater pixel chase in...
  theaterChase(strip.Color(redVal, grnVal, bluVal), 40); // accelormeter vals
//  theaterChase(strip.Color(127, 0, 0), 50); // Red
//  theaterChase(strip.Color(0, 0, 127), 50); // Blue
 // rainbow(20);
//  rainbowCycle(20);
 //   theaterChaseRainbow(40);

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);;

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*2; j++) { // 2 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<20; j++) {  //do 20 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on


      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on


      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);

STEP 3 Wire it up!: 

(This project/step assumes you soldered your accelerometer already.)

This is a lot of wiring, so I put the wiring into steps using Fritzing. Each image is an extension to the next, but does not have the previous step. Continue through the images as though they were all the same. I did not move the resistors to leave a reference.

This last image is how it should look (except for one wire running from INT on accelerometer to 2 on Arduino) with extending wire (the yellow black and blue wires running off the breadboard) that leads to LED strip.


This is my actual wiring.

STEP 4 Putting it all inside / Switch first:

Using Drill, Paddle Bit (3/4 inch is what worked for the switch I bought) and switch choose where you would like to place the switch. Keep in mind it will need to be reached while the helmet is on.

Drill hole in helmet and push switch through hole, try to keep it straight before you push it through because if it is snug it won't want to twist while it's in the helmet.

Cut one of the two wires of the battery connector and add wire to both ends of the wire you cut (I had 26 gauge wire handy, so that's what I used). Insulate and secure splice using heat shrink and a heat gun or blowdryer to heat it up.

Use Stakons to connect wires to switch. This is used for a snug fit and is less likely to come loose.

Plug in 9V battery to arduino and test switch out.


Use the scotch double sided tape and wrap it around the inside of the helmet where you want to put your LED strip. Measure everything out! This can be a pain because the tape can lose it's stickiness if you touch it too much. Run LED strip around the helmet pressing hard on the strip to make it stick well to tape.

Trim LED strip. I also added tape to keep the wires flush with the sides of the helmet.

STEP 6 Mounting:

Mount the breadboard, battery, and the Arduino in the middle of the helmet with scotch double stick tape making sure not to put them in the way of where the foam inside will sit. The breadboard I used already had a sticky backing, so I didn't add the tape to that, but I did for the Arduino and battery.

STEP 7 Cut it up!:

When I bought the helmet, the foam inside was too thick and made visibility almost impossible, so I cut the foam in half with scissors.

Next I realized that the helmet was too wobbly to stay on your head without some sort of support, so I cut the other half a little shorter to stop before it got to the black visor.
I also cut a black piece of cloth about 12" x 12" and put it between the two halves of the foam to help protect and also hide the wiring. 
I did not attach the cloth in any way other than tucking it between the bottom half and the sides of the helmet. I wanted the cloth to be removable in order to get to the wiring and to change out the battery in the future. 

STEP 7 Try it on!:

The code takes a few seconds to start up, so give it some time and enjoy!

Saturday, December 2, 2017

Arduino Accelerometer Testing Code:

 // MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
void loop(){
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers<<8|;  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)<<8|;  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)<<8|;  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)<<8|;  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)<<8|;  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)<<8|;  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)<<8|;  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);

Wednesday, November 29, 2017

Week 13 Reflection

Day 1:

    • The MPU-6050 from Invensense (full disclosure: I'm not affiliated with Invensense in any way) contains a three-axis accelerometer and three-axis gyroscope which respectively measure acceleration on and rate of rotation about three orthogonal axes. This brings your total variables in the system (or "degrees of freedom", if you prefer) to six. More degrees can be added with an additional GPS, real-time clock, barometer, magnetometer, or other spacial/inertial sensing device. Each additional degree of freedom increases the potential accuracy of the IMU, assuming the algorithms that read the sensors utilize the data effectively. Both the accelerometer and gyroscope in the MPU-6050 are made with MEMS technology which means they rely on the physical deflection of microscopic structures made out of silicon. 
        • Read up on MPU and what it does to understand how everything will work. 
        • studied the code on this website as well (link at bottom)
        • Found image of how to hook up the hardware:

      • As the IMU rotates about the yaw (Z) axis, a white indicator will point to the current heading. At straight and level operation (pitch and roll values are approximately zero) a "Great Circle" can be drawn around the green equator of the sphere, concentric to the line traced by the yaw heading indicator. If the roll (X) or pitch (Y) values go negative over their respective axes, the LED's corresponding to the "nose" and port (left) side will go from green to red while the "tail" and starboard (right) side LED's will go from green to blue. The opposite will happen if the pitch or roll values go positive. That Great Circle can then be visualized as tilting around the sphere, and wherever the circle touches are the colors of the LED's on the strip.
    • Also soldered MPU.

Wednesday, November 15, 2017

Week 12 Reflection

First day:


Second day:

Natural Born Cyborgs reading of chapter 6 and 7 review.

Chapter 6 & 7:
a lot of the chapter was dated because it is 15 years old, but it was still talking about things that are relevant and some of the things it talked about such as the "black box" idea in cars exists today.
It also talked about advertisements and how they suggest different things to us and whether or not that is useful.
 Also talked and skimmed through chapter 7, which was basically a more broken down and more explaining of the previous chapter with a few other added things. We also had brought up a few things that were in chapter 7 that we had thought of while looking over chapter 6.

Wednesday, November 8, 2017

Week 11 Relfection Post

Day 1:

Talked about natural born cyborgs

Notes on Relay Lab -- Fixed Relay lab.

Day 2:

Made new list. See post below


LEDS Strips with waterproof coating:


Mini Arduino (optional, but probably going to need):




Battery: ???? Have to figure out how much power I'm going to need

Things to think about:

Code: what do I want the lights to do?

Where am I going to store the electronics?

Helpful links?

accelerometer arduino led strips Image search google

Instructable: Arduino LED DJ Helmet

Tools: Wire stripper Drill Paddle bit (3/4 inch) Scissors Razor Knife Tape measure Needle nose pliers Blow Dryer Sharpie ...