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.

Tuesday, June 11, 2013

Sensor experimentation [Maddie and Candice ]

Based on the design situation we wanted to pursue, we were happy to read about a motion sensor that was pretty cheap and easily accessible (at RadioShack on the Ave, yay!). We looked online for codes that would work for our situation, and what we found was code that made a Nikon D80 take a picture when motion was detected from a PIR.

This is how the system worked:
1. Motion is detected from the Parallax PIR sensor
2. The Infrared (IR) LED lights up (as can be monitored by a regular LED lighting up as well)
3. The IR sensor on the camera detects the waveform from the IR LED light
4. IR sensor triggers the shutter on the Nikon D80
5. A picture is taken


We found the code from someone on the intertubes called Steven Holland (http://stratigrafia.org/blog/entries/2012-09-01.html), who customized their code from someone else.

// Based on http://luckylarry.co.uk/arduino-projects/arduino-motion-triggered-camera/
// The sequence of pulses needed appears to have been reverse engineered at http://www.bigmike.it/ircontrol/
// This is another useful site on the subject: http://www.bemasher.net/archives/114

int pirPin = 4; // digital pin 4 for PIR; put a 10k Ohm resistor between pin 4 and OUT on PIR
int ledPin = 13; // digital pin 13 for LED; put a 220 Ohm resistor between pin 13 and the LED
int IRPin = 2; // assign the Infrared emitter/ diode to pin 2; connect other lead of IR diode into ground
int noMotion = 1;

// pulse the infrared emitter for a specified duration (in microseconds)
void pulseON(int pulseDuration) {
unsigned long endPulse = micros() + pulseDuration; // calculate time when pulse should stop
int halfCycle = 13; // half a clock cycle for a 38 Khz (26.32 microseconds period) wave
while(micros() < endPulse) {
digitalWrite(IRPin, HIGH); // emit IR for half a cycle
delayMicroseconds(halfCycle);
digitalWrite(IRPin, LOW); // stop emitting for half a cycle
delayMicroseconds(halfCycle);
}
}

// stop pulsing the infrared emitter for a specified duration (in microseconds)
void pulseOFF(unsigned long delayDuration) {
unsigned long endDelay = micros() + delayDuration; // calculate time when delay is over
while(micros() < endDelay);
}

// sequence of pulses for taking a picture on a Nikon D80 camera
void takePicture() {
for (int i=0; i<2; i++) {
pulseON(2000); // pulse for 2000 microseconds,
pulseOFF(27850); // then off for 27850 microseconds,
pulseON(390); // on for 390 microseconds, and so on
pulseOFF(1580);
pulseON(410);
pulseOFF(3580);
pulseON(400);
pulseOFF(63200);
} // loop the signal twice.
}

void setup() {
pinMode(pirPin, INPUT); // set PIR pin as input
pinMode(ledPin, OUTPUT); // set LED pin as output
pinMode(IRPin, OUTPUT); // set pin as output
}

void loop() {
if(digitalRead(pirPin) == HIGH) {
// motion detected
if (noMotion == 0) {
// take picture only if coming from a state of no motion
digitalWrite(ledPin, HIGH);
takePicture();
noMotion=1;
delay(5000); // wait 5 seconds between pictures
}
} else if(digitalRead(pirPin) == LOW) {
// No motion
digitalWrite(ledPin, LOW);
noMotion=0;
}
}

We found all the components we needed for this experiment on RadioShack, with the exception of the Arduino board and breadboard, which we bought online at Amazon.

- An Arduino board
- A small breadboard
- Parallax PIR sensor #555-28027-RT
- Infrared LED, such as Radio Shack 276-0143
- An LED
- A 220 Ω resistor
- A 10 kΩ resistor
- 22-gauge wire jumpers


Maddie + Candice // Final Video





Here is our video demonstration of the Arduino-powered motion-sensing bubble machine in action. Using a PIR sensor connected to an electronic toy called "The One and Only Gazillion Bubbles" we set up the bubble machine inside a small room where users would enter and activate the motion sensor. 










int pirPin = 4; // digital pin 4 for PIR; put a 10k Ohm resistor between pin 4 and OUT on PIR
int ledPin = 7; // digital pin 13 for LED; put a 220 Ohm resistor between pin 13 and the LED
int noMotion = 1;
int TIP120pin = 9; //for this project, I pick Arduino's PMW pin 11
void setup() {
pinMode(pirPin, INPUT); // set PIR pin as input
pinMode(ledPin, OUTPUT); // set LED pin as output
pinMode(TIP120pin, OUTPUT); // Set pin for output to control TIP120 Base pin
}
void loop() {
int movementSensor=digitalRead(pirPin);

if(movementSensor == HIGH) {
// motion detected
if (noMotion == 0) {
// make bubbles only if coming from a state of no motion
digitalWrite(TIP120pin, HIGH);
digitalWrite(ledPin, HIGH);

noMotion=1;
}
} else {
// No motion
digitalWrite(TIP120pin, LOW);
digitalWrite(ledPin, LOW);
noMotion=0;
}
}

Design Situation [Maddie and Candice]

Home security is a serious problem. According to a report released by the FBI in 2012, property crimes account for an estimated losses of $156.6 billion in the US.

This very interesting inforgraphic from asecurelife.com.



Maddie and I want to create a simple security system using Arduino, a motion sensor, a camera, and a place to store the images captured.


Dan | Stephen //Video

OUR VIDEO

https://vimeo.com/68107448 

Flushing Forests


Dan | Stephen// The Final Countdown

Captain's Log, Stardate: 91048.43


Our project, Flushing Forests is designed to help put an end to excessive toilet paper use. We use a fairly simple input and feedback system to alert the user to when they use too much paper. The Arduino Uno reads the length of paper used each time a person pulls from it. This is done with a wheel that spins with the paper. Tabs on the wheel, presses a lever switch and number of clicks it makes corresponds to the number of squares used. Each attempt to pull paper, has a maximum amount allotted. Audio feedback is played for each square of paper, with an error sound each time they go over the limit. Through our research, we found that people will go for multiple pulls of paper for various reasons. To account for this, we allow multiple pulls of paper, but reduce the maximum limit by 1 for each consecutive pull, beginning with 6 squares, then down to 2 squares indefinitely.

#include "SimpleSDAudio.h"

/*
Authors: Dan Doan and Stephen Bader
Credits: Code heavily adapted from:


Description: Uses a piezo speaker, mouse click wheel, SD card shield, and lever switch to play audio based on 
             squares of toilet paper used.
*/

const int  buttonPin = 6;    // the pin that the pushbutton is attached to
const int speaker = 9;       // the pin that the LED is attached to


// Variables will change:
int clicks = 0;  //counter for the number of button presses
int sheets = 0;  //counter for number of sheets used
int sheetsMax = 6;  //sheetsmax sets the most amount of sheets you can use before the alarm goes off
int buttonState = 0;  //current state of the button
int lastButtonState = 0;  //previous state of the button
boolean pulled = false;  //Records if paper pull has happened
unsigned long pullTime; //Time since the last pull


void setup() {
  Serial.begin(9600);
  Serial.println("H E L L O W O R L D !");
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(speaker, OUTPUT);
  // initialize serial communication:
  
  SdPlay.setSDCSPin(10);
  SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_STEREO | SSDA_MODE_AUTOWORKER);
}

