Making Furniture Interactive

September 28, 2007

Example of subroutines in Arduino

Filed under: Course Materials,Examples — jet @ 3:42 pm

A simple example of an Arduino sketch that uses subroutines.

/* subroutine_demo.

The basics of subroutines in Arduino, this is no substitute for the
real documentation.
*/

int minReadPin = 1;                // the first pin we're reading
int maxReadPin = 8;                // the highest pin we're reading

int minLedPin = 9;
int maxLedPin = 11;
int redLedPin = 9;
int blueLedPin = 10;
int greenLedPin = 11;

void setup() {                    // run once, when the sketch starts
pinMode(redLedPin, OUTPUT);      // sets the digital pin as output
}

// a subroutine with no arguments
// turn all the LEDs off
void LedAllOff() {
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, LOW);
digitalWrite(greenLedPin, LOW);

}

// a subroutine with two arguments
void LedOn(int pin, int duration) {
digitalWrite(pin, HIGH);   // sets the LED on
delay(duration);                  // waits for a second
digitalWrite(pin, LOW);    // sets the LED off
}

// a subroutine that returns a value using a loop
bool AreAnyPinsTrue()  {

// start with minReadPin and go to maxReadPin, checking each pin
for (int i = minReadPin; i <= maxReadPin; i++) {
// make sure we're in read mode.
pinMode(i, INPUT);
int i = digitalRead(i);
if (i > 0) {
return true;
}

/* or we can be the cool c hacker:
if(digitalRead(i)) {
return true;
}
*/
}
// if we didn't find any pins on, then return false by default
return false;
}

void loop()                     // run over and over again
{
LedAllOff();
if (AreAnyPinsTrue() == true) {
LedOn(redLedPin, 1000);
}
}

Advertisements

September 26, 2007

Group jameco order notice

Filed under: Tools — gregsaul @ 5:47 pm

Hey guys,

Tiago and me are making an order from jameco tomorrow after interactive furniture. If anybody would like to order anything as well and maybe share in the shipping let me know either tonight via email gregsaul@gmail.com or in class tomorrow.

Jameco’s good for general components resistors, transistors etc but also has plenty of motors sensors tools etc and can be found at http://www.jameco.com .

September 25, 2007

Example of how to post code

Filed under: Course Materials,Examples — jet @ 8:54 am

To post source code, you need to put a wrapper around it using “sourcecode”. Use the “Code” tab of the editor to insert the “sourcecode” tags, not the “Visual” tab. The “Visual” tab does all sorts of magic that will cause the “sourcecode” tag to not be recognized.

[sourcecode language="cpp"]

[put your source here]

[/sourcecode]

