As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Thursday, May 9, 2013

Noble + Gavia // Practice Code and Replacement Parts

Since our parts haven't arrived in the mail yet, we made do with what the Sparkfun Inventor's Kit had.  We used the kit's piezo instead of a larger one, a potentiometer instead of a vibration sensor, a button instead of an infrared remote switch, and base LEDs instead of brighter ones.  I recently bought a larger servo from radioshack for the part where it shoots silly string, but this part of the project was done before then.

I coded the Arduino to arm itself when the button is pressed.  A LED comes on to show that it's armed and if the potentiometer's analog reading reaches a certain value, red LEDs flash on and the piezo makes a buzzing noise.  This code has the basic logic of our system.  The system can be armed or disarmed, and the sensor triggers a reaction once a certain value is detected.



Here's our code:


#define LED_ALARM 13   //Red LEDS on output pin 13
#define LED_ON 12   //Green LED on ouotput pin 12
#define BUTTON 2   //Button switch on input pin 2
#define SENSORPIN 0   //Potentiometer on analog input pin A0
#define BUZZER 11   //Piezo buzzer on output pin 11

int val = 0;   //It's value changes based on whether the button is pressed or not
int old_val = 0;   //Stores the old value of the button so it properly turn on or off
int state = 0;   //State of the button, is it on or off?
int sensorValue;   //Value of the potentiometer

void setup() {                
  pinMode(LED_ALARM, OUTPUT);
  pinMode(LED_ON, OUTPUT);
  pinMode(BUTTON, INPUT);
  pinMode(BUZZER, OUTPUT);
}

void loop() {
   val = digitalRead(BUTTON);   //Sets the value to LOW or HIGH based on the button being pressed or not

   if ((val == HIGH) && (old_val == LOW)){   //Changes the state of the button to on or off
     state = 1 - state;
     delay(10);
   }
   
   old_val = val;   //So we know that we're going from one button state to another when it's pressed
   
   if (state == 1) {   //If the button is pressed the green light comes on and the potentiometer starts to read
     digitalWrite(LED_ON, HIGH);
     sensorValue = analogRead(SENSORPIN);
   } else {
     digitalWrite(LED_ON, LOW);    //If the button isnt pressed then the light is off
   }
   if (sensorValue > 500) {   //If the potentiometer is a certain value, the alarm sounds and the red LEDs flash
      digitalWrite(LED_ALARM, HIGH);
      delay(250);
      digitalWrite(LED_ALARM, LOW);
      delay(250);
      
      buzz(BUZZER, 2500, 500);   //buzz the buzzer on pin 11 at 2500Hz for 500 milliseconds
      delay(1000);
    }
}

void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2;     //calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length/ 1000;    //calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to 
  //// get the total number of cycles to produce
 for (long i=0; i < numCycles; i++){    //for the calculated length of time...
    digitalWrite(targetPin,HIGH);    //write the buzzer pin high to push out the diaphragm
    delayMicroseconds(delayValue);    //wait for the calculated delay value
    digitalWrite(targetPin,LOW);    //write the buzzer pin low to pull back the diaphragm
    delayMicroseconds(delayValue);    //wait again for the calculated delay value
  }
}

Wednesday, May 8, 2013

Randy & Charlie: Microphone

We got our electret microphone to work going off of this schematic: http://www.dtic.upf.edu/~jlozano/interfaces/microphone.html. However it barely picks up any sound at all. We think it's a problem with the op-amp.


/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 
 This example code is in the public domain.
 */

int vibrationPin = 9;
long strength, data;
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(vibrationPin, OUTPUT); 
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  float sensorValue = (float)analogRead(A0);
  // print out the value you read:
  
  strength = (long)voltageToHertz(sensorValue);
  data = (long)voltageToByte(sensorValue);
  Serial.println(sensorValue);
  tone(vibrationPin, strength, 100);
//  String value = String(sensorValue);
//  Serial.write(value);
  delay(2);        // delay in between reads for stability
}

float voltageToHertz(long volts) {
  long value = (float)(180 * ((float)volts / (float)1024));
  if (value > 20) {
    return value;
  } else {
    return 0;
  }
}

float voltageToByte(long volts) {
  long value = (float)(255 * ((float)volts / (float)1024));
  if (value > 20) {
    return value;
  } else {
    return 0;
  }
} 

Randy & Charlie: Vibration Motor with Proximity Sensor

