Serial communication project: Part I

 

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

Team: Claudia Russo, Rafael Poloni and Poonam Patel


PART 1: Concept and circuitry (Arduino)


Materials used: Breadboard, wires, 2 ultra sonic distance sensors.

20-min brainstorm:

Inspired by our last project, the three of us were excited to think of a game that you can play with some kind of physical action. We spend 20 minutes each coming up with fun concepts

Some ideas we liked…

IMG_6353.jpg

What we narrowed down on: A jumping game

IMG_6346.jpg


How would one play?

We’re still working on what the game would be. But for now: a player would follow some instruction on the screen and they’s have to either physically jump or duck. If they do the wrong action, they lose. If they get it right, they keep going until they lose.

Figuring out the first part of the game: Sensors

The distance sensor needs to differentiate between two actions : Jump and duck.

Which one to use: Ultrasonic vs Infrared sensor?

  1. IR sensor: We tried using this one first, but quickly realised it wouldn’t work because of the way it reads an object. Or rather, we couldn’t find a way.

2. US distance sensor:

After a lot of exploring, we tried to use this sensor instead and after many minutes and hours, we got it to work that way we wanted!!! Special shout out to Rafa for coding abilities, if you’re reading this.

Schematic diagram

IMG_6372.jpg

Code:

const int jumpTrigPin = 11;
const int jumpEchoPin = 12;

const int lowerTrigPin = 9;
const int lowerEchoPin = 10;

float distance1 = 0;
float distance2 = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);        //set up a serial connection with the computer
  
  pinMode(jumpTrigPin, OUTPUT);
  pinMode(lowerTrigPin, OUTPUT);
  pinMode(jumpEchoPin, INPUT);    //the echo pin will measure the duration of pulses c
  pinMode(lowerEchoPin, INPUT);
}

void loop() {
  
  distance1 = getDistance1();
  distance2 = getDistance2();   
    if (distance1 < 40 && distance2 < 60){
      Serial.println("jump");
      Serial.print(distance1);
      Serial.print(" | ");
      Serial.println(distance2);
    }    
    
    else if (distance1 >= 40 && distance2 >= 60){
      Serial.println("lower");
      Serial.print(distance1);
      Serial.print(" | ");
      Serial.println(distance2);
    }
    else{
      Serial.println("standing");
      Serial.print(distance1);
      Serial.print(" | ");
      Serial.println(distance2);
    }

  delay(100);      //delay 50ms between each reading
}

//--------------------

float getDistance1()
{
  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(jumpTrigPin, HIGH);
  delayMicroseconds(10); 
  digitalWrite(jumpTrigPin, LOW);

  echoTime = pulseIn(jumpEchoPin, 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
}

float getDistance2()
{
  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(lowerTrigPin, HIGH);
  delayMicroseconds(10); 
  digitalWrite(lowerTrigPin, LOW);

  echoTime = pulseIn(lowerEchoPin, 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
}



See it work…

 
 
Poonam Patel