Week 4: JavaScript Exercise 2 (Chen)

Partner: Pearl

During class, Pearl and I struggled to understand what it was we needed to be changing since none of what we were typing were having any effect on the website. However, after talking to Professor Chen and the learning assistants, we figured out we had to work with the display and blocks in the CSS, rather than adding colors. Once we figured out the dimensions of the boxes, we went with the multiconditional approach. However, one thing we struggled with was despite typing in all the needed information, the console kept saying that there was an error. But after much trial and error, we figured out that after every “else” there has to be an “if”, not just one “else if”.

Stupid Pet Trick – Adonis Langumas

September 29, 2017

Professor JH Moon

Aim/Goal: Use the knowledge gained to create a personal project.

“Don’t Steal My Shushi”

Materials:

1* USB Cable

1* Solderless Breadboard

1* 1M resistor

1* DFRduino Uno R3

Jumper Cables M/M

1* Servo

Ultrasonic Sensor

M/F Jumper Cables

 

Cardboard

Sushi

Cat

Electrical Tape

Day 1:

I begin the project by deciding on what I needed. I knew I needed a piece to move every time someone moved towards the sushi. For this I decided on using The ultrasonic sensor to take information about distance, and I used a servo as the output to have movement. After getting the materials, I built the circuit.

The circuit worked, but I struggled with the code. The sensor was taking in readings, but the servo was not moving accordingly. I soon realized that my syntax was off. After getting some help, I fixed it and learned how to properly use if statements. I set the servo to move to a random position.

 

I then attached the platform for the sushi and added the sensor to it. Following this, I put the circuit in a box to make it easier to move around, store, and make it look nicer in general. 

Day 2: For day 2 I mainly decorated my product to improve its appearance.

Day 3: This involved improving the code to the user experience as I got feedback and observed how others interacted with it. I added a delay to prevent the twitching that would sometimes happen. I also Used a while loop to make sure it would always move a minimum distance.

Conclusion: The code was extremely important. I realized that even when a project is “done” much can be improved when you take into account how others interact with it. The feedback I got was the most important tool when improving my project.

 

 

 

/*
  Ping))) Sensor

  This sketch reads a PING))) ultrasonic rangefinder and returns the distance
  to the closest object in range. To do this, it sends a pulse to the sensor to
  initiate a reading, then listens for a pulse to return. The length of the
  returning pulse is proportional to the distance of the object from the sensor.

  The circuit:
  - +V connection of the PING))) attached to +5V
  - GND connection of the PING))) attached to ground
  - SIG connection of the PING))) attached to digital pin 7

  created 3 Nov 2008
  by David A. Mellis
  modified 30 Aug 2011
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Ping
*/

// this constant won't change. It's the pin number of the sensor's output:

const int pingPin = 7;
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
boolean dave;
int old_angle = 0;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  myservo.attach(9);

}
void loop() {
  // establish variables for duration of the ping, and the distance result
  // in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH pulse
  // whose duration is the time (in microseconds) from the sending of the ping
  // to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  //set an old angle
  //Find out if the difference between the new angle and the old angle is too little
  //Generate a new angle if it's too small
  //Otherwise keep on trying again (using a while loop?)
  if (cm < 15) {
      int angle = random(10, 170);
      while (abs(angle-old_angle) <= 45) {
        angle = random(10, 175);
      }
      myservo.write(angle);
      old_angle = angle;
      delay(500);
  }
  //myservo.read(angle);

  delay(100);
}

long microsecondsToInches(long microseconds) {
  // According to Parallax's datasheet for the PING))), there are 73.746
  // microseconds per inch (i.e. sound travels at 1130 feet per second).
  // This gives the distance travelled by the ping, outbound and return,
  // so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the object we
  // take half of the distance travelled.
  return microseconds / 29 / 2;
  // waits 15ms for the servo to reach the position
}

Stupid Pet Trick | Wei Wang

This week we were asked to do a Stupid Pet Trick project for our midterm. So at first my idea was to build a project with a rose the color of which would transfer from red to purple bit by bit according to the data from a pressure sensor.

However, with the borrowed vibration sensor, the color could not change gradually because of the requirement of constant knocks with increasing force. Therefore, I changed it to a temperature sensor. But unfortunately, the temperature range that I could make to it is quite small, so that the data range for each LED to turn on is very limited, making the color change   invisible . And another problem is that the data range that sensor transferred would e determined by the room temperature that may vary on account of air conditioner. Consequently, this plan was also abandoned.

And finally, I found a component that could best suit my expectation, the potentiometer. The data would change steadily with the adjustment to it, and the gap between the lowest and the highest data was comparably huge, from 0 to 1023, so that every period for each color of the light to fade is enough for human eyes to detect. Moreover, the speed of the changes would be easy to control with a potentiometer than a sensor,espectially a temperature sensor.

So I buit a circuit with the green, yellow and red LEDs, and a potentiometer to control their fading. However, with a paper rose covering the LEDs, the green and yellow light became invisible, so I added another two green LEDs and one other yellow one, making the yellow light as bright as the red, but there was still a failure for the green light to travel throw the paper. As a consequence, I removed all the green LEDs, and leave only the yellow and red ones to contribute to the color fading.

Then came to the computer coding. I first did the code like this, with the map function.

But the yellow LED just turned on and off periodically even wIMG_2185hen the value is bigger than 800. So I added more command into the code.

So the yellow light would fade away due to the increasing value with stronger and stronger red light from inside the rose.

CLICK HERE TO WATCH THE VIDEO OF MY PROJECT – BOY & ROSE GIRL

 

IxLab 4 – Stupid Pet Trick Show/ Professor Moon/ Dylan Wang

Recitation 4 – Stupid Pet Trick Show

Date: September 29th, 2017

Documented by: Dylan Wang

Instructor: Moon Junghyun

In this Stupid Pet Trick show, I made an “angry crocodile”, once you touched its back, its eyes would blink, the fan on its tail would work and the buzzer inside its body would ring out loud.

So the first step is to make the shell of the crocodile. I download a papercraft blueprint from Twitter and the image is shown below.

Following the instruction on the IMA Documentation blog, I transformed this picture to an Adobe Illustrator file which is ready for laser cut and it is shown in the screenshot below.

After finish this blueprint, I used laser cut machine to cut to out as shown in the following video.

Then it comes to the circuit part. I want to achieve the goal of using one sensor to control three functions, so I build the circuit shown below.

And it worked perfectly.

Then the big problem comes: I cannot get anything into the body part of my crocodile since it’s way more complicated than I expected and the body part is definitely too small for that.

I get two LEDs into the head part and the fan into the tail part.

So the final decision I made is to throw breadboard into the body while leaving five wire out to connect to Arduino board.

And this is what the final result looks like.

And below is the code I used.

Hope you like this “angry crocodile” 😎

 

float sinVal;            
int toneVal;
unsigned long tepTimer ;//(1)  
#define pin A1

void setup() {
        Serial.begin (9600);
        pinMode(pin, INPUT);
        pinMode(10, OUTPUT);
        pinMode(9, OUTPUT);
}

void loop() {
        uint16_t value = analogRead (pin);
        double distance = get_IR (value); 
        Serial.println (value);               
        Serial.print (distance);
        Serial.println (" cm");
        Serial.println ();
        delay (500);  
        digitalWrite(10, LOW);
        delay(2);
        
        if(distance<10){         
              for(int x=0; x<180; x++){
                sinVal = (sin(x*(3.1412/180)));
                toneVal = 200+(int(sinVal*1000));
                tone(8, toneVal);
                delay(2); 
          }   
        } else {    
           noTone(8);                       
        }
        
        if(distance<10){  
        digitalWrite(10, HIGH); 
        delay(2); 
        }

        if(distance<10){  
        digitalWrite(9, HIGH); 
        delay(1000);
        }
        else {
        digitalWrite(9, LOW); 
        delay(1);
        }

}
//return distance (cm)
double get_IR (uint16_t value) {
        if (value < 16)  value = 16;
        return 2076.0 / (value - 11.0);

}

IL(Moon)-Stupid Pet Trick Show by Zeping Fei (Phyllis)

Date: September 29th, 2017

Documented by: Zeping Fei

Aim: Create a physically interactive device based on the understanding of digital and analog.

Project Name: “GET THE SKITTLES”

Principle: The box will open once you hit the donkey, but its open time is RANDOM. If you want the skittles, try to get them inside the box as fast as possible!

Materials:

donkey hammer*1

piezo electric disc*1

1 megohm resistor*1

hand-made box*1

breadboard*1

Arduino*1

servo*1

wires

cardboard

markers

skittles

foam

Schematic and First Sketch

Process

At first, I borrowed both FSR and vibration sensor, but I didn’t know how to use them, could’t distinguish their usages, and  whether I should use both of them or choose only one (left). Therefore, I choose to try the vibration sensor first and make the circuit to test if it could work. However, it works only for two times but then it “dies” (right).

       

With the help of Nick, the sensor is taken apart and I use the front part only (without using the analog process part).

After trying several times, it works very well, so I use the donkey hammer to hit it and have another test. It worked, and we can see “knock” when the hammer touched the sensor.

Since it works very well, I connect the sensor to the hammer so that the sensor would be stable for user to use, and more importantly, it looks cuter.

       

Since the sensor part is almost done, I get started with the box part. I plan to make a box myself which can be controlled of being opened and closed. I have came up with many ideas about how to open the box smartly, and one of them is to use a stick and connect it to the servo, so that they can rotate together. However, I was so struggling with their position. Moon guided me to fix them on one side of the little box, and the following picture shows how I stable it. Finding out that they can support the top of the box as a lever and smoothly rotate together. (Originally, I was thinking to make a hole and let the stick go through it, but I realized that although it could work, the friction would be really strong, which is not good for the function of the box at all.) I plug in the servo and test whether the circuit can work or not.

Therefore, I cut the stick to a suitable length, stabilize it on the edge of the box and test it again. This time, I put some heavy stuff in the box, so that it won’t fall and mess up. Much better. The early form of my project is smoothly done.

       

Decoration #1

Decoration #Final

Final test

In order to make the box more stable without using any other heavy materials (which will also take the space of the skittles), I use double-side tape at the bottom to stick it on the table.

User Experience

Reflection

I was once struggling with the codes, but there’re lots of examples in Arduino which are of great help.

When creating an interactive project, picking RANDOM time provides more challenge and joy for the users, which is also really creative.

Besides, when connecting the sensor to the donkey, I found that the disc and the join part between the disc and the wire are more sensitive. According to this, I changed the position of the sensor on the hammer.

before moving

after moving

 

 

 

Rudi’s class — Stupid Pet Trick, “a silly game box” by Jerry Ding Yuhao

Stupid pet trick — A silly game box  

Ding Yuhao

Rudi’s class

29 Semtember 2017

Firstly, I want to show a video of how it works:

The stupid pet trick is to make something surprising or interesting, the essence of it is interactive but not only scientific. I decided to created a game box, as a game box is the easiest way to gain people’s attention. The game that I was making was a game that tested your responding speed. In short, “Press the button when the green light is on”.This is an overview of my project, and I will explain how it works and my designing process.

This game box is made up of these components:

2 red LED, 2 green LED, 1 yellow LED, 2 ultrasonic rangers, 2 motors, 1 button, 3 breadboards, arduino, and serveral cardboards

The rule of the game

The first thing is to finalize the rule of the game.  It is a respond-speed testing game. So my first design is

  1. the red light blink for 2 times
  2. the yellow light is on for 1s
  3. After random seconds(1-5s), the green light is on, and the player have to press the button
  4. If the player makes it in 1s, the other green light is on, or the red one is on

However, this version is not interactive enough, so I decided to add a second round, but the rule is gonna be much more complex. I used the ultrasonic ranger and put it by the side of the button. The usage of it is to make the player hand 8cm higher than the button, so it makes the player harder to press and the game harder.

And when the player finally wins he can get his money back like this:

Programming

Programming is really a hard issue. One problem occurred in the very first. I used a lot of delay, that made the sensors getting data in a really low frequency. I fixed it by using if language to seperate the delay part and the sensor part.There were also some other little problems but I managed to fix them.

A programming was really long, so many logical mistakes occurred, so I had to ran it again and again, using lots of Serial.print to test whether it was working or not, but it was worth it.

Coin system

Every game box had a coin system! So I decided to add one two, I see ultrasonic sensor to sense the coin by distance. I also added a motor under the coin groove like this

This stops the coin and when the sensor senses the coin the motor will open. This stops the coin for roughly 1s, but it ensures that the coin is sensed enery time.

The sensor is attached nearby with you can see on the picture, the sensor is under the white square.

One problem always occur with this system, the sensor sometimes is too sensitive, so it sometimes sensed my motor, to fix this, I made the sense distance really low, it is actually <=1cm, so the job of the motor also is to make sure the coin stops on it so that sensor can sense it.

Box design

I used cardboard, which is really convenient, and I used two cardboards to display the items, I tried my best to write a easy and understandable instructions as you can see. Also I will show you the inside layout, it’s a little bit mess because it is full of wires, but it works.

Another problem:

There was abother big problem occurred when I was making this project. My arduino stopped working because of that(No light was on). I was really stressed, and then I pulled out all the pins and connected it one by one to see which part was broken, eventually it turned out to be the switch’s problem. I did soldering it before, but I still couldn’t figure out why. I fixed it by changing a new switch.

This is the broken switch.

Displaying feedback

Technically, only one small problem occurred, that was a coin slipped to the wires and it created light disorders. All other things went on well. It was played more than 30 times and everything went on well.

However, there was a problem with the interactive part. Although I wrote the instructions, people still seemed hard to understand my game’s rules. I need to explain to them every time. Next time, I must make my explanations easy, such as using pictures or videos. And also, I can improve the game quality to make itself easier.

Lastly, another video of a game player.

Ding Yuhao

29 September 2017

 

 

 

int button;
int t;
int b;
#include "Ultrasonic.h"
#include <Servo.h>

Servo myservo; 
Servo mm; 
Ultrasonic ultrasonic(5);
Ultrasonic money(9);
void setup() {

  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, INPUT); // switch
  myservo.attach(10);
  mm.attach(11);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8,OUTPUT);
  t = 30;
  long RangeInCentimeters;
}

