Interaction Lab – Final Project: Roberto Noel and Robert Prast

Date  5/21/2017

Instructor  Marcela Godoy

Student Name  Roberto Noel and Robert Prast

Project Name The Seeing Eye Hat

Core Component  Distance sensors

Software Arduino, Processing

Materials:

– Seeing Eye Hat: hat, Arduino, Breadboard, buzzers, UR Range sensors, battery pack.

– Game Hat: hat, Arduino, Breadboard, buzzers, accelerometer, bluetooth.

Inspiration:

Walking down Century Avenue, we noticed that there were bumps on the sidewalk, but we weren’t quite sure what they were for. However, after asking Chinese friends about these bumps, we learned that these bumps are put in place to assists blind people walk along the street. We wanted to expand on this idea of assisting blind people with navigation, so we decided to make this our IMA project. We learned about previous projects that aimed at the same objective, one of which used a cane with range sensors and haptic feedback. We found this interesting, but we wanted to make something wearable that is harder to misplace than a cane. Initially, we thought of creating glasses with range sensors, but we soon realized that it would be hard to fit the needed technology onto a pair of glasses (especially the UR sensors as we could have used a small Arduino and breadboard. To solve this problem, we decided to use a hat. 

Another problem arose, however, looking back at the Final Project requirements, we found that we were required to use processing. To solve this we decided to create a second hat that would act as a game, simulating the difficulties that blind people experience in their navigation.

Conceptual Development:

Once we decided on using hats instead of glasses, we had to think of how the technology would actually work. For the first hat, the conceptual piece was very easy, we would just use 3 UR sensors (Left, Middle and Right) which would trigger buzzers to go off if they read below a certain range. This way, when there is an object in front of the blind person, they will be alerted by the buzzer. For the second hat, the conceptual piece was a bit harder because we needed to make the simulation somewhat realistic. We initially thought of creating a virtual maze on the processing sketch and then having the person try to walk through it in a virtual context, essentially creating non-visible obstacles that the player had to get around. The problem we ran into with this was that, while an accelerometer could measure the direction we were facing, it would be hard to accurately measure the actual 3d positioning of the person. To solve this, we decided to make the obstacles appear randomly, instead of creating a pre-set maze. We would also give the player a .5 second window where they could turn and face another direction before being impacted by the object. The player was alerted that there was an obstacle through the same mechanism of the first hat, buzzers.

Process:

Before writing any code, we decided to put the hardware components together. For the seeing eye hat, we began by gluing the UR sensors to their appropriate positions on the hat.

IMG_4842

Then we string the wires through holes that we cut in the had and connected them to the Arduino. One problem that we ran into here, however, is that we weren’t quite sure how to properly connect it since there were 4 ports to connect wires from but most of the schematics online only showed three wires. Additionally, some of the schematics showed that we needed to use the analog ports and others used digital. After playing around with a few different set ups with one sensor and some basic code, we found out that although there were four ports, we only needed to use three and the sensors were digital.

IMG_4886

We finished up with the UR sensors and moved on to gluing and setting up the buzzers. This was a very simple task.

IMG_4888

Once our hat was done hardware-wise, we downloaded a library that would facilitate the use of the UR sensors and began coding. We set up basic code just to make sure that the sensors were reading the proper values but when we tested it, we ran into a problem. One of the sensors wasn’t working…

IMG_4884

After checking the wires and the code to make sure we were doing nothing wrong, we decided that the sensor was in fact broken. To fix this, we simply replaced it with a new sensor.

IMG_4885

The last step was to finish coding the buzzers and make sure our thresholds and the angles at which we had the buzzers were appropriate.

IMG_4887

After finishing the Seeing Eye Hat, it was time to set up the game hat. We had already set up a few gif animations to add to the processing sketch which would make the hat feel more game-like.

Ghost_Death_East

The hardware for the second hat was fairly similar in-terms of the buzzers, but we had two new obstacles, the accelerometer and the bluetooth. The wiring for the accelerometer was fairly straightforward, and Robert had worked with bluetooth in his Network Everything class. We got the hardware done in about an hour.

IMG_4897 IMG_4896 IMG_4895

After coding a simple game that would make the buzzers go off and trigger animations in processing we were finished and had both hats ready:

IMG_4934

 

Conclusion:

Although some parts of this project were extremely tedious, the sense of accomplishment once it was done was outstanding and our small successes throughout the process made everything worth it (especially when we finally got the UR sensors working properly). There were many elements to this that we worked very hard on and it felt very good to see all the parts working well in unison. I don’t think our progress on the Seeing Eye Hat will stop here. Eventually we hope to create a more complex system which would integrate a 3D camera with binaural sound and simulate echolocation for blind people.

//Seeing Eye Hat
#include "Ultrasonic.h"
int buzzerL = 9;
int buzzerM = 11;
int buzzerR = 10;

int rSensor = 7;
int mSensor = 8;
int lSensor = 12;
Ultrasonic ultrasonic_1(lSensor);
Ultrasonic ultrasonic_2(mSensor);
Ultrasonic ultrasonic_3(rSensor);
void setup()
{
  Serial.begin(9600);
  pinMode(buzzerL, OUTPUT);
  pinMode(buzzerM, OUTPUT);
  pinMode(buzzerR, OUTPUT);
}
void loop() {
  long RangeInCentimeters_1, RangeInCentimeters_2, RangeInCentimeters_3;



  RangeInCentimeters_1 = ultrasonic_1.MeasureInCentimeters(); // two measurements should keep an interval
  RangeInCentimeters_2 = ultrasonic_2.MeasureInCentimeters(); // two measurements should keep an interval
  RangeInCentimeters_3 = ultrasonic_3.MeasureInCentimeters(); // two measurements should keep an interval

  Serial.println("Sensor_1: ");
  Serial.print(RangeInCentimeters_1);//0~400cm
  Serial.println(" cm");
  Serial.println("Sensor_2: ");
  Serial.print(RangeInCentimeters_2);//0~400cm
  Serial.println(" cm");
  Serial.println("Sensor_3: ");
  Serial.print(RangeInCentimeters_3);//0~400cm
  Serial.println(" cm");

  if(RangeInCentimeters_1 <140){
    tone(buzzerL,500);
    delay(500);
    noTone(buzzerL);
  }
  if(RangeInCentimeters_2 <180){
    tone(buzzerM,500);
    delay(500);
    noTone(buzzerM);
  }
  if(RangeInCentimeters_3 <140){
    tone(buzzerR,500);
    delay(500);
    noTone(buzzerR);
  }


  delay(250);
}

// Game Hat Arduino

#define echoPin_1 7
#define echoPin_2 4
#define echoPin_3 A0
void setup() {
  Serial.begin (9600);

  pinMode(echoPin_1, INPUT);
  pinMode(echoPin_2, INPUT);
  pinMode(echoPin_3, INPUT);
  
}
void loop() {
  long duration_1, distance_1, duration_2, distance_2, duration_3, distance_3;

  duration_1 = pulseIn(echoPin_1, HIGH);
  distance_1 = (duration_1/2) / 29.1;
  duration_2 = pulseIn(echoPin_2, HIGH);
  distance_2 = (duration_2/2) / 29.1;
  duration_3 = pulseIn(echoPin_1, HIGH);
  distance_3 = (duration_3/2) / 29.1;
  Serial.print(distance_1);
  Serial.println(" cm");
  Serial.print(distance_2);
  Serial.println(" cm");
  Serial.print(distance_3);
  Serial.println(" cm");
  delay(500);
}
// Game Hat Processing
import gifAnimation.*;
import processing.serial.*;
Serial myPort;
int[] sensorValues = {4, 4};
PImage[] animation_1;
PImage[] animation_2;
PImage[] animation_3;
PImage[] animation_4;
PImage[] animation_5;
PImage[] animation_6;
Gif death_north;
Gif death_east;
Gif death_west;
Gif dodge_north;
Gif dodge_east;
Gif dodge_west;
void setup() {
  size(500, 500);
  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.bufferUntil('n');
  printArray(Serial.list());
  death_north = new Gif(this, "Ghost_Death_North.gif");
  death_west = new Gif(this, "Ghost_Death_West.gif");
  death_east = new Gif(this, "Ghost_Death_East.gif");
  dodge_north = new Gif(this, "Ghost_Dodge_North.gif");
  dodge_west = new Gif(this, "Ghost_Dodge_West.gif");
  dodge_east = new Gif(this, "Ghost_Dodge_East.gif");

  animation_1 = Gif.getPImages(this, "Ghost_Death_North.gif");
  animation_2 = Gif.getPImages(this, "Ghost_Death_West.gif");
  animation_3 = Gif.getPImages(this, "Ghost_Death_East.gif");
  animation_4 = Gif.getPImages(this, "Ghost_Dodge_North.gif");
  animation_5 = Gif.getPImages(this, "Ghost_Dodge_West.gif");
  animation_6 = Gif.getPImages(this, "Ghost_Dodge_East.gif");
} 

void draw () {
  if (sensorValues[0]==1 && sensorValues[1]==0) {
    background(255);
  }
  if (sensorValues[0]==1 && sensorValues[1]==0) {
    //HIT FROM THE LEFT
    image(death_west, 0, 0);
    death_west.play();
    
  }
  if (sensorValues[0]==0 && sensorValues[1]==0) {
    //MISS FROM THE LEFT
    image(dodge_west, 0, 0);
    dodge_west.play();
  }
  if (sensorValues[0]==1 && sensorValues[1]==1) {
    //HIT FROM THE UP
    
    image(death_north, 0, 0);
    death_north.play();
  }
  if (sensorValues[0]==0 && sensorValues[1]==1) {
    //MISS FROM THE UP
    image(dodge_north, 0, 0);
    dodge_north.play();
  }
  if (sensorValues[0]==1 && sensorValues[1]==2) {
    //HIT FROM THE RIGHT
    image(death_east, 0, 0);
    death_east.play();
  }
  if (sensorValues[0]==0 && sensorValues[1]==2) {
    //MISS FROM THE RIGHT
    image(dodge_east, 0, 0);
    dodge_east.play();
  }
  
}

void serialEvent(Serial myPort) {
  String myString = myPort.readStringUntil('n');

  // if we get any bytes other than the linefeed:
  if (myString != null) 
  {
    // remove the linefeed
    myString = trim(myString);

    // split the string at the tabs and convert the sections into integers:
    
    sensorValues=int(split(myString,','));
    printArray(sensorValues);
  }
}

Sound Lab

Roberto Noel

Materials: For this lab we used an Arduino, a breadboard, some wires and a variable resistor.

Process:

First we hooked up the Arduino and the breadboard so that the values from the variable resistor would be read in the Serial monitor. Then, using serial communication, sent that value to the processing sketch where we mapped the values to readable arguments for the different functions of the sketch. There were two functions, one moved a ball on the screen and the other changed the speed of the song that was being played.

What I learned:

I learned how to use sound as another channel for interactive media. I have continued to use this library in my personal projects.

(my phone was broken so I couldn’t take pictures of the process)

import processing.serial.*;
Serial myPort;
  
import processing.sound.*;
SoundFile file;

int val;
float pos;
float speed;

void setup(){
  
  size(500,500);
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
  file = new SoundFile(this, "DJ_Scream-Migos-Young_Rich_Nation-Migos-Versace_Prod_By_Zaytoven.mp3");
  file.play();
}


void draw(){
  
  if (myPort.available() > 0)
  {
    val = myPort.read();
     println(val);
     pos = map(val, 0, 255, 0, width);
     speed = map(val, 0, 255, 0, 2);
  }
  background(0);
  fill(val, val, val);
  ellipse(pos,250, 55, 55);
  
  file.rate(speed);
}

Final Project Essay

Robert Prast and Roberto Noel

Interaction Lab

Professor Marcela

April 26, 2017
Strolling down any major Shanghai street you can notice a series of bumps and grooves, which to the common eye have no evident purpose. However, after learning from my Chinese friends that these bumps are put in place to assists blind people walk along the street we began to look at them as a source of artificial sight. We wanted to expand on this artificial sight and essentially extend the site past just the street.
To put this idea into a reality we intend on pairing ultrasonic sensors and speakers. With a series of three ultrasonic range sensors suspended across a hat. The three sensors will be positioned on the left, center, and right of the frames with all the sensors angled downward. We have not decided on the final angle yet, but through our prototypes and testing/experimenting we can finalize the angle. When an object passes the threshold of the range sensors, the corresponding buzzer will go off. For example, if the left sensor detects an object the left buzzer will go off and if the center one detects an object both the left and right buzzer will sound.Picture1

 

One of the more recent developments in this kind of technology is a cane that has sensors on it and can alert you about the objects around it. The problem, however, is that this cane can easily be lost as it is not a wearable and it doesn’t tell you the direction from which objects are coming from.  We think that our invention solves these two problems.Picture2

Additionally, in the spirit of interaction, which we define for our project as connecting an unknown experience to a user, we will have a processing sketch that will simulate how a blind person would go about using our system. Therefore, we will have a sketch randomly generate items, whose relative position in the sketch can be translated to a relative position in real life. To put this simply, if an object randomly generates on the right side of the sketch, the buzzer on the right will go off. The object will continue to buzz until the user moves their head to a different direction. For now, we want the sketch to run for 2 to 3 min and to have the user completely blind folded to fully simulate the sensation of being blind.

Picture3

We think this project is a good first step towards the development of a more complex product which would integrate sonic sensors with binaural (3D) sound. This product would provide similar sensations to echolocation and would be a good navigational assistant for the blind. We hope that this project provides some insight into how the final product would function.

Picture4

3D

Roberto Noel
Midterm Project
Professor Marcela
4/21/2017

For this project I used Tinker Cad. I decided to use an accelerometer in a game controller. Before starting I went online and found that the dimensions of the accelerometer were 20mm by 20mm. These served as my guidelines later for creating a slot for the accelerometer.

After obtaining these dimensions, I went into Tinker Cad and using the Playstation Move controller as a reference, started modeling. First, I made a handle with a diameter of a little over two inches (I found that this would probably be comfortable to hold). Because I didn’t want to copy the Playstation Move exactly, I made the ball on the top significantly larger. This would provide for an interesting weight distribution on the controller which could more easily simulate what you would feel when holding something like a tennis racket which is more top-heavy.

Then it was time to work on creating the slot for the accelerometer. To start, I put a base box which would make a smoother plane to cut into (I didn’t want to cut the slot directly into the cylindrical handle). After that, I used another box with the dimensions of the accelerometer and cut that shape into the handle using the “hole” function.  I also grouped all these shapes together to make them easy to work with.

Lastly, I decided to brand the controller so I created text with the words “Magic Wand” and grouped them on to the controller.

This was an interesting project because, although I had 3D modeled before, I had never given much though to the real-world dimensions of the product I was creating. Tinker Cad made it really easy to change these dimensions and make them actually useable. It was also a very easy program to use compared to the previous ones I had been exposed to (Blender and Meshmixer).

Screen Shot 2017-04-21 at 1.32.31 PMScreen Shot 2017-04-21 at 1.38.30 PMScreen Shot 2017-04-21 at 1.45.10 PM Screen Shot 2017-04-21 at 1.45.04 PMScreen Shot 2017-04-21 at 1.45.15 PM Screen Shot 2017-04-21 at 1.45.56 PMScreen Shot 2017-04-21 at 1.51.29 PMScreen Shot 2017-04-21 at 1.52.22 PM

Stamp Documentation

Roberto Noel
Midterm Project
Professor Marcela
4/18/2017

This project was interesting. I had never used Illustrator before but I got the hang of it pretty quickly. My idea was to trace a smiley face, but I didn’t want to do it exactly as the base image so I made it a bit weirder and gave it some hair. I watched the video tutorial at the same time as making the stamp so I learned how to use the program in sync with the tutorial.

First I got a picture of the smiley face off Google and then I added a layer on top of it that I could use to trace the original image. Since it was just a smiley face this was quite easy. Then I got a red circle since the laser cutter only sees red, and using  the pathfinder, I made an inverse image of it. After that, the last step was to use transform and flip it.

Unfortunately, I had to travel to Guangzhou on Friday so I wasn’t able to make it to the Autodesk offices.


Screen Shot 2017-04-18 at 4.51.16 PM Screen Shot 2017-04-18 at 4.51.56 PM Screen Shot 2017-04-18 at 4.58.48 PM Screen Shot 2017-04-18 at 4.58.52 PM Screen Shot 2017-04-18 at 5.03.48 PM Screen Shot 2017-04-18 at 5.11.09 PMScreen Shot 2017-04-18 at 5.12.47 PMScreen Shot 2017-04-18 at 5.14.44 PM

Above is the screenshots of my process for creating the laser cut document for my stamp.

Midterm Project Roberto Noel- NFC Door Unlock

Roberto Noel
Midterm Project
Professor Marcela
4/1/2017

NFC Door Unlock
Partner:Robeter Prast

Materials: Breadboard, Arduino UNO , NFC Module from DFRobot, 360 Degree Servo, Duct Tape, Wires

Idea: Our idea came from wanting to make getting into the dorm room simpler. Every student already has to have their NYU student cards on them to sign out of the dorm, so it would be beneficial to have a system to incorporate this technology in our rooms. At first I wasn’t quite sure of the popularity and simplicity of NFC, but after realizing how reliant Apple Pay and Google Pay are on this technology it seemed to be a perfect fit for our idea.

Code: Our code wasn’t too complex, however in order to work with our specific NFC module we had to use a custom library to make things works smoothly. This was pretty easy to do, since you can just drag the file into the library folder. Controlling the servo was quite simple too since I had worked with servos in my last project. The code overall is simple and easy to follow.

Implementation: To bring our idea to life, we simply tapped the NFC module and arduino UNO to the front of the door in the center, and used long wires that ran through the crack in the door to a servo on the other side near the lock. Although not the most elegant design, it was functional and got the job done. The servo pulled down a duct tape piece that was connected to the lock to forcibly unlock the door. After finding the best location for the motor, the door unlocked easily.
breadboard2 servo

Conculsion and What I learned: Doing this project, I learned a lot about the application of NFC technology, and how it is so common place in our daily life now. Additionally, I learned about how the arduino communicates on the RX and TX pins. In the end, working on this project was fun, rewarding, and taught me alot about using ardiuno.

Serial Communication L

Instructor: Marcela

Class: Interaction Lab

Objective: The purpose of this lab was for use to learn how to use serial communication to create interaction between Arduino and processing. We got to learn how to do this both ways, so inputs from Arduino would create a reaction in processing and vice-versa.

Process: We decided to start with inputs coming from processing and then going to Arduino and then later focus on Arduino inputs going to processing. The idea was that processing would create an image of three circles RYG and when you clicked a circle, the corresponding LED would turn on. Then there would be a light sensor on the Arduino that would change the image of the three circles depending on how much light it detected.

These were our materials:

17440121_968901336577530_1593351041_n

The set up for the lights was easy, simply connect each light to a pin and a resistor and then ground all the lights. The light sensor was a bit harder because we needed to connect it to three things, an analog read, a power source and a ground. This is what the three lights looked like all set up.

17410436_968901313244199_1910479419_n

I decided, however, that if I were to add the light sensor, the wiring would make it difficult to see each light, so I used a small breadboard to separate the lights from the big breadboard and then add in the sensor:

17439614_968901286577535_152248237_n

After the wiring was set up, the rest was up to the coding. For processing, we just drew the three circles with the corresponding colors and according to which circle you clicked it would send a value (R, Y, G) to the Arduino code. The Arduino code then used if statements that were dependent on the value sent through serial communication and the corresponding light on the breadboard would light up according to that:

17409919_968901289910868_162082970_n

Next we had to do serial communication from the light sensor to the processing image. We set up an analog read on the light sensor and a serial write that would send that value to processing. Then we set up if statements that would turn a certain circle black according to different intervals.

After that we were done:

17410218_968901256577538_1829545693_n 17409810_968901246577539_1817100506_n

Result: We learned a lot from this lab, the concepts were still relatively simple but the syntax and certain mechanics of the coding were interesting to learn.

 

The processing code is this (I couldn’t figure out how to post both codes in the bottom):

import processing.serial.*;
Serial myPort;
int valA; //value from arduino
int x, y, z;
void setup() {
myPort = new Serial(this, Serial.list()[2], 9600);
// Change the Serial.list()[0] to your port
size(500, 200);

}
void draw() {
ellipse(250, 100, 100, 100); //red
fill(x, 0, 0);
ellipse(100, 100, 100, 100); //green
fill(0, y, 0);
ellipse(400, 100, 100, 100); //yellow
fill(z, z, 0);

// to send a value to the Arduino
if (dist(mouseX, mouseY, 250, 100) < 50){
if (mousePressed) {
myPort.write(‘Y’);
//println(‘Y’);
}
else {
myPort.write(‘y’);
//println(‘y’);
}
}
if (dist(mouseX, mouseY, 100, 100) < 50){
if (mousePressed) {
myPort.write(‘R’);
//println(‘R’);
}
else {
myPort.write(‘r’);
//println(‘r’);
}
}
if (dist(mouseX, mouseY, 400, 100) < 50){
if (mousePressed) {
myPort.write(‘G’);
//println(‘G’);
}
else {
myPort.write(‘g’);
//println(‘g’);
}
}

x = 255;
y = 255;
z = 255;
while(myPort.available() > 0){
valA = myPort.read();
}
println(valA);
if(valA > 220 && valA < 250){
x = 0;
}
else if(valA < 220 && valA > 200){
z = 0;
}
else if(valA < 200){
y = 0;
}
}

int valA, val;

void setup() {
  Serial.begin(9600);
  pinMode(11, OUTPUT); //red
  pinMode(10, OUTPUT); //yellow
  pinMode(9, OUTPUT); //green
}

void loop() {
  // receive a value from processing
  while (Serial.available()) {
    val = Serial.read();
  }
  // test the value
  if (val == 'R') {
    digitalWrite(11, HIGH);
  } else if (val == 'r') {
    digitalWrite(11, LOW);
  }
//  delay(10); // wait for Processing
  if (val == 'Y') {
    digitalWrite(10, HIGH);
  } else if (val == 'y') {
    digitalWrite(10, LOW);
  }
//  delay(10); 
  if (val == 'G') {
    digitalWrite(9, HIGH);
  } else if (val == 'g') {
    digitalWrite(9, LOW);
  }
//  delay(10); 

  
  valA = analogRead(0)/4;         // read voltage value 
//  Serial.println(valA);
  Serial.write(valA);
  delay(10); 
}

Stoplight Lab – Lab 2

Instructor: Marcela

Class: Interaction Lab

Objective:

The purpose of this lab was to learn how to use the Arduino with the breadboard to create a circuit that we could control from our computer. We learned how to ground the circuit and how to use digital and analog pins as well as the 5v pin.

Process:

I started out by connecting three wires, one for each of the main lights of the stoplight. Then, I connected the resistors. I also used a button as an input to be used as the alert for someone crossing the road. After that, I set up the remaining two LEDs with resistors and the wiring was complete.

Since the code was provided to use for this lab, it was very easy because all we had to do was make the circuit.

17409705_968895143244816_1798717272_n

17409815_968895146578149_551211080_n17439808_968895153244815_1898274927_n

Next we had to make a circuit in which we controlled an RGB  LED with variable resistors.

Ir was a similar concept except this time, we had three inputs to control one output. The hardest part was getting the orientation of the RGB light correct since it is hard to tell which prong does what. Eventually we got it working, and using the code provided to us, we had fun playing around with the different lights.

17409978_968895159911481_1866352975_n 17439645_968895156578148_1616170394_n

Result: This was a fairly simple lab but it helped establish some very fundamental concepts about circuits. We also learned how to use different components such as variable resistors.

 

Sensor Lab – Roberto Noel

Date: Mar 10, 2017 Friday
Instructor: Marcela
Project: Sensor Lab

Intro:

The aim of this lab was to learn how to use sensors. Going in to this lab, I knew it would be very useful, especially for my stupid pet trick project. Initially, I wanted to use a sonic distance sensor, but the one I received outputted wrong values so I decided to go with the Infrared Sensor instead. My goal was to be able to change the color of an LED using this sensor at different distances.

17102014_958176210983376_1627618031_n17203797_961580580642939_857485187_n

Process:

The most tedious part of this process was hooking up the right wires to the right holes in the breadboard and the Arduino. I also had to search online to see which wire on the infrared sensor corresponded to each function. Eventually I got everything hooked up correctly. This part of the process helped me a lot because I learned how to create more complex circuits with an input and an output.

.17124835_958176237650040_1130828083_n17141427_958176227650041_1962188472_n

Once that was all hooked up, I started coding. This took a while because I had to map the 0 – 1023 values to 0-255 in order for it to control the color. Initially, I didn’t know how to do this, but I googled it and found out.

Once the code was all sorted, it worked very well.

Video: https://www.youtube.com/watch?v=0dHCT5yv66A

Reflection:

This lab was very useful, it taught me how to use the IR Distance Meter and how to code for it. I ended up using this sensor in my stupid pet trick project.

//#include <SoftwareServo.h>

float map_distance = 0;
const int LEDR = 11;
const int LEDB= 9;
const int LEDG = 10;

int r = 0;
int g = 0;
int b = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(LEDR,OUTPUT);
  pinMode(LEDG,OUTPUT);
  pinMode(LEDB,OUTPUT);

  


}

