Wednesday, May 13, 2015

Final Project

Project Candy Hopper

This Final project was designed under the same premise of our midterm project.
The aim was to bridge the gap between physical toys and the digital world for children and teenagers.
This time though we were able to make the YEI 3-Space sensor work properly.

Using the sensor to collect orientation information, we sent using serial communication Quaternions to Unity where a game was played.

Here is a picture of the Bunny
https://drive.google.com/file/d/0B8ZGdT5f3eJkWGk1VlF3X2phdGs/view?usp=sharing

Here is a picture of the Game.
https://drive.google.com/file/d/0B8ZGdT5f3eJkMTFISHRNN3lTSlE/view?usp=sharing

Using the sensor attached to the bunny. The players goal was to realign Zach/Stefani the bunny with his body in outer space. Each level had 4 matches and there were 10 levels total.

Difficulties
--------------
The greatest difficulty was that the sensor began to break down and output inaccurate information.
To resolve this we had to modify the game immensely to have variable difficulty and a larger acceptable angle range.

Levels and timers were also modified to make the game seem realistic and still worth playing.

Monday, April 20, 2015

Data Visualization Labs

Part 1
https://docs.google.com/a/stern.nyu.edu/file/d/0B2SeRUgxADHINk9GcDBIanE5Wjg/edit
We used a line graph to show how many times the word Amos showed up in books over time.

Part 2
https://docs.google.com/a/stern.nyu.edu/file/d/0B2SeRUgxADHISFR5ZVpsVTducEE/edit
Comparing spending per day between two months.

Part 3
https://docs.google.com/a/stern.nyu.edu/file/d/0B2SeRUgxADHINEVLQXBJakNzOW8/edit
Realtime updating chart of the length of articles on wikipedia.

Mechatronic Project

For this project Me, Zach, and Kevin built a ballista style catapult.

Here is a picture of the setup workspace
https://drive.google.com/file/d/0B8ZGdT5f3eJkRklSTHRwR240ZXc/view?usp=sharing

Here is a video of the catapult in action
https://drive.google.com/file/d/0B8ZGdT5f3eJkUkRJTFhqZm1ndms/view?usp=sharing

----------------------------------------------------------------

The two types of machines we used here were
A DC motor used to wind up a "chain" that pulled the loaded chamber back.
This machine uses a circular motion to build up potential energy in the rubber bands holding the loaded chamber

A Servo Motor that acted as switch to release the chain holding the chamber to fire the catapult.
This was a conversion of rotational energy into a much larger amount of energy built up in the rubber bands.
By using a small force to release a built up larger force, this machine acted similarly to how transistors work.

Miscalculations and Problems
-------------------------------------
This particular project had more problems than any previous project.
First, building a steady structure for the ballista was near impossible given the funds available.
The structure was built out of chopsticks and tape.

Second, the DC motor had no textured surface attached to the spinning pin. As such it was difficult to get a chain to rotate with the motor pin.
This was resolved with thread, needles, a cut rubberband, and super glue.

Third, the rubberbands really didn't hold enough power to launch our projectiles very far.
Rather, the structure wasn't built long enough to pull the chamber back far enough.
However, given the weak rotational power of the DC motor, it was impossible to make the structure any longer.

Given these problems, this catapult is more a proof of concept to show that the design works.
It isn't ready to be mass-produced and marketed as a weapon of damage.

Wednesday, April 15, 2015

Pong Assignment

Here's a video explaining what I did

https://drive.google.com/file/d/0B8ZGdT5f3eJkZG5CaGktZnVlRjg/view?usp=sharing

ARDUINO CODE
/////////////////////////////////////////
const int potPin1 = A0;
const int potPin2 = A5;

const int button1=3;
const int button2=5;

void setup() {
 Serial.begin(9600);
}
void loop() {
 int potVal1 = analogRead(potPin1);
 potVal1 = map(potVal1,0,1023,0,127);
 int potVal2 = analogRead(potPin2);
 potVal2 = map(potVal2,0,1023,0,127);

 int buttonVal1 = digitalRead(button1);
 int buttonVal2 = digitalRead(button2);


 Serial.write(buttonVal1);
 delay(10);
 Serial.write(buttonVal2);
 delay(10);
 Serial.write(potVal1);
 delay(10);
 Serial.write(potVal2);
 delay(50);
}
////////////////////////////////////////////

