[Ix Lab AW] Lab 3 Linda Yao

  • Lab Date: 9/23/2016
  • Documentation Date: 9/26/2016
  • Documented by: Linda Yao
  • Instructor: Antonius Wiriadjaja
  • Partner:   –

I first started with playing with the basic shapes and lines. screen-shot-2016-09-23-at-12-11-28-pmscreen-shot-2016-09-23-at-12-06-45-pm

Later I worked with the bouncy ball codes and personalized it to my liking and learned about vectors. Results are shown in the gif below:

ezgif-com-video-to-gif

 

 

 

 

 

 

Through this lab I learned a lot about how to manipulate codes to get the desired outcome. After getting the starting code which was

PVector location;  // Location of shape
PVector velocity;  // Velocity of shape
PVector gravity;   // Gravity acts at the shape's acceleration

void setup() {
  size(640,360);
  location = new PVector(100,100);
  velocity = new PVector(1.5,2.1);
  gravity = new PVector(0,0.2);

}

void draw() {
  background(0);
  
  // Add velocity to the location.
  location.add(velocity);
  // Add gravity to velocity
  velocity.add(gravity);
  
  // Bounce off edges
  if ((location.x > width) || (location.x < 0)) {
    velocity.x = velocity.x * -1;
  }
  if (location.y > height) {
    // We're reducing velocity ever so slightly 
    // when it hits the bottom of the window
    velocity.y = velocity.y * -0.95; 
    location.y = height;
  }

  // Display circle at location vector
  stroke(255);
  strokeWeight(2);
  fill(127);
  ellipse(location.x,location.y,48,48);
}

After playing around I realized by changing the velocity and the variables that interacts with the velocity I could change the speed and how high the ball goes. As vectors also acts as variable, it controls the position of the ball.

Later on I personalized the void setup and

void setup() {
size(640, 540);
location = new PVector(0, 0);
velocity = new PVector(3, 3);
gravity = new PVector(0, 0.2);
}

void draw() {

background(0);
stroke(255);
strokeWeight(2);
fill(random(200), random(200), random(200));
ellipse(location.x, location.y, 50, 50);

}

Also after talking to Antonius, I learned how to restrict the ball from escaping the background.