void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    pullTime = millis();  //Records when paper pulling starts
    pulled = true;  //Records if they start pulling paper
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      clicks++;
    } 
  }
  
  lastButtonState = buttonState;  //saves the current state as the last state for next run through the loop
 
  if(clicks == 3) {  //Convert number of clicks to sheets
    clicks = 0;
    sheets++;  //3 clicks = 1 sheet
    Serial.print("sheets:  ");
    Serial.println(sheets);
    
    //Selects the audio corresponding to the number of sheets used
    if (sheets == 1) {    
      SdPlay.setFile("1.wav"); 
    }
    if (sheets == 2) {    
      SdPlay.setFile("2.wav"); 
    }
    if (sheets == 3) {    
      SdPlay.setFile("3.wav"); 
    }
    if (sheets == 4) {    
      SdPlay.setFile("4.wav"); 
    }
    if (sheets == 5) {    
      SdPlay.setFile("5.wav"); 
    }
    if (sheets == 6) {    
      SdPlay.setFile("6.wav"); 
    }
    
    if (sheets > sheetsMax) {  // Anything over the max sheets gets an error sound
      Serial.println("STOP!");
      SdPlay.setFile("ERROR.wav"); 
    }
    
    SdPlay.play();
  } 
  
  //Tracks time between pulls
  if(pulled == true && millis() - pullTime >= 6000) {  // Checks if a pull has happened and lets 6 seconds pull
      pullTime = millis();
      pulled = false;
      clicks = 0;  // Resets clicks and sheets for the next pull
      sheets = 0; 
      if (sheetsMax > 2) {  //This stops sheetsMax from going lower than 2 sheets
        sheetsMax--;  //Decreases max allowed sheets for next pull
        Serial.print("sheetsMax is now: ");
        Serial.println(sheetsMax);
      }
  }
}