void loop() {
  // put your main code here, to run repeatedly:
  map_distance = map(analogRead(3),0,1023,0,100);
  Serial.println(map_distance);
  
//  if (map_distance > 10){
//    analogWrite(LED,map_distance);
//  }
//  else{
//    digitalWrite(LED,LOW);
//  }
  if (map_distance > 10 && map_distance < 30){
    r = 255;
    g = 0;
    b = 0;
  }
  else if (map_distance > 31 && map_distance < 60){
    r = 0;
    g = 255;
    b = 0;  }
  else {
    r = 0;
    g = 0;
    b = 255;
  }
  analogWrite(LEDR,r);
  analogWrite(LEDG,g);
  analogWrite(LEDB,b);
}

Stupid Pet Trick – Roberto

Date: Mar 10, 2017 Friday
Instructor: Marcela
Project: Stupid Pet Trick
Intro:
Before completing this project, I was very confused as to what I could do with the limited knowledge of programming I have. Thankfully, in the past few labs we learned how to use essential components that would help me for this lab (sensors and servos).
To come up with my idea, I began with this premise: Every great invention solves a widespread problem. And then I completely disregarded that premise and created something utterly useless, a machine that high-fives you. I knew from the beginning that this machine had no potential, and after finishing coding it and putting the parts together, I saw for certain that I had accomplished absolutely nothing. It was perfect.
The Process:
The steps that went into creating this were fairly simple. I started out by gathering the hardware components: a servo, an infrared distance sensor and a bunch of wires. I hooked up the infrared sensor to the Arduino’s analog input via the breadboard and the servo through the digital input. That was pretty much it for the hardware side of it. I did run in to one problem however, when I was connecting the wires to the infrared sensor, one of the female slots on the sensor broke. To fix it I used tape.
17203777_961580560642941_1885130219_n
After that was fixed and it was all wired and ready to go, I put all the components in a box so that it wouldn’t look so messy.
 17198761_961580583976272_1135404179_n