PONG GAME CODE(I didn't take any code from any online sources, everything was written by me)
/////////////////////////////////////////////
import processing.serial.*;
Serial arduinoPort;

//Input Variables
int buttonVal1; // 0 or 1
int buttonVal2;
int potVal1; // 0 to 127(max byte)
int potVal2;

//Screen vars
int scrnW = 800;
int scrnH = 550;

//ball variables
static float bRad = 30;
float bPosX=0;
float bPosY=0;
float bVelX=0;
float bVelY=0;

//paddle variables
float pWidth = bRad;
float pHeight = 6*bRad;
float pPosX=0;
float pPosY=0;
float pVel=8;

void setup(){
  size(scrnW,scrnH);
  bPosX=width/2;
  bPosY=height/2;
 
  println(Serial.list());
  String portName = Serial.list()[0];
  arduinoPort = new Serial(this,portName,9600);
}

void draw(){
  byte [] inputBuffer = new byte[7];
  while(arduinoPort.available()>3){
    inputBuffer = arduinoPort.readBytes();
    arduinoPort.readBytes(inputBuffer);
    if(inputBuffer!=null){
      String myString = new String(inputBuffer);
      buttonVal1 = inputBuffer[0];
      buttonVal2 = inputBuffer[1];
      potVal1 = inputBuffer[2];
      potVal2 = inputBuffer[3];
     
      //println(buttonVal1 + " "+buttonVal2 + " " + potVal1+" "+potVal2);
    }
  }
 
 
 
  //UPDATE PHYSICS
  Update();
 
  //DRAW
  background(255,255,0);
 
  //draw paddle
  fill(0,0,255);
  rect(pPosX,pPosY,pWidth,pHeight,7);
 
  //draw ball
  fill(255,0,0);
  ellipse(bPosX,bPosY, bRad*2, bRad*2);
 
}


//bound of paddle
//0 to height-pHeight/2;
void Update(){
  //move paddle
  if(buttonVal1==1){
    pPosY+=pVel;
    if(pPosY>height-pHeight){pPosY=height-pHeight;}
  }
  if(buttonVal2==1){
    pPosY-=pVel;
    if(pPosY<0){pPosY=0;}
  }
 
  //update Ball Velocity
  float acellX = map(potVal1,6,127,1,-1);
  float acellY = map(potVal2,6,127,-1,1);
  bVelX+=acellX;
  bVelY+=acellY;
  if(bVelX>pVel){bVelX=pVel;}
  if(bVelX<-pVel){bVelX=-pVel;}
  if(bVelY>pVel){bVelY=pVel;}
  if(bVelY<-pVel){bVelY=-pVel;}
 
  //update Ball position
  bPosX+=bVelX;
  bPosY+=bVelY;
 
  //Process ball borders
  ballBorders();
 
  //Process ball-Paddle Collision
  paddleCollision();
}

void ballBorders(){
  float top = bPosY+bRad;
  float bot = bPosY-bRad;
  float left = bPosX-bRad;
  float right = bPosX+bRad;
 
  if(top>height){
    bPosY=height-bRad;
    bVelY*=-1;
  }
  if(bot<0){
    bPosY=0+bRad;
    bVelY*=-1;
  }
  if(right>width){
    bPosX=width-bRad;
    bVelX*=-1;
  }
  if(left<0){
    bPosX=bRad;
    bVelX*=-1;
    println("LOSE");
  }
 
}

void paddleCollision(){
  //find out if there is collision.
  boolean tf = isPaddleCollision();
  //if there is,
  if(tf){
    bVelX*=-1;
    bPosX=bRad+pWidth;
  }
}

boolean isPaddleCollision(){
  float topB = bPosY+bRad;
  float botB = bPosY-bRad;
  float leftB = bPosX-bRad;
  float rightB = bPosX+bRad;
 
  float topP = pPosY+pHeight;
  float botP = pPosY;
  float leftP = pPosX;
  float rightP = pPosX+pWidth;
 
  if(topB<botP) {
    println(1);
    return false;
  }
 
  if(botB>topP){
    println(2);
   return false;
  }
  if(rightB<leftP){
    println(3);
    return false;
  }
  if(leftB>rightP){
    println(4);
    return false;
  }
  println("COLLISION");
  return true;
 
 
}

/////////////////////////////////////////////

Monday, April 13, 2015

Motor Labs!

Part 1:
Moving servo motor using Processing
https://drive.google.com/file/d/0B2gmbe_Oq0vNeVRUNmcydTZ0aE0/view?usp=sharing

Part 2
Changing motor speed using potentiometer
Mapped the potentiometer input from 0-1023 to 0-255
Then I sent that mapped value to the transistor.

https://drive.google.com/file/d/0B2gmbe_Oq0vNdFJnTHhodDhqNVE/view?usp=sharing

Part 3
Moving motor speed with processing.
Using identical code in processing from part 1.
I modified the code in arduino from part 2 to read input from processing.
Since the processing input was already from 0 to 255, i directly used analogWrite() to pass in that value to the motor.

https://drive.google.com/file/d/0B2gmbe_Oq0vNZFB1bEZwamNTV28/view?usp=sharing

Thursday, April 2, 2015

Midterm Project (Delayed to Monday)

As stated in the last blog post, this project will use a 3-Space Sensor, accelerometer, gyroscope, and magnetometer to sense the movement, position, and orientation of a toy bunny.

The bunny acts as a remote control to play a game developed via Unity.

The game can be seen here:
https://drive.google.com/file/d/0B8ZGdT5f3eJkc0Joa25RQnpIQ1U/view?usp=sharing


Unfortunately due to the explosion on 2nd Avenue and 7th, we lost access to the sensor and our equipment for a duration of time. 

Furthermore, the sensor had not been working properly due to poor connection and failed to work using multiple code samples, blue tooth connection, and serial communication.

We decided to order another sensor, with various other parts.

They will arrive on Friday and given the weekend, this project should be completed and ready for demonstration by Monday.

Friday, March 27, 2015

My Special Lovable Bunny Friend

Concept
We use the position and orientation of our loveable bunny friend to play games. This allows children to keep playing with their dolls even when on the computer by using their doll as a controller of sorts.We also demonstrate how the orientation and position of a doll can be accurately tracked through accelerometer, gyroscope and magnetometer information.

Target
Little children who play with dolls have to unfortunately put their toys down when accessing technology. With this, we enable children to not put down their toys even when on the computer. Furthermore, this allows them to bring their dolls into various realities and worlds as they play different games. The target audience is children.

Technical System
The YEI 3-Space sensor constantly takes down information on its three sensors. The accelerometer, magnetometer, and gyroscope. We use serial communication to read the data and process it into position and orientation information on our loveable bunny. The sensor is hidden inside the bunny along with the microcontroller or bluetooth chip. These then send information to the computer or display where a game is visually shown and can be played through the orientation and position of the bunny.
The game we developed is a 3-D version of cube runner where a bunny can move in different directions depending on the orientation it is facing. The objective is to dodge cubes for as long as possible and it is built in Unity.

Specs
3-Space Sensor - $124 - ordered from eBay
Teensy - $24 - Teensy website
Arduino Kit - $85 - from the arduino website
Bluetooth Chip - $10 - eBay

Manufacturing Techniques
The only advanced technique we will use aside from using a breadboard to hook up wires together includes soldering pieces onto the sensor to establish a more stable connection.

Problems
Sensor was broken.
Unsteady connection - needs to be soldered.
None of the code snippets found and modified seem to work.
Solution - we will order another sensor; one that has a USB connection built in.

Division of Labor
Kevin - Assisted in building Unity game
         - Contributed to game design

Simon - Built game to be played via bunny in Unity
          - motivational support
Zach - getting the sensor data to work properly and connect with Unity
        - contributing to game design


Sunday, March 22, 2015

Homework 5


Part 1
https://drive.google.com/file/d/0B8ZGdT5f3eJka0gtdFkzZkY5cVk/view?usp=sharing

What language is Processing based on?
Java

In your own words, what is the difference between a global and a local variable?
A global variable can be accessed or modified anywhere in code. Local variables exist only within that scope and cannot be accessed through code outside that scope.

What data type does the draw() function return when it is called?
void. no return necessary.

In your own words, explain in detail what the code below the “//keep the circle in bounds” comment does
 if the top of the circle is above the top boundary or bottom of the circle is below the bottom boundary. reverse Y velocity.
Part 2
https://drive.google.com/file/d/0B8ZGdT5f3eJkVnJodEFnWUEzcXc/view?usp=sharing


Part 3
https://drive.google.com/file/d/0B8ZGdT5f3eJkVkFnTXpmZmgzdXM/view?usp=sharing   etchasketch

Sunday, March 1, 2015

Homework 3

Homework 3

Part 1)
https://drive.google.com/file/d/0B8ZGdT5f3eJkc0VOSkVHZy1XQWc/view?usp=sharing
This tech can allow wheel chairs to recognize when a person is sitting properly on the seat or has fallen off and may be in danger.
It can also be used to measure the strength of a persons pulse to recognize when it is weaker than normal based on fluctuations read on the force sensitive resistor.

