Making Things Interactive

March 5, 2008

Mid-term Project: Mood Cube

Filed under: 7: Mid-Term Project,Assignments,Christopher Bridgman — cbridgma @ 10:29 pm

So here is my finished Mid-term project as per my innitial proposal. The challenge in creating this mood light was using the accelerometer and getting the arduino to read all 3 inputs at one given time to achieve a desired output. The cube responds to motion through the use of the accelerometer. For this light, using a digital read of the accelerometer sufficed to measure the position of the cube in respect to an initial position. As the sensor readings changed, I programed the arduino to change the color of the lights so a specific set of values would equal a certain color in the cube, ie. 1,1,1 = white. The cube is pretty sensitive to movement, a tap can get it to change colors, due to a very short delay. Any longer delay seemed to make the cube go buggy and disco like. With the short delay, it was able to stay a constant color while in the static position. It is not very clear in the video, due to poor camera resolution, but the color progression goes from off to white, red, purple (red and blue), blue, orange, and back to off.

Pictures:  mood cube blue_red    mood cube blue

Here is the final circuit diagram:   Mood Cube Schematic

Parts List:

Arduino Microcontroller

Blue LED’s x4

Ultra Bright White LED’s x4

Red LED’s x4

Orange LED’s x4

TIP120/TIP3055 Transistor or equal x4

4″x4″ Plexiglass Pieces for outer cube

ADXL 3030 3 Axis Accelerometer

9 Volt External Power

100 Kohm Resistors x4 for LED’s

1 Kohm Resistors for TIP120 Transistors.

 Here is the code. Notice the use of the ‘&&’ to read all 3 inputs from the accelerometer at one time.


int statusPin = 13;                // LED connected to digital pin 13
int xPin = 9;                      // X input from accelerometer
int yPin = 10;                     // Y input from accelerometer
int zPin = 11;                     // Z input from accelerometer
int redPin = 6;                    // Red LED's connected to pin 6
int orangePin = 7;                 // Orange LED's connected to pin 7
int bluePin = 5;                   // Blue LED's connected to pin 5
int whitePin = 3;                  // White LED's connected to pin 3
int xval;
int yval;
int zval;
int val;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(redPin, OUTPUT);         // sets the digital pin as output
  pinMode(orangePin, OUTPUT);      // sets the digital pin as output
  pinMode(bluePin,OUTPUT);         // sets the digital pin as output
  pinMode(whitePin,OUTPUT);        // sets the digital pin as output
  pinMode(xPin, INPUT);            // sets the PWM pin as input
  pinMode(yPin, INPUT);            // sets the PWM pin as input
  pinMode(zPin, INPUT);            // sets the PWM pin as input
  Serial.begin(9600); 
}

void loop()                     // run over and over again
{
  xval = digitalRead(xPin);        // set xval egual to the xPin reading
  yval = digitalRead(yPin);        // set yval equal to the yPin reading
  zval = digitalRead(zPin);        // set zval equal to the zPin reading
 

  Serial.print("X Value: ");
  Serial.println(xval);   

  Serial.print("Y Value: ");
  Serial.println(yval);  

  Serial.print("Z Value: ");
  Serial.println(zval);  

  digitalWrite(statusPin, HIGH);
  delay(15);
  digitalWrite(statusPin, LOW);
  delay(15);

  if ( (xval == 1) && (yval == 1) && (zval == 1))    // if x-y-z values are 1-1-1, light up the white LEDs
  {
    digitalWrite(redPin,LOW);
    digitalWrite(orangePin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,HIGH);
  }

  if ( (xval ==1) && (yval == 0) && (zval == 0))     // if x-y-z values are 1-0-0, turn all lights off
  {

    digitalWrite(redPin,LOW);
    digitalWrite(orangePin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,LOW);
  }

  if ( (xval == 1) && (yval == 1) && (zval == 0))    // if x-y-z values are 1-1-0, light up the orange LEDs
  {

    digitalWrite(redPin,LOW);
    digitalWrite(orangePin,HIGH);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,LOW);
  }

  if ((xval == 1) && (yval == 0) && (zval == 1))     // if x-y-z values are 1-0-1, light up the red LEDs
  {

    digitalWrite(redPin,HIGH);
    digitalWrite(orangePin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,LOW);
  }

  if ((xval == 0) && (yval == 1) && (zval == 0))    // if x-y-z values are 0-1-0, light up the blue LEDs
  {

    digitalWrite(bluePin, HIGH);
    digitalWrite(redPin, LOW);
    digitalWrite(whitePin, LOW);
    digitalWrite(orangePin, LOW);
  }
 
    if ((xval == 0) && (yval == 0) && (zval == 0))   // if x-y-z values are 0-0-0, light up the red and blue LEDs creating purple
  {                                                 

    digitalWrite(bluePin, HIGH);
    digitalWrite(redPin, HIGH);
    digitalWrite(whitePin, LOW);
    digitalWrite(orangePin, LOW);
  }

}
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

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

Blog at WordPress.com.

%d bloggers like this: