Serial communication project: Part II

 

This is PART 2 of a two week project using Arduino and Processing.

Team: Claudia Russo, Rafael Poloni and Poonam Patel


PS: Our main idea of making a game didn’t work out. And so we thought of a different concept that simplified the serial communication part. Also, our circuitry with the distance sensor in part 1 still applies for our changed concept.


PART 2: Serial communication (Processing)


Materials used: Breadboard, wires, an ultra sonic distance sensor.


Our (new) concept: So near and yet so far

The three of us were inspired to work on a theme that we related to and one of the things that came up was how isolated we felt even in the most crowded parts of NYC. We wanted to work with that and create an interactive experience to get a sense of how that feels for us.



How the interactive installation works

When someone walks towards the screen, faces start to appear and pass in a certain perspective on the screen and talking sounds are heard, which get louder as the person gets closer to the screen.



Schematic diagram

Schematics-01.png


Arduino code (revised)

const int TrigPin = 11;
const int EchoPin = 10;

float distance = 0;

void setup() {
  
  Serial.begin(9600);
  Serial.println("0");

  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);

}

void loop() {

  if(Serial.available() > 0){
    char input = Serial.read();
    distance = getDistance();
    Serial.println(distance);
    delay(50);
  }

}



float getDistance()
{
  float echoTime;                   //variable to store the time it takes for a ping to bounce off an object
  float calculatedDistance;         //variable to store the distance calculated from the echo time
  
  //send out an ultrasonic pulse that's 10ms long
  digitalWrite(TrigPin, HIGH);
  delayMicroseconds(10); 
  digitalWrite(TrigPin, LOW);

  echoTime = pulseIn(EchoPin, HIGH);      //use the pulsein command to see how long it takes for the
                                          //pulse to bounce back to the sensor

  calculatedDistance = echoTime / 148.0;  //calculate the distance of the object that reflected the pulse (half the bounce time multiplied by the speed of sound)
  
  return calculatedDistance;              //send back the distance that was calculated
}



Processing code

import processing.serial.*;
import processing.sound.*;

Serial myPort;
SoundFile file;

float sound;

float inByte = 0;

float size;
float size01;
float size02;
float size03;
float size04;
float size05;
float size06;
float size07;
float size08;
float size09;
float width01;
float height01;
float height04;
float height05;
float height06;
float height07;
float height08;
float width02;
float width03;
float width04;
float width05;
float width06;
float width08;

void setup() {
  
  file = new SoundFile(this, "talking.mp3");
  //file.amp(sound);
  file.play();
  file.loop();

  size(1680, 1000);
  printArray(Serial.list());

  String portName = "/dev/tty.usbmodem14401";
  myPort = new Serial(this, Serial.list()[3], 9600);
  myPort.bufferUntil('\n');
}

void draw() {
  
  file.amp(sound);
  background(0);

  fill(255);
  ellipse(width01, height01, size01, size01);
  size01 = size;
  if (size01 <= 0) { 
    size01=0;
  }
  
  if (size01 > 0) {
    width01 = width/4*3+size01*1.5;
    height01 = height/4*3+size01*1.5;
  }
  
  fill(0);
  ellipse(width01-size01/8, height01-size01/8, size01/10, size01/10);
  
  fill(0);
  ellipse(width01+size01/8, height01-size01/8, size01/10, size01/10);

  fill(255);
  ellipse(width02, height/2, size02, size02);
  size02 = size - 100;
  if (size02 <= 0) { 
    size02=0;
  }
  if (size02 > 0) {
    width02 = width/4-size02*1.5;
  }
  
  fill(0);
  ellipse(width02-size02/8, height/2-size02/8, size02/10, size02/10);
  
  fill(0);
  ellipse(width02+size02/8, height/2-size02/8, size02/10, size02/10);

  fill(255);
  ellipse(width03, height/2, size03, size03);
  size03 = size - 160;
  if (size03 <= 0) { 
    size03=0;
  }
  if (size03 > 0) {
    width03 = width/4*3+size03*1.5;
  }
  
  fill(0);
  ellipse(width03-size03/8, height/2-size03/8, size03/10, size03/10);
  
  fill(0);
  ellipse(width03+size03/8, height/2-size03/8, size03/10, size03/10);

  fill(255);
  ellipse(width/2, height04, size04, size04);
  size04 = size - 290;
  if (size04 <= 0) { 
    size04=0;
  }
  if (size04 > 0) {
    height04 = height/4-size04*1.5;
  }
  
  fill(0);
  ellipse(width/2-size04/8, height04-size04/8, size04/10, size04/10);
  
  fill(0);
  ellipse(width/2+size04/8, height04-size04/8, size04/10, size04/10);


  fill(255);
  ellipse(width05, height05, size05, size05);
  size05 = size - 420;
  if (size05 <= 0) { 
    size05=0;
  }
  if (size05 > 0) {
    width05 = width/4-size05*1.5;
    height05 = height/4-size05*1.5;
  }
  
  fill(0);
  ellipse(width05-size05/8, height05-size05/8, size05/10, size05/10);
  
  fill(0);
  ellipse(width05+size05/8, height05-size05/8, size05/10, size05/10);

  fill(255);
  ellipse(width06, height06, size06, size06);
  size06 = size - 500;
  if (size06 <= 0) { 
    size06=0;
  }
  if (size06 > 0) {
    width06 = width/4*3+size06*1.5;
    height06 = height/4-size06*1.5;
  }
  
  fill(0);
  ellipse(width06-size06/8, height06-size06/8, size06/10, size06/10);
  
  fill(0);
  ellipse(width06+size06/8, height06-size06/8, size06/10, size06/10);


  fill(255);
  ellipse(width/2, height07, size07, size07);
  size07 = size - 600;
  if (size07 <= 0) { 
    size07=0;
  }
  if (size07 > 0) {
    height07 = height/4*3+size07*1.5;
  }
  
  fill(0);
  ellipse(width/2-size07/8, height07-size07/8, size07/10, size07/10);
  
  fill(0);
  ellipse(width/2+size07/8, height07-size07/8, size07/10, size07/10);

  fill(255);
  ellipse(width08, height08, size08, size08);
  size08 = size - 680;
  if (size08 <= 0) { 
    size08=0;
  }
  if (size08 > 0) {
    width08 = width/4-size08*1.5;
    height08 = height/4*3+size08*1.5;
  }
  
  fill(0);
  ellipse(width08-size08/8, height08-size08/8, size08/10, size08/10);
  
  fill(0);
  ellipse(width08+size08/8, height08-size08/8, size08/10, size08/10);

  fill(255);
  ellipse(width/2, height/2, size09, size09);
  size09 = size-800;
  if (size09 <= 0) { 
    size09=0;
  }
  if (size09 > 0) { 
    size09 = size09*10;
  }
  
  fill(0);
  ellipse(width/2-size09/8, height/2-size09/8, size09/10, size09/10);
  
  fill(0);
  ellipse(width/2+size09/8, height/2-size09/8, size09/10, size09/10);

  
}

void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
      // trim off any whitespace:
      inString = trim(inString);
      // convert to an int and map to the screen height:
      inByte = float(inString);
      println(sound);
      size = map(inByte, 60, 10, 0, 900);
      sound = map(inByte, 60, 10, 0, 1);
      if (sound <=0) {
        sound = 0;
      }
      if (sound >=1) {
        sound = 1;
      }
    }
  myPort.write("x");
}

See it in action…

 
 
Poonam Patel