Part 2)
https://drive.google.com/file/d/0B8ZGdT5f3eJkNHhfZWJydVZzMzQ/view?usp=sharing

Voltage is not divided here because max voltage is only 2 Volts.

The designs using this sensor cannot take part in any quick reactive physical computing. Rather, it is more useful at making slow gradual adjustments, like adjusting flame in an oven based on the temperature.

One way to use this is to adjust light in a sunbathing capsule based on temperature.
Another way is to use these in fire detectors. When temperature hits a certain level that is dangerous, the fire alarm should sound.

Part 3)
https://drive.google.com/file/d/0B8ZGdT5f3eJkdWxMcjRJNi15bWM/view?usp=sharing

Current going through the switch LED is limited by a 10kOhm resistor whereas the other LED is limited only by a 560Ohm resistor.

Current through the switch LED is 5/10000=.0005 Amps whereas current through the other LED is 5/560=.009 Amps

Part 4)
https://drive.google.com/file/d/0B8ZGdT5f3eJkUlJ1TFFadmNLXzA/view?usp=sharing

Sensitivity is much greater when the potentiometer resistance is turned to a minimum.

Part 5)
https://drive.google.com/file/d/0B8ZGdT5f3eJkOC0wYUZDcWdnMEE/view?usp=sharing

https://drive.google.com/file/d/0B8ZGdT5f3eJkb3hCUDlUdHdDaEE/view?usp=sharing

