Final Project – Robotic Arm

For the final project, I wanted to make a robotic arm and a p5js sketch that would ask the user to stack blocks of different colors in the right order. As I started working on the project, I realized how difficult it was to make the robotic arm work.

I selected double layered popsicle sticks for the construction of the arm connected together by cardboard squares with slits in them. I wanted the arm to have 4 degrees of freedom. I used big servo motors for the base rotation and the 2nd degree of freedom. For the next two, I used small servos because the bigger ones were too heavy for the popsicle sticks to handle. Then, I went on to make the buttons for moving the arms which I needed 8 of, to account for each movement back and forth. The hardest part was to get the buttons working because there were so many wires and connections that there was always some variable not working properly. One thing that I didnt know at first was that I needed an external power source for the bigger batteries. So I got that working, but then what I didnt know after that was that I needed to ground the power source and the signal from the arduino both into the arduino. Being oblivious to this, I lost a lot of time. Finally, after getting buttons to work, I made the connections more permanent with screws, a lot of hot glue. I soldered the connections to the motors because the arm had to move and the jumper wires would fall out. There were 9 connections to solder for this.

Lazy Susan:

At the beginning the professor recommended me to use a lazy susan for the base rotation, and I constructed the whole thing with the lazy susan but it turned out to be less than ideal because the motor I was using wasn’t enough to turn the lazy susan, so that was a lot of time wasted as well.

Construction:

For the base I made a box out of cardboard and I used 8 big momentary switches as the controls. I had to solder all 8 momentary switches, which was 16 connections. I cut holes in the cardboard for the switches and left a huge opening so the base could rotate properly. I also layered several cardboard pieces around the base motor for more stability.

Progress Videos:

Video 1

Pic 1

Final Video

Week 11 – AakifR

1. Moving Ellipse Using Sensor:

(Arduino Code Remains same as given in class)

/* Week 11.2 bidi serial example
 * Originally by Aaron Sherwood
 * Modified by Mangtronix
 *
 * Add this library to Sketch files
 *  https://github.com/mangtronix/IntroductionToInteractiveMedia/blob/master/code/p5.web-serial.js files
 *
 * You must include this line in your index.html (in Sketch Files) to load the
 * web-serial library
 *
 *     <script src="p5.web-serial.js"></script>
 *
 * Arduino code:
 * https://github.com/mangtronix/IntroductionToInteractiveMedia/blob/master/code/Week11Serial.ino
 */

let rVal = 0;
let alpha = 255;
let left = 0; // True (1) if mouse is being clicked on left side of screen
let right = 0; // True (1) if mouse is being clicked on right side of screen

function setup() {
  createCanvas(640, 480);
  textSize(18);
}

function draw() {
  // one value from Arduino controls the background's red color
  background(map(rVal, 0, 1023, 0, 255), 255, 255);
  
  ellipse(rVal +25,height/2, 50,55); // makes an ellipse that moves with resistor

  // the other value controls the text's transparency value
  fill(255, 0, 255, map(alpha, 0, 1023, 0, 255));

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
    

    // Print the current values
    text('rVal = ' + str(rVal), 20, 50);
    text('alpha = ' + str(alpha), 20, 70);

  }


  // click on one side of the screen, one LED will light up
  // click on the other side, the other LED will light up
  if (mouseIsPressed) {
    if (mouseX <= width / 2) {
      left = 1;
    } else {
      right = 1;
    }
  } else {
    left = right = 0;
  }
}

function keyPressed() {
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
}

// This function will be called by the web-serial library
// with each new *line* of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function
function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // make sure there is actually a message
    // split the message
    let fromArduino = split(trim(data), ",");
    // if the right length, then proceed
    if (fromArduino.length == 2) {
      // only store values here
      // do everything with those values in the main draw loop
      
      // We take the string we get from Arduino and explicitly
      // convert it to a number by using int()
      // e.g. "103" becomes 103
      rVal = int(fromArduino[0]);
      alpha = int(fromArduino[1]);
    }

    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = left + "," + right + "\n";
    writeSerial(sendToArduino);
  }
}

//Arduino Code
/*
// Week 11.2 Example of bidirectional serial communication

// Inputs:
// - A0 - sensor connected as voltage divider (e.g. potentiometer or light sensor)
// - A1 - sensor connected as voltage divider 
//
// Outputs:
// - 2 - LED
// - 5 - LED

int leftLedPin = 2;
int rightLedPin = 5;

void setup() {
  // Start serial communication so we can send data
  // over the USB connection to our p5js sketch
  Serial.begin(9600);

  // We'll use the builtin LED as a status output.
  // We can't use the serial monitor since the serial connection is
  // used to communicate to p5js and only one application on the computer
  // can use a serial port at once.
  pinMode(LED_BUILTIN, OUTPUT);

  // Outputs on these pins
  pinMode(leftLedPin, OUTPUT);
  pinMode(rightLedPin, OUTPUT);

  // Blink them so we can check the wiring
  digitalWrite(leftLedPin, HIGH);
  digitalWrite(rightLedPin, HIGH);
  delay(200);
  digitalWrite(leftLedPin, LOW);
  digitalWrite(rightLedPin, LOW);



  // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0,0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data

    int left = Serial.parseInt();
    int right = Serial.parseInt();
    if (Serial.read() == '\n') {
      digitalWrite(leftLedPin, left);
      digitalWrite(rightLedPin, right);
      int sensor = analogRead(A0);
      delay(5);
      int sensor2 = analogRead(A1);
      delay(5);
      Serial.print(sensor);
      Serial.print(',');
      Serial.println(sensor2);
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
}
*/

 

2. LED Brightness Control:

/* Week 11.2 bidi serial example
 * Originally by Aaron Sherwood
 * Modified by Mangtronix
 *
 * Add this library to Sketch files
 *  https://github.com/mangtronix/IntroductionToInteractiveMedia/blob/master/code/p5.web-serial.js files
 *
 * You must include this line in your index.html (in Sketch Files) to load the
 * web-serial library
 *
 *     <script src="p5.web-serial.js"></script>
 *
 * Arduino code:
 * https://github.com/mangtronix/IntroductionToInteractiveMedia/blob/master/code/Week11Serial.ino
 */

let rVal = 0;
let alpha = 255;
let left = 0; // True (1) if mouse is being clicked on left side of screen
let right = 0; // True (1) if mouse is being clicked on right side of screen

function setup() {
  createCanvas(255, 255);
  textSize(18);
}

function draw() {
  // one value from Arduino controls the background's red color
  background(map(rVal, 0, 1023, 0, 255), 255, 255);


  // the other value controls the text's transparency value
  fill(255, 0, 255, map(alpha, 0, 1023, 0, 255));

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
    

    // Print the current values
    text('rVal = ' + str(rVal), 20, 50);
    text('alpha = ' + str(alpha), 20, 70);

  }


  // click on one side of the screen, one LED will light up
  // click on the other side, the other LED will light up
  if (mouseIsPressed) {
    if (mouseX <= width / 2) {
      left = 1;
    } else {
      right = 1;
    }
  } else {
    left = right = 0;
  }
}

function keyPressed() {
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
}

// This function will be called by the web-serial library
// with each new *line* of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function
function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // make sure there is actually a message
    // split the message
    let fromArduino = split(trim(data), ",");
    // if the right length, then proceed
    if (fromArduino.length == 2) {
      // only store values here
      // do everything with those values in the main draw loop
      
      // We take the string we get from Arduino and explicitly
      // convert it to a number by using int()
      // e.g. "103" becomes 103
      rVal = int(fromArduino[0]);
      alpha = int(fromArduino[1]);
    }

    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    
    let sendToArduino = mouseX + "," + mouseY + "\n";
    writeSerial(sendToArduino);
  }
}
// Week 11.2 Example of bidirectional serial communication

// Inputs:
// - A0 - sensor connected as voltage divider (e.g. potentiometer or light sensor)
// - A1 - sensor connected as voltage divider 
//
// Outputs:
// - 2 - LED
// - 5 - LED

int leftLedPin = 3;
int rightLedPin = 5;

void setup() {
  // Start serial communication so we can send data
  // over the USB connection to our p5js sketch
  Serial.begin(9600);

  // We'll use the builtin LED as a status output.
  // We can't use the serial monitor since the serial connection is
  // used to communicate to p5js and only one application on the computer
  // can use a serial port at once.
  pinMode(LED_BUILTIN, OUTPUT);

  // Outputs on these pins
  pinMode(leftLedPin, OUTPUT);
  pinMode(rightLedPin, OUTPUT);

  // Blink them so we can check the wiring
  digitalWrite(leftLedPin, HIGH);
  digitalWrite(rightLedPin, HIGH);
  delay(200);
  digitalWrite(leftLedPin, LOW);
  digitalWrite(rightLedPin, LOW);



  // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0,0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data

    int xPos = Serial.parseInt();
    int yPos = Serial.parseInt();
    if (Serial.read() == '\n') {
      analogWrite(leftLedPin, xPos);
      analogWrite(rightLedPin, yPos);
      int sensor = analogRead(A0);
      delay(5);
      int sensor2 = analogRead(A1);
      delay(5);
      Serial.print(sensor);
      Serial.print(',');
      Serial.println(sensor2);
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
}

3. Part third

/* Week 11.2 bidi serial example
 * Originally by Aaron Sherwood
 * Modified by Mangtronix
 */
let velocity;
let gravity;
let position;
let acceleration;
let wind;
let drag = 0.99;
let mass = 50;

let LED_STATE = 0;

function setup() {
  createCanvas(640, 360);
  background(125, 125, 125);
  position = createVector(width / 2, 0);
  velocity = createVector(0, 0);
  acceleration = createVector(0, 0);
  gravity = createVector(0, 0.5 * mass);
  wind = createVector(0, 0);
}

let connected = false;

function draw() {
  background(255);
  fill(255, 200, 0);
  if (!serialActive) {
    text("Press SPACE to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
  }

  if (connected === true) {
    applyForce(wind);
    applyForce(gravity);
    velocity.add(acceleration);
    velocity.mult(drag);
    position.add(velocity);
    acceleration.mult(0);
    ellipse(position.x, position.y, mass, mass);
    if (position.y > height - mass / 2) {
      velocity.y *= -0.9; // A little dampening when hitting the bottom
      position.y = height - mass / 2;
      LED_STATE = 0;
    } else {
      LED_STATE = 1;
    }
  }
}

function applyForce(force) {
  // Newton's 2nd law: F = M * A
  // or A = F / M
  let f = p5.Vector.div(force, mass);
  acceleration.add(f);
}

function keyPressed() {
  if (key == " ") {
    mass = random(15, 80);
    position.y = -mass;
    velocity.mult(0);
    setUpSerial();
  }
 
}

// This function will be called by the web-serial library
// with each new *line* of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function

function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    let fromArduino = split(trim(data), ',');
    if (fromArduino[0] < 512) {
      wind.x = map(fromArduino[0], 200, 512, -2, 0);
    } else {
      wind.x = map(fromArduino[0], 513, 1023, 0, 1);
    }
    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = LED_STATE + "\n";
    writeSerial(sendToArduino);

    connected = true;
  }
}
int leftLedPin = 2;
int rightLedPin = 5;


void setup() {
 // Start serial communication so we can send data
 // over the USB connection to our p5js sketch
 Serial.begin(9600);


 // We'll use the builtin LED as a status output.
 // We can't use the serial monitor since the serial connection is
 // used to communicate to p5js and only one application on the computer
 // can use a serial port at once.
 pinMode(LED_BUILTIN, OUTPUT);


 // Outputs on these pins
 pinMode(leftLedPin, OUTPUT);
 pinMode(rightLedPin, OUTPUT);


 // Blink them so we can check the wiring
 digitalWrite(leftLedPin, HIGH);
 digitalWrite(rightLedPin, HIGH);
 delay(200);
 digitalWrite(leftLedPin, LOW);
 digitalWrite(rightLedPin, LOW);






 // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH);  // on/blink while waiting for serial data
    Serial.println("0,0");            // send a starting message
    delay(300);                       // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}


void loop() {
 // wait for data from p5 before doing something
 while (Serial.available()) {
   digitalWrite(LED_BUILTIN, HIGH);  // led on while receiving data


   int LED_STATE = Serial.parseInt();
   //int right = Serial.parseInt();
   if (Serial.read() == '\n') {
     digitalWrite(rightLedPin, LED_STATE);
     int sensor2 = analogRead(A1);
     delay(5);
     Serial.print(sensor2);
     Serial.print(',');
     Serial.println('Y');
   }
 }
 digitalWrite(LED_BUILTIN, LOW);
}

 

Week 10 – Musical Instrument

For this assignment, we wanted to make a hovering keyboard. We used the ultrasonic distance measuring sensor to set specific distance ranges to specific notes. As the user would move their hand through different ranges, different notes would play. We also added a button to turn off the instrument completely in addition to implementing a maximum range beyond which the instrument doesn’t produce any sound.

Video:

#include "pitches.h"
// defines pins numbers
const int trigPin = A0;
const int echoPin = A1;
const int speakerPin = 8;
const int pushButton = A2;
// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT);  // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);   // Sets the echoPin as an Input
  pinMode()
  Serial.begin(9600);  // Starts the serial communication
  
}
void loop() {
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);  // delay in between reads for stability
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
  // Playing outside distance range or the instrument is turned off
  if (distance >= 40 || buttonState == 1) {
    noTone(speakerPin);
  }
  // Play C4 in first 10cm
  else if (distance >= 0 && distance <= 10) {
    tone(speakerPin, NOTE_C4, 1000 / 4);
  }
  // Play G4 in next 10cm
  else if (distance >= 11 && distance <= 20) {
    tone(speakerPin, NOTE_G4, 1000 / 4);
  }
  // Play A4 in next 10cm
  else if (distance >= 21 && distance <= 30) {
    tone(speakerPin, NOTE_A4, 1000 / 4);
  }
  // Play F4 in next 10cm
  else if (distance >= 31 && distance <= 40) {
    tone(speakerPin, NOTE_F4, 1000 / 4);
  }
}

Future Applications:

I think for future applications, the number of keys could be expanded to have 12 keys, and buttons to move up or down an octave so it could be a complete hovering piano with all possible keys present on a keyboard.

Reading Response Week 9 – AakifR

I think that the reading “Making Interactive Art: Set the Stage, Then Shut Up and Listen” captures what all art is about and how all art works regardless of whether it’s explicitly interactive or not. After the artist publishes their work for other people to see, a process of interaction between the artist’s thoughts and the thoughts of the audiences starts to happen. This is where the magic of meaning happens. Each viewer has their own perspective towards anything they encounter and with each interaction a new meaning is formed. Sometimes, the new meanings are quite vastly different than what the artists originally thought of when making the art. For example, the robotic arm that sweeps hydraulic fluid by Sun Yuan and Peng Yu called “Can’t Help Myself” was originally intended to be about migration and sovereignty but viewers largely interpreted it to be about being depressed and trying to hold oneself together.

I think for me personally, I learn a lot and connect a lot of dots while I’m having conversations with people rather than when I’m with myself. So this idea of putting an artwork out there and then let people interact with it and have conversation with it is something that makes a lot of sense to me.  As I think about capstone, I want to integrate more of this two way conversational aspect so that I learn more about myself and ideas and also how other people think about them.

Week 9 Assignment – AakifR

For this week I wanted to experiment with the Ultraviolet Distance Sensor that was provided in the Starter Kit. I hooked it up to the Arduino and then tried to create a sort of system that turns a red light on if the distance of the object becomes too little or too big from the sensor. Some of the applications could be, for example, to alert an automated robot vehicle if it’s getting too close to an obstacle and similarly if it’s moving too far apart.

Video Demonstration:

Code:

// defines pins numbers
const int trigPin = A0;
const int echoPin = A1;

const int pushButton = A2;

const int greenLEDPin = 13;
const int redLEDPin =  12;


// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  pinMode(greenLEDPin, OUTPUT);

  Serial.begin(9600); // Starts the serial communication
}
void loop() {


int buttonState = digitalRead(pushButton);

  if (buttonState == HIGH) {
   
    digitalWrite(greenLEDPin, HIGH);
  }
  else{
    digitalWrite(greenLEDPin, LOW);
  }

// print out the state of the button:
  Serial.println(buttonState);
  delay(1);  // delay in between reads for stability



  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);

  if (distance >= 10 && distance <=  20){
    digitalWrite(redLEDPin, HIGH);
  }
  else{
    digitalWrite(redLEDPin, LOW);
  }

}

 

Midterm – Flappy Pokemon

 

For the midterm project, I decided to combine the common game flappy bird with my own obsession with Pokemon using one of my favorites as the main character.

Problems:

One of the main problems I ran into was figuring out how to restart the game without actually restarting the sketch. It took a lot of work to finally figure out how to do it because one of the arrays I was using wasn’t being reset with my resetSketch() function. So, after a lot of debugging, I figured out how to reset that array every time I reset the game.

This game is still very wonky and there are a lot of improvements that could be done for it to be an overall better experience. I am quite proud of my use of the flying animation and the continuous scrolling background.

 

Game:

Week 5 Response

I found the idea of using computer vision to judge how intensely a person is smiling to be very intriguing. There is an animated short film by the name of Shehr-e-Tabassum which imagines a dystopian future where anyone who doesn’t smile is considered to be outcast and is immediately captured by the government. I can only wonder how computer vision technology in the future will be used for deep public surveillance and for penalizing those who don’t comply.

I wonder if cameras are the only way we can implement computer vision. I think things like heat sensors and sonar technology also has a space in the computer vision landscape. I also wonder if computer vision will ever be as advanced as a human eye and by extension will AI ever be able to process as much information as humans can or will it always be limited by what computer vision can achieve and have to rely on other sensors for getting a complete picture of what is happening. There is also anti computer vision technology which will massively undercut the effectiveness of computer vision and security systems in general.

Week 4 Assignment

I used the geolocation data of power plants around the world combined with the data for the production capacity for each plant. I used the geolocation to put them on the canvas, and then at each point a bar extends from the canvas vertically upward to account for the capacity of the plant.

I think something to make this more visually appealing would be to add some interactivity. I think it could be that as the user clicks on a point, they can get more information about that power plant, like the country, capacity, type of plant, etc. A pop-up text box could display such information.

Week 4 Writing Assignment – Aakif

I don’t know what to say about this reading. It just gave a really good explanation on how things should be designed and what factors to be considered in addition to establishing a lexicon for understanding design for these objects.

I think one thing that I noticed was that he mentioned how as technology improves, it will become more difficult to understand technology, but at the same time it will make it easier to understand technology because of technology. This is true today. As it is quite difficult to understand today’s mobile devices by older people. It requires one to have a familiarity with technology from a young age or have followed the development of technology over the past few years. It almost if new devices have a barrier to entry, and the threshold is quite high. But at the same time it is so much easier to do such complicated tasks in such a short time if you get the hang of it.

Reading Reflection – Week# 3

I am in agreement and disagreement with the author at the same time. I like that the author really makes it a point to clarify that there are degrees of interactivity and that refrigerator is a low level (zero) and conversation is a high level. But I don’t agree with his way of doing away with all the other media and claiming they are zero interactivity e.g. film, music. The claim that there are degrees of interactivity should be justly applied to these media as I think a medium like film is very much interactive as it has the viewer and the maker in a continuous conversation, albeit the method of conversation is a little different than 1:1 live conversation.

I think the author is biased toward high interactivity activities and is ridiculing other media and reducing their significance to interactivity. In my eyes, interactivity or interactive media is anything that someone interacts with, and film and music are perfectly interactive as is conversation. Just as the author says, in even real life conversations, there isn’t a perfect interative conversation ever because there are so many requirements for it. Building off this point, things like film and music are equal to normal conversations on the scale of interactivity.