if (location.y >height) { //|| location.y <= 0
velocity.y = velocity.y * -1; // exponential neg
} else if (location.y <=0) {
velocity.y = 3; //resets

By adding adding this code, I rested the ball to its original velocity overtime it reaches the max Y value which makes the ball bounce back when it hits the ceiling.  Since we haven’t learned this in class yet I want to experiment with the different types of code to create the same bouncing ball using other type of codes.

PVector location;
PVector velocity;
PVector gravity;

void setup() {
  size(640, 540);
  location = new PVector(0, 0);
  velocity = new PVector(3, 3);
  gravity = new PVector(0, 0.2);
}

void draw() {

  background(0);
  stroke(255);
  strokeWeight(2);
  fill(random(200), random(200), random(200));
  ellipse(location.x, location.y, 50, 50);


  //  if (location.y>0) {
  location.add(velocity); //add velocity to location
  //  }
  velocity.add(gravity); //add gravity to velocity
  //bounce off edges
  if ((location.x >width) || (location.x < 0)) {
    velocity.x = velocity.x * -1;
  }
  if (location.y >height) { //|| location.y <= 0
    velocity.y = velocity.y * -1; // exponential neg
  } else if (location.y <=0) {
    velocity.y = 3; //resets
  }
}

Vinduino – Jimmy

Vinduino is a open source project that utilizes Arduino and facilitates agricultural irrigation by using water in a more efficient way. This is extremely useful to farmers, especially in southern California because a severe drought and water shortage are affecting the agricultural production right now. Surprisingly, this farmer operating the project has managed to save 430,000 gallons of water, essentially cutting his water usage by twenty five percent!

Beforehand, the pivotal problem in irrigation was the uneven water distribution. Previously, the single sensor would detect the water but would be too late and there is more water than the plant can consume. The excess water is then seeped below the root zone, taking with it unused nutrients and precious water. By using multiple sensors, most likely three, you can precisely measure the water so that it will not exceed the active root zone. The Vinduino R3 system utilizes timers, solar battery charger, soil moisture sensors, Wifi module, irrigation valve control, and temperature or humidity sensors.

This layered, sensory system will grant access superb water efficiency, low cost of investment, and relatively easy installation. With the modern age increasingly depending on Internet usage, this concept is applicable to agriculture as well. The automated irrigation adjustment via Internet control is one of those applications.

Lab 4 (Sept 30th)

Date: Sept. 30th, 2016
Documented on: Sept. 30th, 2016
Documented by: Lily Mark
Instructor: Luisa
Partner: Tisa Segovic

This week’s lab was all about sensors! Our goal was to connect a sensor to through Arduino to control an output. The sensor we got was the distance sensor for 10-80cm and the output we chose to use was a (green) LED light.

The first step we took was hook up our sensor and observe it through the serial output to make sure it was working properly.

img_5572

Once we confirmed that, we set up the hardware to make sure out LED worked properly as well.
Once both of our components were working independently, we needed to connect them so that the sensor was controlling that output, almost the way a button would.

img_5573
We moved the power to come from pin2 and then added into our code to only send power to pin2 if the sensor was within a certain range.

This was our final product:

14513726_1419690831393570_369797108_o

 

 

 

[Ix Lab AW] -Lab 4 – (Non)Functioning Sensors – Selma

Today’s lab was…. interesting to say at least. What started off as a simple assignment of connecting a sensor to a circuit, and playing around with it became a chaotic attempt to figure out how are things supposed to be connected, and how to make them work.

From all of the choices we had, i really wanted to try out the moisture sensor – I found it particularly interesting because humidity generally makes me sick and gives me bad headaches, and I wanted to figure out if I could put it to some personal use. However, as I came to request it, I heard a disappointing response – 没有。Alright, choice no. 2 – vibration sensor. I went through the checkout process, came back to my seat and just as i opened the bag i realised my sensor was broken. So I had to move on to choice number 3, which, if we are going to be honest, was not a choice, but pure circumstance. By the time it was my turn to take out a sensor, only a bunch of accelerometers were left, so I took out one, came back to my seat, made sure all the components were attached and started looking up how to connect it.

The sensor had 4 pins, ground, VCC, SDA and SCL. WHAAT? What do those three even represent?! Every website I stumbled upon used a different type of board or a different model of accelerometer – I had an insanely hard time finding anything useful, including just a sample code I could use. I asked one of the professors to help me out, and he directed me to GitHub. There, I found a sample code and a sketch, but, surprise surprise, it was using a different board. So, after 15 minutes of searching and attempting to figure it out, I asked one of the fellows to help me out and we finally managed to find a relevant article online on how to connect the sensor to arduino uno.

However, since I still did not have a sample code I knew would give me the right results, I realised I should change the sensor as I still could not understand how this one works.  So I went to one of the fellows, and asked for any other sensor – luckily someone had just returned an IR Ranger 20-150 and I was able to take that. It is important to mention that at this point, there were only about 20 minutes of lab left. As I opened my sensor, another surprise was waiting for me – the wire that comes with it was not there. Hence, i tried connecting it using F/M wires, but the pins were too wide and three could not fit, so I asked one of the fellows for the wire that comes with it. I got it, but the colour code of the wires was not matching one of the instructions I found online. As you can see in the image below, ground wire comes out of the middle pin, but on the wire I was provided by one of the fellows, the ground was the one on the furthest left.

Desperate to get something to work, I asked one of the professors how I could connect the sensor to my Arduino board and he told me to follow the colour code of the wires meaning, the furthest left was to be connected to ground, the middle to 5V and the right one to A1. I did so, and copied the code pasted below, but my Arduino program could not upload it as it could not see my port. I tried restarting the program, disconnecting and connecting my board, I even restarted my computer, but no change. Port was just as invisible as before.

But then it occurred to me that I should switch my power and ground wires, and guess what? Arduino finally managed to upload my sketch and the program started working! WOOHOOO! There was not a happier person in the room, but that happiness was not long lasting. At that moment, fellows started calling out for us to return the sensors as it was already 12.30pm and it hit me that within 75 minutes, the only thing I managed to do was connect three wires….

Hence, during this class, I was unfortunately not able to create anything significant, but I learnt that I should always follow diagrams and that I do not need to restart my computer if the port is not showing.

Here are all the links I tried out for figuring out how the accelerometer works:

Links for Sharp IR Ranger:

The Code for the IR Ranger (the one that worked):

#include <SharpIR.h>

#define ir A1
#define model 20150

boolean done=false;
SharpIR sharp(ir, 25, 93, model);

// ir: the pin where your sensor is attached
// 25: the number of readings the library will make before calculating a mean distance
// 93: the difference between two consecutive measurements to be taken as valid
// model: an int that determines your sensor: 1080 for GP2Y0A21Y
// 20150 for GP2Y0A02Y
// (working distance range according to the datasheets)

void setup(){

Serial.begin(9600);
pinMode (ir, INPUT);

}

void loop(){

delay(2000); // it gives you time to open the serial monitor after you upload the sketch

if (done==false){ // it only runs the loop once

unsigned long pepe1=millis(); // takes the time before the loop on the library begins
int dis=sharp.distance(); // this returns the distance to the object you’re measuring
Serial.print(“Mean distance: “); // returns it to the serial monitor
Serial.println(dis);

unsigned long pepe2=millis()-pepe1; // the following gives you the time taken to get the measurement
Serial.print(“Time taken (ms): “);
Serial.println(pepe2);
done=true;

}

}

Sherry Zhuang: Interaction Lab 4 Report/Professor Mikesell

In today’s lab, we experimented with two Arduino sensors, the distance sensor and the accelerometer sensor.

For the distance sensor, we connected it to Arduino with three wires (red to power, black to ground and blue to input pin 0).

img_6519

The sensor detects the distance between any object and the distance sensor. In the serial monitor, we actually get two values. The first one is the value read from the analog input. In the source code, there is a function where the first value is modified by an equation that gives us a second value. And this second value is a better estimation of distance.

Then, we wanted to use this sensor to control a LED light. We plugged the light on pin 13 and set the conditions that if the distance is lower than 100, the LED will be on.

img_6530

Here is the video,

img_6532

We also tested with the accelerometer sensor. After downloading the accelerometer library in Arduino and getting the sample code, we wanted to plug in the sensor. The pins were a little bit confusing at first, but later with the help of the instructor, we figured them out. (Red to power, black to ground, white to A4 and yellow to A5)

The accelerometer sensor gives us three values in the serial monitor and the three values are related to the acceleration in each axis. (can be used in tilting)

Here is the video,

img_6527

 

#define pin A0
 
void setup () {
    Serial.begin (9600);
    pinMode (pin, INPUT);
    pinMode (13,OUTPUT);
}
 
void loop () {
    uint16_t value = analogRead (pin);
    uint16_t range = get_gp2d12 (value);
    Serial.println (value);
    Serial.print (range);
    Serial.println (" mm");
    Serial.println ();
    delay (500);
    if (range<100){
     digitalWrite(13,HIGH);
 }
 else{
  digitalWrite(13,LOW);
 }
 
 
}
 
uint16_t get_gp2d12 (uint16_t value) {
    if (value < 10) value = 10;
    return ((67870.0 / (value - 3.0)) - 40.0);




}

Grass Work Update – Jimmy

13

First, we prepared the soil by mixing it in with grass seeds. I designed my project so that each soil pocket would be larger in size than the one before it; essentially, it was a line of pouches that grew in size from one end to the other. I tightened the knots between each pouch with some rubber bands. We then moved our project to the farm room and gave it plenty of water.

2 4

The left picture is from Tuesday 9/27 and the right one is from 9/29 Thursday. The grass have been growing considerably however there have been mold problems at the bottom of the pouch where it touches the wet surface of the white plastic board. It has been relatively easy growing the grass. Each class I’ve been just giving the pouches plenty of water individually.

 

Interaction lab-05-XY- Huiyan Sang Grove Ultrasonic Ranger + Arduino

Date: Sept. 29th, 2016
Documented on: Sept. 30th, 2016
Documented by: Huiyan Sang
Instructor: XY, Feng
Partner: Yaqi Wang

In this lab, we combine the ultrasonic ranger with Arduino. We use the example of the sensor and add a ledPin and use analogWrite() to control its light. The Grove-ultrasonic sensor is a non-contact distance measurement module which is compatible with the Grove system. By measuring the distance from the object, it could control our target according to our coding. We also use the map() to define the range of our values so that it could change smoothly.

video:lab5

const int pingPin = 7;
int ledPin = 10;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

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();

  delay(100);

  analogWrite(10, map(cm, 0, 200, 0, 255));

}

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;
}