Wednesday, February 18, 2015

Physical Computing Homework 2

Homework assignment 2

Part 1
https://drive.google.com/file/d/0B8ZGdT5f3eJkczBsSkswcXNHUkk/view?usp=sharing

Part 2
https://drive.google.com/file/d/0B8ZGdT5f3eJkR1hzeFpNWFVNN28/view?usp=sharing
1) I would move the switch past the junction point along the 560 ohm resistor.
Wo when the switch is open, current can only flow through the 10kiloOhm resistor.
When the switch is closed, most of the current will flow through the 560 ohm resistor due to the significantly lower resistance.
Arguably no current goes through the 10kiloOhm resistor.

Part 3
https://drive.google.com/file/d/0B8ZGdT5f3eJkTklKbS1yX0QtUlk/view?usp=sharing
1) 5 Volts, effectively no resistance means all of the voltage is left going back into the pin.
2) 0 Volts, all voltage is used up in the resistor.
3) 5kOhms because this evens out the current going into both sides, and since 10kOhms takes up all the voltage, 5kOhms will take up half as much voltage.
4) Because the LED faces the full force of voltage coming from pin5 since the resistor is located after.
In this situation, 5V / 4 results in a maximum voltage of 1.2V that will protect the LED from blowing.

Part 4
https://drive.google.com/file/d/0B8ZGdT5f3eJkQ3o2cmdPMk1PbEE/view?usp=sharing
1) No, becuase the speaker has 8Ohms of resistance which limits the current and prevents a short circuit.
2) More current.
3) Yes.

Part 5
https://drive.google.com/file/d/0B8ZGdT5f3eJkd3RlQ3ZKUzBFc3M/view?usp=sharing
1) Switch the locations of the 10kOhm resistor and photoresistor. When light increases, resistance increases on the path going to ground, which means more current flows into the pin.