void loop() {
if (t == 30){
    digitalWrite(6, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);

    int dis = money.MeasureInCentimeters();
    Serial.print(dis);
    if (dis<=1){
      Serial.print(dis);
     for (int pos = 0; pos <= 100; pos += 1) { 
        mm.write(pos);          
        delay(5);
      }
      delay(500);
       for (int pos = 100; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
          mm  .write(pos);              // tell servo to go to position in variable 'pos'
          delay(5);                       // waits 15ms for the servo to reach the position
      } 
      digitalWrite(6, HIGH);
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(7, HIGH);
      delay(200);
      digitalWrite(6, LOW);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(8, LOW);
      digitalWrite(7, LOW);
      delay(200);
      digitalWrite(6, HIGH);
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(7, HIGH);
      delay(200);
      digitalWrite(6, LOW);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(8, LOW);
      digitalWrite(7, LOW);
      t=0;
    }
    
}
if (t == 0){
  b = 0;
  int ram = random(1000, 5000);
  digitalWrite(3,LOW);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  delay(400);
  digitalWrite(6, LOW);
  delay(400);
  digitalWrite(6, HIGH);
  delay(700);
  digitalWrite(6, LOW);
  digitalWrite(2, HIGH);
  delay(ram);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  t =1;
}
if (t==1){
   int ramm = random(100, 2000);
   button = digitalRead(4);
   Serial.println(button);
   b = b+1;
   Serial.print(b);
   if (b < 150) {
    b=b+1;
   }else{
    digitalWrite(8,HIGH);
    delay(2000);
    digitalWrite(8,LOW);
    digitalWrite(3,LOW);
    t = 30;
    b=0;
   }
   if (button == HIGH) {
      t = 2;
      digitalWrite(7, HIGH);
      delay(2000);
      digitalWrite(3, LOW);
      digitalWrite(7, LOW);    
    }
}
if (t==2){
  int RangeInCentimeters = ultrasonic.MeasureInCentimeters();
  int ram = random(1000, 5000); 
  digitalWrite(6, HIGH);
  delay(400);
  digitalWrite(6, LOW);
  delay(400);
  digitalWrite(6, HIGH);
  delay(700);
  digitalWrite(6, LOW);
  digitalWrite(2, HIGH);
  Serial.print(b);
  while(RangeInCentimeters < 10 or RangeInCentimeters == 0){
    RangeInCentimeters = ultrasonic.MeasureInCentimeters();
    Serial.print(RangeInCentimeters);
    delay(500);
    digitalWrite(2,LOW);
    delay(200);
    digitalWrite(2,HIGH);
    delay(200);
  }
  RangeInCentimeters = ultrasonic.MeasureInCentimeters();
  while(RangeInCentimeters < 10 or RangeInCentimeters == 0){
    RangeInCentimeters = ultrasonic.MeasureInCentimeters();
    Serial.print(RangeInCentimeters);
    delay(500);
    digitalWrite(2,LOW);
    delay(200);
    digitalWrite(2,HIGH);
    delay(200);
  }
  Serial.print(b);

  RangeInCentimeters = ultrasonic.MeasureInCentimeters();
  while(RangeInCentimeters < 10 or RangeInCentimeters == 0){
    RangeInCentimeters = ultrasonic.MeasureInCentimeters();
    Serial.print(RangeInCentimeters);
    delay(500);
    digitalWrite(2,LOW);
    delay(200);
    digitalWrite(2,HIGH);
    delay(200);
  }
  delay(ram);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  t =3;
  b=0;
    
}
if (t==3){
   int ramm = random(100, 2000);
   button = digitalRead(4);
   Serial.println(button);
   b = b+1;
   Serial.print(b);
   if (b < 250) {
    b=b+1;
   }else{
    digitalWrite(8,HIGH);
    delay(2000);
    digitalWrite(8,LOW);
    digitalWrite(3,LOW);
    t = 30;
    b=0;
   }
   if (button == HIGH) {
      t = 5;
      digitalWrite(7, HIGH);
      delay(2000);
      digitalWrite(3, LOW);
      digitalWrite(7, LOW);    
    }
}
if(t==5){
  digitalWrite(6, HIGH);
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(7, HIGH);
      delay(50);
      digitalWrite(6, LOW);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(8, LOW);
      digitalWrite(7, LOW);
      delay(50);
      digitalWrite(6, HIGH);
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(7, HIGH);
      delay(50);
      digitalWrite(6, LOW);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(8, LOW);
      digitalWrite(7, LOW);
      delay(50);
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(7, HIGH);
      delay(50);
      digitalWrite(6, LOW);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(8, LOW);
      digitalWrite(7, LOW);
      delay(50);
      digitalWrite(6, HIGH);
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(7, HIGH);
      delay(50);
      digitalWrite(6, LOW);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(8, LOW);
      digitalWrite(7, LOW);
      for (int pos = 0; pos <= 180; pos += 1) { 
        myservo.write(pos);          
        delay(7);
      }
      delay(2000);
       for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(7);                       // waits 15ms for the servo to reach the position
      }
      t=30;
}




  delay(1);


  // put your main code here, to run repeatedly:

}

Stupid Pet Trick – Jingyi Zhu (jz2915) 9/29

Project name: Pat the pet

Instructor: Professor Marcela Godoy

My idea for the Stupid Pet Trick:

Making a cat that will interact with the person who pat it. If somebody pats it on the head softly, its eyes will light up, but if he pats it too hard, it will meow to warn him.

Building the circuit:

Materials: an Arduino board, a breadboard, an fsr sensor, two LED lights, a buzzer, a 10k ohm resistor, a 220 ohm resistor, and several cables

To make this pet react to people’s action, I used an fsr sensor to sense the pressure people exert on the pet’s head when they press the sensor.

I connected the two LEDs in serial so that the circuit is simple and the LEDs can light simultaneously. But it would be better if I connect the LEDs in parallel because even if one breaks down, the other can still work.

 the schematic

 the circuit

Unfortunately, I forgot to add a 220 ohm resistor to the LED circuit, so when I tested the code, one of them broke. It is very important to protect the components and the circuit with resistors against too large a electric current or a short circuit.

 the broken LED

Programming:

At first, I wrote the code as ‘”digitalWrite(buzzerPin, HIGH)” to make the buzzer sound.  I found that the buzzer only made a “beep” sound because the function for the buzzer to make proper sounds is tone(), which controls the buzzer to sound a certain tone. The tone value I set would change according to the input value of the fsr sensor.