Lab 4/Daniel Mikesell/Ultrasonic Sensor/Ruoxiao Yu

For this lab, I chose the ultrasonic sensor. I wanted to have the LED and buzzer on when the value from the sensor was less than 50cm.

Here is my code.

[code]
/* 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

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

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

This example code is in the public domain.

*/

// this constant won’t change. It’s the pin number
// of the sensor’s output:
const int pingPin = 7;
float sinVal;
int toneVal;

void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(4,OUTPUT);
pinMode(8,OUTPUT);

}

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();
if (cm<50){
digitalWrite(4,HIGH);
for(int x=0; x<180; x++){
sinVal = (sin(x*(3.1412/180)));
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
delay(2);
}

}
else{
digitalWrite(4,LOW);
noTone(8);
}
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;
}
[/code]

Firstly, I connected the sensor with Arduino to see if it was working. And it was, I got the value from the sensor.

fullsizerender

Then I added an LED and a buzzer to it. The LED and the buzzer was in serial at first, but only the LED was on.

fullsizerender-2

I thought it might be the voltage problem. So I changed them into parallel, yet the buzzer was still not working. I then used respective pins for them, still not working.

I checked my code and asked for help. And it turned out that my code for the buzzer wasn’t right. The buzzer needs PWM, but I just used HIGH and LOW to control it. So I fixed my code and both of them would be on when the value from the sensor was less than 50cm.

 