Dan | Stephen //Actuator

After experimenting with different input methods for our project, we had an amazing breakthrough! We started looking at "sexy" solutions, like an Optical Finger Navigation module: (http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/ProductID/715/List/1/Default.aspx), various computer mice, and an infrared emitter and detector. For different reasons, they just didn't work. We dealt with out of date code, unreliable readings, and human error (we lost the OFN module :( ). We went back to researching different ways to read RPMs for a disk. Inspired by the game show Wheel of Fortune, we ended up getting a lever switch: (http://www.radioshack.com/product/index.jsp?productId=2049719). We adapted our spinning wheel to click down the switch and had the Arduino record then convert the number of clicks to sheets of paper. The part itself doesn't come with much documentation, so it took a lot of trial and error to figure out the ground, power, and data prongs on the bottom, (that's NC, NO, and C respectively).

To test it, there's a handy preloaded example, which is documented below:

/*
  State change detection (edge detection)
 
 Often, you don't need to know the state of a digital input all the time,
 but you just need to know when the input changes from one state to another.
 For example, you want to know when a button goes from OFF to ON.  This is called
 state change detection, or edge detection.
 
 This example shows how to detect when a button or button changes from off to on
 and on to off.
 
 The circuit:
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 * LED attached from pin 13 to ground (or use the built-in LED on
   most Arduino boards)
 
 created  27 Sep 2005
 modified 30 Aug 2011
 by Tom Igoe

This example code is in the public domain.
 
 
 */

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    } 
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off"); 
    }
  }
  // save the current state as the last state, 
  //for next time through the loop
  lastButtonState = buttonState;

  
  // turns on the LED every four button pushes by 
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of 
  // the division of two numbers:
  if (buttonPushCounter % 4 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }
  
}




We took a couple of different approaches as I have referenced in previous posts about the kind of actuator we may use to measure the length of a sheet of toilet paper to trigger a specific noise. An optical lens from a mouse, a optical touch pad, inferred sensors among ones we tried and failed to get working.

The one we were able to get to work was a relay lever. The relay lever understand data each time it is clicked similar to how the "Wheel of Fortune" wheel spins and clicks, we have a wheel with three attached tabs that spin when toilet paper is pulled and click agains the lever. We were able to do the math to estimate that every three clicks of a .75inch diameter wheel is approximately one sheet of toilet paper pulled which then lets the Arduino know to play a sound.

The Arduino keeps track of each pull of the paper by using a 5 second delay (account for wipe time) and then reducing the amount of toilet paper allowed before negative noise the next time. This continues until two sheets and stays indefinitely until there is a break of one minute (time for next person to use the bathroom and begin wiping. 



Dan | Stephen//Music and Shields and Problems and Stuff

Part of the solution to our problem is that we want audio output. We were successful in creating "beeps and boops" using the Arduino and a Piezzo speaker but to gain more attention from our targeted audience it is important to us to use more developed sounds.

The first music shield that we worked with was one from Seeed studios which we ran into many problems with. It came put together fully, but did not come with compatible libraries with the UNO version of the Arduino. After many hours of searching for help, trial and error, and no success we found a different music shield we thought might work...

It got lost in the mail....

We worked on making changes to this, but were unsuccessful in our attempts and in our attempts to reach out to people that may know on message boards. (This is an un adjusted version)



Here is some process of the first shield we worked with.




We then moved on to trying to get .wav files that could be small enough to actually exist on the Arduino itself. We were able to get some basic small .wav files to play from a speaker and store in the Arduino but we still could not compress the sounds we actually wanted to fit in the small memore so we got a SD card shield.

We still have trouble compressing the files into 8bit audio .wav files. Before we got them to work properly they could begin to play and then make awful noises, but in the end got them to work. We downloaded the sound from http://www.freesound.org/people/LocalTalkRadio/sounds/118443/





Our code looked like this: 


/*
 SimpleSDAudio absolute minimum example, plays file EXAMPLE.AFM from root folder of SD card (CS on pin 4)
 through speaker/amplifier at pin 9 for ATmega328 / pin 44 for ATmega1280/2560.
 */
#include <SimpleSDAudio.h>
void setup()
{ 
  // SdPlay.setSDCSPin(10); // Enable if your SD card CS-Pin is not at Pin 4... 
  SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER);
  SdPlay.setFile("EXAMPLE.AFM"); 
  SdPlay.play();
}

void loop(void) {
}