Wednesday, December 8, 2010

Final Project

I've finally finished my project. The end result was a a little less than I had originally anticipated but I achieved my main goal of getting my box operational. I had originally planed on having four buttons but due to a lot of complications with code and hardware I ended up only having one. Everything else works as originally designed, the box makes noise when tilted in a direction and the button also makes noise when pressed. The only problem is that the speakers I used aren't very powerful so they aren't very loud.

To make the housing for my components I used blue form insulation that I got from Lowes, black spray paint that I got from Hobby Lobby and Great Stuff spray foam insulation also from Lowes. I cut uniform  squares that I stacked on top of each other and "glued" together with the Great Stuff. I then smoothed out the edges with a knife and cut out the inside of the box. After that I "glued" side panels on to the sides to give it a more box like appearance and spray painted it black. After the paint dried I assembled the components for my box and used velcro to have a removable top. 

I have to give credit to user dany32412 for supplying his code so that I could use it for my project and Thomas Asmuth for helping me trouble shoot my projects problems and helping me figure out my code.








This is the code I used to make my box work. For the complete original code that this is based off of you can go to user dany32412 's profile oninstructibles.com or go to


#include <Wire.h>
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx,accy,accz,joyx,joyy,zbut,cbut;
int ledPin = 13;
int Lledpin = 2; // left led
int Rledpin = 3; // right led
int Uledpin = 4; // up led
int Dledpin = 5; // down led

const int buttonPin = 7; // the number of the pushbutton pin
const int btnPin = 2; // the number of the LED pin
const int extraPin = 8;


// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState2 = 0;


void setup()
{
Serial.begin(19200);
nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake

Serial.print("WiiChuckDemo ready\n");

pinMode(btnPin, OUTPUT); 
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(extraPin, OUTPUT);
}

void loop()
{
buttonState2 = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) { 
// turn LED on: 
digitalWrite(btnPin, HIGH); 
} 
else {
// turn LED off:
digitalWrite(btnPin, LOW); 
}

if(buttonState2 == HIGH) {
digitalWrite(extraPin, HIGH);
} 
else {
digitalWrite(extraPin, LOW);
}

if( loop_cnt > 10 ) { // every 100 msecs get new data
loop_cnt = 0;

nunchuck_get_data();

accx = nunchuck_accelx();
accy = nunchuck_accely();
accz = nunchuck_accelz();
joyx = nunchuck_joyx();
joyy = nunchuck_joyy(); 
zbut = nunchuck_zbutton();
cbut = nunchuck_cbutton(); 
digitalRead(zbut);
if(zbut == 1 ){
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
//Left led accelerometer
if(accx <= 90){
digitalWrite(Lledpin, HIGH);
} else {
digitalWrite(Lledpin, LOW);}
//Right led accelerometer 
if(accx >= 180){
digitalWrite(Rledpin, HIGH);
} else {
digitalWrite(Rledpin, LOW);}
//Up led accelerometer
if(accy >= 165){
digitalWrite(Uledpin, HIGH);
} else {
digitalWrite(Uledpin, LOW);}
//Down led accelerometer
if(accy <= 100){
digitalWrite(Dledpin, HIGH);
} else {
digitalWrite(Dledpin, LOW);}
//Right led joystick
if(cbut == 1){
if(joyx >= 210){
digitalWrite(Rledpin, HIGH);
} else {
digitalWrite(Rledpin, LOW);}
//Left led joystick
if(joyx <= 50){
digitalWrite(Lledpin, HIGH);
} else {
digitalWrite(Lledpin, LOW);}
//Down led joystick
if(joyy <= 70){
digitalWrite(Dledpin, HIGH);
} else {
digitalWrite(Dledpin, LOW);}
//Up led joystick
if(joyy >= 210){
digitalWrite(Uledpin, HIGH);
} else {
digitalWrite(Uledpin, LOW);}
}




Serial.print("accx: "); Serial.print((byte)accx,DEC);
Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
Serial.print("\taccz: "); Serial.print((byte)accz,DEC);
Serial.print("\tjoyx: "); Serial.print((byte)joyx,DEC);
Serial.print("\tjoyy: "); Serial.print((byte)joyy,DEC);
}
loop_cnt++;
delay(1);
}

Final Design

Monday, November 15, 2010

Final Prototype



My project idea is a ball that reacted to motion and impacts with sounds.  For the most part my project was successful when I began putting it together.  However, when  I put together the final product I ran into a few problems. I had 2 main problems, the first was the overall container that I decided to end up using, which was made of Styrofoam. I decided to use this particular material because of it’s availability, cost and how easy it was to carve out.  My main problem with this was that I ended up finding it  almost impossible to fit all of my components into the sphere. My second problem was that the button I decided to use stopped functioning once I assembled my product. I plan on continuing this project for my final, so I plan on trying to work these problems out. I plan on using plastic for the material for my final project and I plan on looking over both my code and my soldering.


Part of the code I used to make the button work I found at

The other part of my code and the general design of my project was from user dany32412 on instructables.com.





Monday, November 1, 2010

Prototype Project

I went to instructibles.com and I found more or less the main element of the project that I wanted to do by user dany32412. I used both Dany's code and hardware layout. Essentially, what Dany's project does is, using the Wii nunchuk's tilt sensor, allows the arduino to, when it senses the nunchuk tilt, it will make sound.
http://www.instructables.com/id/Wii-Nunchuck-Adapter/step9/Testing-The-adapter/?images#images





So, using Dany's instructible for the nunchuk and using Tiffpip79's http://tiffpip79.wordpress.com/ tutorial on impact sensors I should be able to create an interactive ball, similar to my design below.

This is what my prototype looks like so far. The the main difference between this project and Dany's is that I have replaced the LEDs with speakers to produce sound instead of light.