Then I started working on the code which was fairly simple. All I had to do was read the information from the analog input and map it to values between zero and one hundred. After that I created an if statement that said if the mapped value was greater than ten, it would move the servo 110 degrees.
Once the code was done, I had to complete the hardware side of the project by creating the arm that would high-five you. I made that out of styrofoam and cardboard and attached it to the servo with a hot glue gun. I also hot glued the servo and the IR sensor to the box.
17203601_961580617309602_1317679024_n17198316_961580623976268_1811225667_n
Video: IMG_4279 or https://youtu.be/Efi5mCr2XoU
Reflection:
I learned a lot from this project. Initially, I underestimated my ability to create something like this but I surprised myself and learned quite a bit. Although there were small challenges along the way, over all everything went pretty smoothly. I am looking forward to doing my final project and know I will have more tools by then to create something really cool.
#include <Servo.h>
// sets up global variables
float map_distance = 0;
const int servo_1 = 11;
int angle = 0;
Servo myservo;
void setup() {
  // sets up servo and IR
  Serial.begin(9600);
  pinMode(servo_1,OUTPUT);
  myservo.attach(9);
}

void loop() {
  // maps IR read to value between 0 and 100
  map_distance = map(analogRead(3),0,1023,0,100);
  // prints the IR value for testing purposes
  Serial.println(map_distance);x
  // sets up conditions for moving the servo to high five it
  if (map_distance > 20){
    angle = 90;
  }
  else {
    angle = 3;
  }
  myservo.write(angle);
}