/*
* AnalogInput
* by DojoDave <http://www.0j0.org>
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 13. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In the easiest case we connect
* a potentiometer to analog pin 2.
*
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/

// int cellPin = 0;    // select the input pin for the potentiometer
int ledPin = 12;   // select the pin for the LED
int cdsPin = 0;
int cdsVal =0;
int ledDelay =0;

void setup() {
pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
pinMode(cdsPin, INPUT);
Serial.begin(9600);
}

void loop() {

cdsVal = analogRead(cdsPin);
Serial.println(cdsVal);
ledDelay = cdsVal;

digitalWrite(ledPin, HIGH);  // turn the ledPin on
delay(ledDelay);
digitalWrite(ledPin, LOW);   // turn the ledPin off
delay(ledDelay);

}

September 24, 2007

IntroFlirt (a “theremin” made with a photosensor and piezo buzzer)

Filed under: Exercise 4: Four State Machines,Jenn Gooch — jenngooch @ 10:27 pm

My four state project, IntroFlirt, uses a photoresistor and a piezo as its sensor and responder. Its four states are: sleep, attract (once it senses change in light, but then feels abandoned, it will beep for attention), reward (the piezo tonally reciprocates your hand blocking light from the photoresistor, a sort of theremin), and alarm (it freaks out and squeals if you get too close). There’s not a lot of transition between the states, but it’s been slow going for me.

Here’s video of me playing IntroFlirt: its “attract” and “alarm” states, as well as my attempting to play, “Daisy Bell”, a little 2001: A Space Odyssey reference, in light of last week’s discussion:

int piezo = 9; // piezo on PWM pin
int sensor = 5;// photsensor on analog pin

int duration = 16000; //for playTone loop
int sensorVal = 0;
int timer = 0; 
int sleeptimer = 0;
int i = 0;

void setup ()
{
  pinMode(sensor, INPUT);
  pinMode(piezo, OUTPUT);
  Serial.begin (9600);
}
  
void loop () 
{
  sensorVal=analogRead(sensor);
  Serial.print(sensorVal);
  Serial.print("   ");
 
 //Attract  (if INTROFLIRT has been waken, but then abandoned, it will beep for attention)
  if (sensorVal<200 && timer<2000)//sets up timer for attraction beep
  {
    timer=timer++;
    Serial.println(timer);
    Serial.print("   ");
    Serial.println(sleeptimer);
  }

  else if (sensorVal<200 &amp;&amp; timer>1999)//triggers attraction beep
  {
    for (i = 0; i < 15; i ++) playTone (2000);//sets length of attract beep
      timer=0;
      sleeptimer++;//counts how many times it tries to attract before giving up and sleeping
 //Sleep   (INTROFLIRT gives up beeping if abandoned for some time and sleeps)
      if (sleeptimer==5)
      {
        while(sensorVal+20>analogRead(sensor) &amp;&amp; analogRead(sensor)>sensorVal-20);
        sleeptimer=0;
      }
   }
 //Reward (INTROFLIRT reciprocate hand motions with sound equivalent) 
  else if (sensorVal>200 &amp;&amp; sensorVal<850)
  {
    playTone (sensorVal);
    delay (1);
  }
 //Alarm (INTROFLIRT freaks out if you smother it and squeals)
  else if (sensorVal>850)
  {
    playTone(230);
  }
}

// PLAY TONE from http://www.arduino.cc/en/Tutorial/PlayMelody
// uses input from photoresistor to output piezo tone, like a photosensor Theremin
void playTone(int tone) 
{
  long elapsed_time = 0;
  while (elapsed_time &lt; duration)
  {
    digitalWrite(piezo,HIGH);
    delayMicroseconds(tone / 2);
    digitalWrite(piezo, LOW);
    delayMicroseconds(tone / 2);
    
    elapsed_time += (tone);   // Keep track of how long we pulsed
  }
}

[Dan D.W. Kang] Assignment Four

Filed under: Dong Woo Kang,Exercise 4: Four State Machines — dwkang @ 9:51 pm

*Description

My “state machine” for this assignment essentially uses the same system that I’ve created for assignment 3. This time, however, I re-wrote the code so that it has the four different states and transitions between them.

 

 

The transition of this system is simple. It goes from sleep – arousal – attract – reward, according to the proximity of the object to the sensor. The state can always step back to the previous state (for example from reward to attract) if you simply back away from the sensor.  If the person leaves the chair to the sideway, instead of gradually backing away from the chair, the system will enter the state of “sleep,” repeating the whole process from the start.

Here is how it works:

View A: http://www.youtube.com/watch?v=65ufWzWCrLc

View B: http://www.youtube.com/watch?v=FUAd_VZSnrA

* Configuration

There are seven different LEDs attached to the chair, making the system seem more complicated than it really is. All the red wires from the LEDs are connected to the ground pin and the green wires are connected to the digital pins on Arduino board.  The I/R sensor was used to dectect the distance from the chair to the object, and it is attached at the bottom of the back support of the chair.

 

*Code

int analogValue0 = 0;
int analogPin0 = 0;
int value = 0;
int red1 = 13;
int red2 = 4;
int yellow1 = 12;
int yellow2 = 5;
int green1 = 11;
int green2 = 6;
int blue = 7;

void setup()
{
pinMode(analogPin0, INPUT);
pinMode(red1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(green1, OUTPUT);
pinMode(green2, OUTPUT);
pinMode(blue, OUTPUT);
Serial.begin(9600);
}

void loop()
{

analogValue0 = analogRead(analogPin0);
Serial.print(”Raw Sensor value;”);
Serial.println(analogValue0);

//sleep
if (analogValue0 =150 && analogValue0 <225)
{
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
digitalWrite(yellow1,LOW);
digitalWrite(yellow2,LOW);
digitalWrite(blue,LOW);
for(value = 0 ; value =0; value-=5)
{
analogWrite(green1, value);
analogWrite(green2, value);
delay(20);
}

}
//attract

if(analogValue0 >= 225 && analogValue0 = 450)
{
digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
digitalWrite(yellow1, LOW);
digitalWrite(yellow2, LOW);
digitalWrite(green1, LOW);
digitalWrite(green2, LOW);
digitalWrite(blue, LOW);

digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);

digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);

digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);

digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);

digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);

digitalWrite(red1, HIGH);
delay(50);
digitalWrite(red1, LOW);
digitalWrite(yellow1, HIGH);
delay(50);
digitalWrite(yellow1, LOW);
digitalWrite(green1, HIGH);
delay(50);
digitalWrite(green1, LOW);
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
digitalWrite(green2, HIGH);
delay(50);
digitalWrite(green2, LOW);
digitalWrite(yellow2, HIGH);
delay(50);
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(50);
digitalWrite(red2, LOW);

digitalWrite(red1, HIGH);
delay(500);
digitalWrite(green1, HIGH);
delay(500);
digitalWrite(yellow1, HIGH);
delay(500);
digitalWrite(blue, HIGH);
delay(500);
digitalWrite(green2, HIGH);
delay(500);
digitalWrite(yellow2, HIGH);
delay(500);
digitalWrite(red2, HIGH);
delay(500);

digitalWrite(red1, HIGH);
digitalWrite(yellow1, HIGH);
digitalWrite(green1, HIGH);
digitalWrite(blue, HIGH);
digitalWrite(green2, HIGH);
digitalWrite(yellow2, HIGH);
digitalWrite(red2, HIGH);
delay(2000);

}

}

September 23, 2007

Example: Temperature controlled fan

Filed under: Course Materials,Examples — jet @ 9:57 pm

Very nice — a tutorial on controlling a fan’s speed with a temperature sensor.

September 20, 2007

[Video] LEV, the Theremin-playing robot plays “Crazy”

Filed under: Matt Thompson — Mattt Thompson @ 10:38 pm

I just ran across this tonight, so I thought I’d share it with you guys. I really like the juxtaposition of bare-bones DIY with retro electronics. After all, nothing says old-school sci-fi quite like the theremin and a MIDI synthesizer.

Video after the jump.

(more…)

September 19, 2007

Exercise 2: Four States

Filed under: Exercise 3: Four States,Uncategorized — architk @ 10:55 pm

img_5225.jpg

img_5234.jpg

This exercise has given me time to recap everything I have learned so far in terms of programming and electrical wiring. I now need to think about and work on the fabrication part. I cleaned up the wires  which previously were all tangled up with jumper wire kit I bought from Radioshack. It was very neat and easy to understand the wiring.

In this exercise, I used photosensor again to create different states. The photosensor responds to the amount of light present in the surrounding area. I used three LEDs (Red, Yellow, Blue) and put short straws on top of the LEDs to maximize the dynamic glow in the dark. At first I struggled with the sensor to work because I put it in wrong direction. I understood now how the breadboard works and how I should place like photosensors and resistors.

Sleep is the state when there is no light turned on. Complete darkness. Attract is when the red light glows with limited light present. When I turn the switch of a lamp on, the lamp will illuminate the room and the red Led would change to yellow and to blue very fast. This is arousal. Reward is three lights blinking simultaneously.

img_5229.jpgimg_5227.jpgimg_5228.jpg

sourcecode language=’css’
int analogValue0 = 0;
int analogPin0 = 0;
int ledPinRed = 13;
int ledPinYellow = 11;
int ledPinGreen = 7;

void setup() {
  pinMode(analogPin0, INPUT);
  pinMode(ledPinRed,OUTPUT);
  pinMode(ledPinYellow,OUTPUT);
  pinMode(ledPinGreen,OUTPUT);
    Serial.begin(9600); // Set up the serial communication.
}

void loop() {
  analogValue0 = analogRead(analogPin0);
  Serial.print(“Raw Sensor value: “);
  Serial.println(analogValue0);
 
  if (analogValue0 > 400) {
    digitalWrite(ledPinGreen, HIGH);
  }
  else {
    digitalWrite(ledPinGreen, LOW);
  }
  if (analogValue0 > 125&&analogValue0 < 400) {
    digitalWrite(ledPinYellow, HIGH);
  }
  else {
    digitalWrite(ledPinYellow, LOW);
  }
  if (analogValue0 < 125) {
    digitalWrite(ledPinRed, HIGH);
  }
  else {
    digitalWrite(ledPinRed, LOW);
  }
}
/sourcecode

Circuit-drawing software

Filed under: Resources,Ronit Slyper — Ronit @ 9:38 pm

I thought some people might find the free software Dia to be useful in future projects. It’s a diagram-drawing program, and does a great job of helping you draw out circuits in only a few minutes – often easier than explaining in English which wires go where 🙂 . (For linux, Windows, and Mac via macports.)

Thought on Iain Banks’s “Descendant”

Filed under: Readings,Ronit Slyper — Ronit @ 9:24 pm

So, a thought on this reading…

The thing about the story that really sticks in my mind, a few days after having read it, is the camera. The protagonist has all this advanced suit technology, yet derives the most comfort from a simple still camera. It’s intentionally discordant – the suit is/appears nearly human, but not human enough, and therefore provides an odd lack of comfort to the protagonist, who only interacts with it in formal, somewhat stilted dialog. The reader, too, is torn between distaste and empathy for the suit – the author varies our views of it, never letting us settle on one feeling. This strange mix of horror/kinship has been termed the uncanny valley, a phenomenon where objects that appear too humanlike assume an aura of zombie-ness that humans find discomfiting. Thus the camera, with its static, yet familiar, pictures, provides more comfort than the more advanced technology.

Next Page »

Blog at WordPress.com.