Month: September 2017

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”.

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
}

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.

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 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.

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.

Stupid pet trick — A silly game box

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.

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

the red light blink for 2 times

the yellow light is on for 1s

After random seconds(1-5s), the green light is on, and the player have to press the button

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.

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.

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.

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.

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.

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.

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.