Lab 4/ Alexis Zerafa/ Daniel

Today I chose to try and get the Grove 3-Axis Accelerometer to control a multiple color LED light.

It worked after some code tweaking but you have to shake the accelerometer really hard.

 

Here is my code

#include <Wire.h>
#include <ADXL345.h>
int redPin = 9; // the pin that the red LED is attached to
int greenPin = 10; // the pin that the green LED is attached to
int bluePin = 11; // the pin that the blue LED is attached to
ADXL345 adxl; //variable adxl is an instance of the ADXL345 library

void setup(){
Serial.begin(9600);
adxl.powerOn();

//set activity/ inactivity thresholds (0-255)
adxl.setActivityThreshold(75); //62.5mg per increment
adxl.setInactivityThreshold(75); //62.5mg per increment
adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?

//look of activity movement on this axes – 1 == on; 0 == off
adxl.setActivityX(1);
adxl.setActivityY(1);
adxl.setActivityZ(1);

//look of inactivity movement on this axes – 1 == on; 0 == off
adxl.setInactivityX(1);
adxl.setInactivityY(1);
adxl.setInactivityZ(1);

//look of tap movement on this axes – 1 == on; 0 == off
adxl.setTapDetectionOnX(0);
adxl.setTapDetectionOnY(0);
adxl.setTapDetectionOnZ(1);

//set values for what is a tap, and what is a double tap (0-255)
adxl.setTapThreshold(50); //62.5mg per increment
adxl.setTapDuration(15); //625us per increment
adxl.setDoubleTapLatency(80); //1.25ms per increment
adxl.setDoubleTapWindow(200); //1.25ms per increment

//set values for what is considered freefall (0-255)
adxl.setFreeFallThreshold(7); //(5 – 9) recommended – 62.5mg per increment
adxl.setFreeFallDuration(45); //(20 – 70) recommended – 5ms per increment

//setting all interrupts to take place on int pin 1
//I had issues with int pin 2, was unable to reset it
adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN );

//register interrupt actions – 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1);
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);

pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop(){

//Boring accelerometer stuff
int x,y,z;
adxl.readXYZ(&x, &y, &z); //read the accelerometer values and store them in variables x,y,z
// Output x,y,z values
Serial.print(“values of X , Y , Z: “);
Serial.print(x);
Serial.print(” , “);
Serial.print(y);
Serial.print(” , “);
Serial.println(z);

double xyz[3];
double ax,ay,az;
adxl.getAcceleration(xyz);
ax = xyz[0];
ay = xyz[1];
az = xyz[2];
Serial.print(“X=”);
Serial.print(ax);
Serial.println(” g”);
Serial.print(“Y=”);
Serial.print(ay);
Serial.println(” g”);
Serial.print(“Z=”);
Serial.println(az);
Serial.println(” g”);
Serial.println(“**********************”);
delay(500);

int valx = (int)map(ax, -1, 1, 0, 255);
int valy = (int)map(ay, -1, 1, 0, 255);
int valz = (int)map(az, -1, 1, 0, 255);
colorRGB(valx,valy,valz);
delay(100);
}
void colorRGB(int red, int green, int blue){
analogWrite(redPin,constrain(red,0,255));
analogWrite(greenPin,constrain(green,0,255));
analogWrite(bluePin,constrain(blue,0,255));
}

 

And here’s the result

img_7983 img_7985 img_7979

ZZ – Response to Vinduino | Week #5

I am surprised to see how accurate the sensor made of gypsum and water is when the moisture is above 50%, but when the moisture is not as high, two out of six sensors’s accuracy dramatically decreased. The idea of having three sensors though I am not sure if it will actually save water since there are so many other aspects we need to consider such as the distance between sensors determined by the root situation, and the soil condition. I personally doubt the 25% water to be saved isn’t that practical. The advantage of using Vinduino that will have a more consistent moisture soil for the plant definitely exists, and this might be helpful for the growth of the plant.