I connected the LEDs to digital pin 11, but the LEDs wouldn’t light when the buzzer worked properly.  It was because the use of a tone function will interfere with pin 3 and pin 11. So I changed the output pin to pin 10 instead.  Professor Marcela helped me find this out in Arduino documentations.

The digital output of the LEDs was also according to the input value collected by the fsr sensor so that the brightness of the LEDs changed to the force exerted on the sensor.

I then collected data from the serial monitor, to set the threshold value of the analog input that triggers the buzzer. I used an if() function to make the buzzer sound when the input is equal to or greater than 400.

Building the structure:

Materials: a cardboard box, cotton, foam bag and tape.

I cut a narrow gap to pull the fsr sensor out from the inside of the box, so that the breadboard can fit into the box.

I then cut two holes for the LEDs, but it turned out that the LEDs will be detached easily because the cables stands unstably against the upper wall of the box. So I built a support structure inside the box to stable the breadboard.

To make the buzzer heard clearly, I cut a big hole in the middle. But the buzzer is too deep inside the box and the cotton had a good sound-proof effect, in the end, the buzzer couldn’t be easily heard.

Professor Marcela gave me a suggestion that I put the buzzer outside the box to make it heard.

 

 

 

 

 

/* FSR testing sketch.

  Connect one end of FSR to 5V, the other end to Analog 0.
  Then connect one end of a 10K resistor from Analog 0 to ground
  Connect LED from pin 11 through a resistor to ground

  For more information see www.ladyada.net/learn/sensors/fsr.html */

int fsrAnalogPin = 0; // FSR is connected to analog 0
int LEDpin = 10 ;      // connect Red LED to pin 10 (PWM pin)
int fsrReading;      // the analog reading from the FSR resistor divider
int LEDbrightness;
int buzzerPin = 8;
int buzzerVolume;

void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
  pinMode(LEDpin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
}

void loop(void) {
  fsrReading = analogRead(fsrAnalogPin);
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);

  // we'll need to change the range from the analog reading (0-1023) down to the range
  // used by analogWrite (0-255) with map!
   if (fsrReading >=400) {
    // digitalWrite(buzzerPin, HIGH);
    buzzerVolume = fsrReading+400;
    tone(8, buzzerVolume);
    }else{
    noTone(8);
    //digitalWrite(buzzerPin, LOW);
    }
    LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
    // LED gets brighter the harder you press
    analogWrite(LEDpin, LEDbrightness);

  delay(100);
}

Stupid Pet Trick- The Devil’s Treat (Mary Wang)

Stupid Pet Trick- The Devil’s Treat (Mary Wang) 

Date: 9/29/2017

Instructor: Marcela

Designed and produced by Huanci Wang (Mary)

Special thanks to Marcela who helped me with my coding!

Name of the project: The Devil’s Treat

 

Goal: Make people laugh… and eat less candy! Continue reading

#include <Servo.h>
int sensorPin = A0;    // select the input pin for the potentiometer
Servo servoPin;      // select the pin for the servo
int sensorValue = 0;  // variable to store the value coming from the sensor
int val;