Instrument:
By the definition of interactivity, there is a cycle of exchange between me, the controller and the unstruments base note. As the instrument continues to play arpeggios, I adjust my input so that it adjusts it's output.

Critique: No cover. could be better on that aspect.

https://drive.google.com/file/d/0B8ZGdT5f3eJkNjdmaFVtR1E3OEE/view?usp=sharing

Tuesday, February 10, 2015


Week 1 Physical Computing: Basics
by Simon Zhang

This week we worked with basic electronics using resistors, capacitors, potentiometers, LED's and switches.

Simple LED Circuit
https://drive.google.com/open?id=0B8ZGdT5f3eJkNDZsc2I2ZWVHdnc&authuser=1

1) What is the purpose of the resistor?
Protect the LED from being fried. To use up some of the voltage and to limit current so that wires do not overheat.

2) Using Ohm’s Law (V=IR), what is the current running through this circuit?
5/560 = .009 Amps3) Using Ohm’s Law again, calculate the resistor value you would have to use in order to have only 15mA of current in this circuit?
5/.015 = 333.33333~ Ohms

4) Assuming the LED drops 2.2V of voltage, how much voltage is dropped by the resistor?
5-2.2 = 2.8Volts

LED Circuit with Switch
https://drive.google.com/open?id=0B8ZGdT5f3eJkSEhJUUpEd28yQ2M&authuser=1

1) Looking at the schematic diagram, if you moved the switch so that it was connected between the resistor and the LED, how would the circuit’s behavior change?
Nothing would Change. The switch in any location on this circuit acts to open and close the circuit.

2) Looking at the schematic diagram, if you moved the switch so that it was connected between the LED and ground, , how would the circuit’s behavior change?
Still Nothing would change. For the same reason as before.

Simple LED Circuit with Potentiometer
https://drive.google.com/open?id=0B8ZGdT5f3eJkWi1NYW5wQ1NHbkU&authuser=1

1) Why is the 560Ω resistor necessary?
Once again, this is to limit the current and reduce the maximum voltage allowed to go into the LED.
If the Potentiometer were turned so that resistance towards the LED were 0, then we depend on the 560 Ohm resistor to keep the LED from frying.

2) How much current is flowing through the circuit when the 10kΩ potentiometer is turned all the way up (offering the maximum resistance)?
5/(10000+560) = .5 milliAmperes
This effectively makes the LED go out since there is too much resistance.

3) What other types of variable resistors do you know about (name at least 4)?
Volume control, Brightness control, Photoresistors.

Dueling LEDs circuit with potentiometer

https://drive.google.com/open?id=0B8ZGdT5f3eJkQ2VGeEc1ZVNKaFE&authuser=1
1) Give a quick (1-2 sentences) explanation of why this circuit behaves the way it does. Include an explanation for how the current going through each LED is affected by a single turn of the potentiometer
The potentiometer just varies the resistance going towards both sides of the output wires. By turning it all the way one way, one directions recieves all 10kOhms of resistance and the other side has no resistance. By turning the potentiomter back and forth, the current going to both LED's varies because their currents vary. If turned all the way one way, one of the LED's would receive all remaining voltage and the other LED would have no current going through it because resistance is too high.

Capacitor Charging
https://drive.google.com/open?id=0B8ZGdT5f3eJkYUNzRURjX243VUU&authuser=1
1) How does adding a 2.2kΩ resistor between the pushbutton and the capacitor affect the capacitor’s charging behavior?
The charging behavior would be slower, and the initial current with which the capacitor is charged would start at a lower value.

Capacitor Discharging with LED delay
https://drive.google.com/open?id=0B8ZGdT5f3eJkTDZDZ0hSTFd0QWc&authuser=1

1) Looking at the circuit schematic diagram, why does the capacitor discharge up through the LED part of the circuit, and not directly from the capacitor down to ground?
Charge is built up on one side of the capacitor and can only leave through that side. In our theory, positive charge builds up on the north side of our capacitor and can only escape by moving up, turning right, and going through the LED. That way, it can travel to ground.