This code is a modified code from a HC-SR04 Tutorial (http://treehouseprojects.ca/ultrasonictutorial/). Using the HC-SR04 sensor to sense the proximity of an object and then activate a vibration motor that vibrates at a rate proportionate to the proximity of the object.

/*

Randy Huynh

This code is a modified code from a HC-SR04 Tutorial 
(http://treehouseprojects.ca/ultrasonictutorial/).
Using the HC-SR04 sensor to sense the proximity of an 
object and then activate a vibration motor that vibrates 
at a rate proportionate to the proximity of the object.

*/
 
//pin which triggers ultrasonic sound
const int pingPin = 13;
 
//pin which delivers time to receive echo using pulseIn()
int inPin = 12;
 
//range in cm which is considered safe to enter, anything
//coming within less than 5 cm triggers red LED
int safeZone = 50;
 
//vibration pin.
int vibrationPin = 9;
 
void setup() {
  // initialize serial communication
  Serial.begin(9600);
}
 
void loop()
{
  //raw duration in milliseconds, cm is the
  //converted amount into a distance
  long duration, cm, strength;
 
  //initializing the pin states
  pinMode(pingPin, OUTPUT);
  pinMode(vibrationPin, OUTPUT); 
 
  //sending the signal, starting with LOW for a clean signal
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
 
  //setting up the input pin, and receiving the duration in
  //microseconds for the sound to bounce off the object infront
  pinMode(inPin, INPUT);
  duration = pulseIn(inPin, HIGH);
 
  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);
 
  //printing the current readings to ther serial display
//  Serial.print(cm);
//  Serial.print("cm");
//  Serial.println();

  strength = (long)centimetersToHertz(cm);
  // Serial.println(strength);
  // Serial.write(strength);
  
  Serial.write((long)centimetersToByte(cm));
  tone(vibrationPin, strength, 100);
  delay(100);
}
 
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;
}

float centimetersToByte(long centimeters) {
  if (centimeters < safeZone && centimeters != 0) {
    return (float)(255 - (255 * ((float)centimeters / (float)50)));
  } else {
    return 0;
  }
} 

float centimetersToHertz(long centimeters) {
  if (centimeters < safeZone && centimeters != 0) {
    return (float)(180 - (180 * ((float)centimeters / (float)safeZone)));
  } else {
    return 0;
  }
} 


Tuesday, May 7, 2013

Houston, We Have Detection

There's something truly exciting about testing ideas and discovering they actually work. Shoot, it's also exciting to test your idea and find out it doesn't work. The beauty lies in the act of trying. We've been muttering about using a PIR Motion Sensor (by Parallax) for a few weeks now, so when we actually took the little bugger out of its packaging, it was our moment of truth.
Being that we are two individuals with little experience (none, actually) when it comes to coding, Arduinos and sensors, this is an extremely intimidating realm to enter into. Thankfully, once again, the internet is our friend, this time in the form of Dave Giancaspro's article on Wired.com. He was creating some kind of motion-triggered, heart-attack-giving halloween decoration. I bet he would be disappointed that we are using his code to take pretty pictures of Hummingbirds.

Anyway.

Thanks to him we had this code:

int motion_1 = 2;int light_1 = 13;void setup(){ pinMode (motion_1,INPUT); pinMode (light_1, OUTPUT);}void loop (){ digitalWrite (light_1,LOW); delay(1000); //this delay is to let the sensor settle down before taking a reading int sensor_1 = digitalRead(motion_1);\ if (sensor_1 == HIGH){ digitalWrite(light_1,HIGH); delay(500); digitalWrite(light_1,LOW); delay(500); }}

Next, plug in a few wires, the sensor, and an LED, and BLAMMO! We now have an LED light that flashes when the motion sensor has been tripped.


=


For our next step, we intend to replace the flashing LED with a remote that trips the camera. Here's to majestic animal imagery in our future!

Steps As Multi-Dimensional Arrays – Mallika Simone, Sarah Churng

Recap:

We are the drunk walking narc team. OurDuino detects drunk walking and does something about it.

Goal:


  • _COLLECT PRESSURE VALUES from stepping, every 30 seconds every 3 minutes
  • _ANALYZE PATTERNS for degradation in pacing over time
  • _RESPOND with a flag if patterns are determined to be "drunk" (More on what this change will be later)

Strategy:



  • _4 FORCE PRESSURE SENSORS, 2 per foot (1 in heel, 1 in ball)
    We will be using the combined value, in order to accommodate for the variance in distributed weight across the foot.
  • _4 ANALOG PINS on Arduino, with conversions of the analog values to scalar values
  • "Phases[0-N]" MULTI-DIMENSIONAL ARRAYS ", one created every 3 minutes.
    Each contains the following information:
    • "LeftInputs" ARRAY, with 60 cells, 1 every 500 ms. for over 30 seconds
    • "RightInputs" ARRAY, with 60 cells, 1 every 500 ms. for over 30 seconds
  • "Weigh" FUNCTION that analyzes each Phase array and returns a statistical weight for the pacing rate
  • "Compare" FUNCTION that compares the statistical weight from sober (early) phases to current phase

Algorithm Psuedocode:


LeftArray;[]
RightArray[];
PhaseArray[][];

void fillFeetArrays {
   read in left sensor values;
   store values in LeftArray;

   read in right sensor values;
   store values in RightArray;
}

void fillPhaseArray {
   every 3 minutes:
      while ( power != OFF ) {
         int n = 0;

         for (halfsecs = 0; halfsecs < 60; halfsecs++) {
             fillFeetArrays;
             store LeftArray and RightArray in PhaseArray[n][];      
         }
         n++;
      }
}

psuedocode for filling the multidimensional arrays


Code:


/*
  AUTHORS: sarah churng; mallika simone
  SUMMARY: Measures the force exerted in walking.
  Reads in analog input via Force Pressure Sensors (FPS) from pins 
  A0 and A1, and maps the results to 2 respective ranges from 0 to 255.
  
  Stores these results to arrays LeftValues and RightValues,
  inside multidimensional arrays LeftFoot and RightFoot, respectively.
  
  CIRCUITS:
1* FPS connected to analog pin A0.
   Center pin of the potentiometer goes to the analog pin.
   side pins of the potentiometer go to +5V and ground
 * LED connected from digital pin 10 to ground

2* FPS connected to analog pin A1.
   Center pin of the potentiometer goes to the analog pin.
   side pins of the potentiometer go to +5V and ground
 * LED connected from digital pin 9 to ground

   USE AND POTENTIAL for the data collected:
 * PACING: as a function of the inputs over time
 * BALANCE: as a comparison between the two inputs' pressure resistances
  
 */


// ANALOG DATA: Left Foot
const int analogInPin1 = A0;                            // Force Pressure Sensor at A0
const int analogOutPin1 = 10;                           // LED at variable pin 10
int sensorValue1 = 0;                                   // value from variable sensor
int outputValue1 = 0;                                   // value from output to analog out

// ANALOG DATA: Right Foot
const int analogInPin2 = A1;                            // Force Pressure Sensor at A1
const int analogOutPin2 = 9;                            // LED at variable pin 9
int sensorValue2 = 0;                                   // value from variable sensor
int outputValue2 = 0;                                   // value from output to analog out

const int StepsPerPass = 10;
int stepCount = 0;

// ARRAYS
int LeftValues[StepsPerPass];
int RightValues[StepsPerPass];


// INITIALIZE serial communications at 9600 bps
void setup(){ 
  Serial.begin(9600);
}

// FILL ARRAYS with pressure values detected
void fillArrays(){
  
  for (stepCount = 0; stepCount < StepsPerPass; stepCount++){
    // READ: analog values
    sensorValue1 = analogRead(analogInPin1);              // Read in input from left foot
    outputValue1 = map(sensorValue1, 0, 1023, 0, 255);    // Map to range of analog 0 - 255
    analogWrite(analogOutPin1, outputValue1);             // Change the analog out value
    LeftValues[stepCount] = outputValue1;
      
    sensorValue2 = analogRead(analogInPin2);              // Read in input from right foot
    outputValue2 = map(sensorValue2, 0, 1023, 0, 255);    // Map to range of analog 0 - 255
    analogWrite(analogOutPin2, outputValue2);             // Change the analog out value
    RightValues[stepCount] = outputValue2;
    
    delay(500);
  }
}

void loop(){
  
  fillArrays();
  
  for (int n = 0; n < StepsPerPass; n++) {
    Serial.print("Left Foot = " );
    Serial.print(LeftValues[n]);
    Serial.print("\t\tRight Foot = " );
    Serial.println(RightValues[n]);
  }

  // Wait 3 minutes to create a new phase cycle
  delay(3000);
  
}

Next steps and things to think about:

  • What's the response type?
    For the actual response to drunk walking, we are considering various social media and technology tools, to signal to friends of the wearer
  • How are people wearing this prototype?
    The arduino and circuits probably have to be housed in a giant belt buckle, with wires  running down each pant leg to the sensors connected in the shoe insoles.

Monday, May 6, 2013

Nick/Mason ~ Readin 'Duinos


This week Nick and I taught our Arduino to read values from a Text file (.txt) to blink LEDs Processing reads the text file in real time, only sending new information to the Arduino. Later we will implement live updating text from a weather source that gives the Arduino weather interpreting capabilities.




The Processing code used is shown below:
import processing.serial.*;
import java.io.*;
int mySwitch=0;
int counter=0;
String [] subtext;
Serial myPort;
void setup(){
//Create a switch that will control the frequency of text file reads.//When mySwitch=1, the program is setup to read the text file.//This is turned off when mySwitch = 0 mySwitch=1;
//Open the serial port for communication with the Arduino//Make sure the COM port is correct myPort = new Serial(this, "COM6", 9600);
myPort.bufferUntil('\n');
}
void draw() {
if (mySwitch>0){
/*The readData function can be found later in the code. This is the call to read a CSV file on the computer hard-drive. */ readData("Users/Nick/SensorData.txt");
/*The following switch prevents continuous reading of the text file, until we are ready to read the file again. */ mySwitch=0;
}
/*Only send new data. This IF statement will allow new data to be sent to the arduino. */if(counter<subtext.length){
/* Write the next number to the Serial port and send it to the Arduino There will be a delay of half a second before the command is sent to turn the LED off : myPort.write('0'); */ myPort.write(subtext[counter]);
delay(500);
myPort.write('0');
delay(100);
//Increment the counter so that the next number is sent to the arduino. counter++;
} else{
//If the text file has run out of numbers, then read the text file again in 5 seconds. delay(5000);
mySwitch=1;
}
}
/* The following function will read from a CSV or TXT file */void readData(String myFileName){
File file=new File(myFileName);
BufferedReader br=null;
try{
br=new BufferedReader(new FileReader(file));
String text=null;
/* keep reading each line until you get to the end of the file */while((text=br.readLine())!=null){
/* Spilt each line up into bits and pieces using a comma as a separator */ subtext = splitTokens(text,",");
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
try {
if (br != null){
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Thursday, May 2, 2013

Enrique & Karin - Week 4

We received our first sensor in the mail late last week. It reads the moisture levels in the soil. This week we wanted to test the sensor by having it detect the water in the soil and provide an analog output.

First we connected three different colored lights to the circuit board. Then we established numerical values for "dry", "moist", and "wet". Lastly we wrote the code that would take the moisture readings and prompt the correlating light to turn on and the one before it to turn off.

Below is a video of what our test looked like:

And this is the code that made it possible:


/*
  # Experiment code for the moisture sensor
  # Editor     : Karin & Enrique
  # Date       : 05.02.2013
  # Version    : 1.0
  # Connect the sensor to the A0(Analog 0) pin on the Arduino board
  # Connect LEDs to pin 13, 8 & 7
  # Give the sensor 5V input

  # the sensor value description
  # 0  ~500     in water
  # 500~700     humid soil
  # 700~1000     dry soil
*/

int green = 13;
int yellow = 8;
int red = 7;

int moistureValue = 0;

void setup(){
  // initialize the digital pins as outputs.
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(red, OUTPUT);

  Serial.begin(9600);
 }

void loop(){
  moistureValue = analogRead(0);
  Serial.print("Moisture Sensor Value: ");
  Serial.println(moistureValue, DEC);
  delay(100);

  //Light red if it's dry
  if (moistureValue >700){
     digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
     digitalWrite(yellow, LOW);   // turn the other LEDs off
     digitalWrite(green, LOW);
  }
  //Light green if it's really wet
  else if(moistureValue < 500){
     digitalWrite(green, HIGH);   // turn the LED on (HIGH is the voltage level)
     digitalWrite(yellow, LOW);  // turn the other LEDs off
     digitalWrite(red, LOW);
  }
  //Light Yellow if it's moist
  else{
    digitalWrite(yellow, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(red, LOW);   // turn the other LEDs off
    digitalWrite(green, LOW);
  }

}