void setup() {
  // declare the ledPin as an OUTPUT:
  //pinMode(ledPin, OUTPUT);
  servoPin.attach(10);
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);
   val = analogRead(sensorPin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 250, 350, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  servoPin.write(val);                  // sets the servo position according to the scaled value
  delay(15);  

Stupid Pet Trick (professor: Rudi)

Stupid Pet Trick

By Xizhu Peng

Instructor: Rudi

Materials:

X1 light sensor

X1 servo

X1 breadboard

X1 Arduino Uno board

X1 10k resistor

I have been brainstorming the project for a long time. At first, I wanted to make a tricky umbrella which opens when it’s dry and closes when it’s raining. However, I realized that my own umbrella was too big to operate and the fake umbrellas I found on Taobao which were made by the paper were too soft and fragile. The materials did not match with my idea so I needed to change a little bit. Then I thought about sunglasses. I wanted to make the sunglasses fall on one’s eyes when the sunlight is strong and goes back when the sunlight is weak. There was an outline and I began to think about materials.
At first, I wanted to paper-cut a face and a pair of sunglasses. Then it came out that the face made by paper might not be able to stay stable. So I decided to print out the portrait. I am really a big fan of Captain America and I always think that he is kind of “unequipped” compared with other superheroes. Then I gave the name for my project:
The sunglasses for Captain America.

My outline is to use the servo to change the direction of the sunglasses if the intensity of light is high enough. According to the notes in my kit, I connected the servo first to check if it worked. I used the codes in Arduino examples (servo-sweep).


Then I used the example ambient light in recitation 2. What I wanted to do was to replace the LED by the servo because I want to control the servo move or not but the certain number of the intensity of light. I tried a couple of times and the servo and the light sensor just worked separately. I got confused and asked Louis. He told me that they should be in different circuits and I should use codes to combine them and make the light sensor influence the servo. And professor Rudi told me that the 220 resistor is not needed for the servo.


So I began to look up the notes I take during the previous classes. I learned that I need to use analog read to read the data from A0 which indicates the intensity of the light. I checked the slides and asked professor Moon. Then I knew the pattern:
if (something) {
// do something
myservo.write(90); // angle range = 0 – 90
} else {
myservo.write(0); // angle range = 0 – 90
}

My final step was to deal with the picture of Captain America to make it “stand up”. I used scotch tape to stick the picture onto the surface of the box. And I cut a hole to let the servo go through.

Yesterday night, I made the condition that if the value was bigger than 800, then the servo worked.
However, during today’s stupid pet trick show, I found that the light was weaker than that yesterday. So I put the value 400. Then I found that sometimes the servo stuck in the hole I cut through the box and the paper and somehow made the servo could not rotate 90 degree. I realized that I should have used more tape to fix it.


Through this stupid pet trick, I know that some ideas seem easy to pursue in my mind, however, it is rather for me to realize it in practice. I still have a long long way to go in IMA.

#include <Servo.h>

Servo myservo;

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
}

void loop() {
  int value = analogRead(A0);
  Serial.println(value);

  if ( value>600) {
    // move myservo
     myservo.write(90);  // angle range = 0 - 90  
  } else {
    myservo.write(0);  // angle range = 0 - 90  
  }
  
  delay(1);
}

Recitation-4 Interaction Lab : Stupid Pet Trick

  • Date: 9.29.2017 
  • Instructor: Rudi
  • Documented by: Yian Zhang (Ian)
  • Course: Interaction Lab
  • Thanks for help: Luis, Jack, Nick, Moon, Rudi

This week we worked on our stupid pet tricks. This is the first time I do all the parts myself (with IMA fellow’s help and guidance): coming up with my own idea, designing and making the circuits, writing the codes and testing and improving it. This week I learned more than what I learned in the past 4 weeks.

My Stupid Pet Trick is called”Don’t turn the page!” If one does so, it will automatically turn back and show him or her the words written on the page.

The circuits include an Arduino, a computer, wires, two breadboards, a 4.7k resistor, a servo and a photoresistor. When the page is turned, the photoresistor hidden under the page is exposed to light and will send data back to the computer. Then the computer will control the servo to spin 180 degrees so that the page connected to the servo is turned back.

 

The video

 

The code

Plan for improvement

I plan to work this weekend to hide the servo and the pen to make it more surprising and beautiful. After all audience’s experience is the most important. I am thinking about connecting the servo to the page directly.

 

Update 2017.10.11

I wanted to make the project more beautiful and delicate. I connected the servo to the page directly so that it would seem as if there’s nothing turning the page but instead the page comes back by itself.  Also, when the page comes back, it comes to the page with “Don’t turn the page” written on it, instead of the previous page.

I connected the servo to the page directly so that it would seem as if there’s nothing turning the page but instead the page comes back by itself. But finally, I gave up this idea because then the whole book was shaken fiercely when a page was turned. And this destroyed the paper and might expose the photocell to the light.

But I did improve the project by : using hot glue to connect the servo attachment to the servo to make it stable; replacing the pen with a hand so it’s more fun; fix the servo with hot glue; writing a reminder so that the audience will help turn the page back. Then the next audience can enjoy the project without being confused.