Making Furniture Interactive

September 16, 2007

A Theft-Aware Cabinet

My goal with this assignment was to get something mechanical working. The result was so amusing that I posted a video here, (downloadable and playable by mplayer on a mac).

The Hardware

  • I built a cabinet out of foamcore. It is very hard to cut foamcore in a straight line. The bottom was hollow; I used mounting tape to stick the Arduino and breadboard onto it.chest.jpgtrickbottom.jpg
  • I ran 3 leds up the back of the cabinet, one to each shelf.leds_in_back.jpg
  • A piezo buzzer from RadioShack was mounted onto the bottom with tape.
  • A hobby-motor circuit was constructed on the breadboard, using the tutorial here. Two AA batteries served as the battery source.underneath.jpg
  • A pair of IR emitter/detector LEDs were obtained from RadioShack, added to the breadboard, then poked up through the bottom shelf. The emitter is on a simple power-resister-emitter-ground circuit; it gives off IR. I used a camera to see that it was glowing. The detector connects to an analog pin; I tested what the pin’s value was when the detector was covered vs. open, and found a threshold of 400 worked well.ir.jpg
  • The wiring:wiring1.jpg

What It Does

An object is placed over the detector. The doors to the cabinet are open and the LEDs cycle pleasantly. But! If one steals the object, the LEDs flash warningly and a buzzer goes off. If the object is returned in time (i.e. the detector’s value goes back below the threshold), everything returns to normal. If not, the doors close and the buzzer cycles unendingly. One images that an Indiana Jones attack would be most effective…

The states machine appears in the following diagram:statemachine.jpg

The Software

/* chest of drawers */
/*
0 sleep - LEDs blinking (sleep -> arousal via IR)
1 arousal - LEDSs flash (arousal -> sleep via IR returns, arousal -> attract via IR remains)
2 attract - motor goes (attract -> reward via time)
3 reward - buzzer (sink)
*/

int led1 = 4;
int led2 = 2;
int led3 = 3;
int motor = 9;
int buzzer = 12;
int detector = 0;
int detector_threshold = 400;
int state = 0;
int stateCounter = 0;

void setup() {
pinMode(led1, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(led2, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(led3, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(buzzer, OUTPUT);
}

void loop() {
int detector_value = analogRead(detector);
stateCounter++;
if (state == 3) {
// do nothing
} else if (state == 2) {
state = 3;
} else if (detector_value > detector_threshold) {
if (state == 0) {
state = 1;
stateCounter = 0;
} else if (state == 1 && stateCounter > 10) {
state = 2;
stateCounter = 0;
}
} else if (detector_value < detector_threshold) {
if (state == 1) {
state = 0;
stateCounter = 0;
digitalWrite(buzzer, 0);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
}

if (state == 0) {
int s = stateCounter % 6;
if (s==0)
digitalWrite(led1, HIGH);
if (s==1)
digitalWrite(led2, HIGH);
if (s==2)
digitalWrite(led3, HIGH);
if (s==3)
digitalWrite(led1, LOW);
if (s==4)
digitalWrite(led2, LOW);
if (s==5)
digitalWrite(led3, LOW);
delay(500);
}
if (state == 1) {
int s = stateCounter % 2;
if (s==0) {
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(buzzer, HIGH);
} else if (s==1) {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(buzzer, LOW);
}
delay(300);
}

if (state == 2) {
analogWrite(motor, 255);
delay(6000);
analogWrite(motor, 0);
}

if (state == 3) {
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
delay(4000);
}
}

September 15, 2007

Exercises Three and Four

Exercises three and four go together. The first part (#3) is to build something that has four different interaction behaviors, modes, or “states”. You can build and demonstrate the behaviors separately, they don’t need to work together at one time. The second part (#4) is to link them together with “transitions” that, when triggered, move the object from one state or behavior mode to another. The details of these two exercises are explained in the PDF here:
state-machine_exercise.pdf

Part One (Exercise 3) Due Sept 18 (Tuesday) at midnight.

Part Two (Exercise 4) Due Sept 25 (Tuesday) at midnight.

September 14, 2007

Category for the Four States assignment

Filed under: Exercise 3: Four States — jet @ 9:41 am

Here’s the category for Exercise 3, “Four States”.

Your submission should be able to exhibit each of four states.  It does not have to transition between states automatically.  For example, you are allowed to write four different programs, each of which exhibits a single state; or you can have all four in one program and exhibit a state, sleep for a couple of seconds, exhibit the next, and so on.

The four states are:

  • sleep
  • attract
  • on/active
  • reward
« Previous Page

Blog at WordPress.com.