Archive for the ‘Arduino’ Category

Physical Prototyping: Final Project “The Mirror of Truth”

Saturday, March 31st, 2012

Explination of the project here

One of the oldest symbols of vanity still in use is the mirror. Snow White is a classic tale with a mirror that only tells the truth so we took that concept and turned it up a little bit. People put a lot of time and money to look. The first to condemn you in the morning or evening before you leave home is often yourself when you make the final touches in front of the mirror. So what happens if you are not the one who gives the opinion, but a real “mean machine”? We wanted to get people to think about all the time and money you put on their “image” really been worth it. To be pulled down to earth is a very humbling feeling that many people should experience more often.

We use arduino and proximity sensor to accomplish this project. The idea is that a person is in front of the mirror for an X amounth of time the mirror will insult that person.
You will need Arduino to control the proximity sensor and processing to control the audio.

Source CODE arduinofungerarnu:




/*
 * Pablo Suzarte
 * Fina project "Mean Machines"
 * Physicial Prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */
int sensorPin = 0;     // Analog input pin 
int sensorValue = 0;   // value read from the sensor
int check = 0;


long previousMillis = 0; 
long interval = 5000;  

void setup() {

  
  randomSeed(42);

 

  Serial.begin(9600);  // for debugging
}

void loop() {
  unsigned long currentMillis = millis();
  sensorValue = analogRead(sensorPin); // read the sensor value
  
//Serial.println(sensorValue);
  // the sensor actually gives results that aren't linear.
  // this formula converts the results to a linear range.
  int range = (6787 / (sensorValue ));
  
  if( range >10 && range<90 && check == 0) {
    delay(200);
    sensorValue = analogRead(sensorPin); // read the sensor value
    int range = (6787 / (sensorValue ));
    
    if( range >10 && range<90){
     
      previousMillis = currentMillis;
      check = 1;
      Serial.print('1'); 
      delay(5000);
    }
  }
  else if( range >10 && range<90 && check == 1 && (currentMillis - previousMillis > interval)) {
    previousMillis = currentMillis;
    check = 2;
    Serial.print('2');   
    delay(10000);
  }
  
  else if( range >10 && range<90 && check == 2 && (currentMillis - previousMillis > interval)) {
    previousMillis = currentMillis;
    check = 0;
    Serial.print('3');   
    delay(6000);
  }
 
  else if((range <10 && range > 0)|| range>90) check = 0;
  
  //Serial.println('3');
  //Serial.println(range);
  delay(200);
  
  //Serial.println(range, DEC);    // print the sensor value
//delay(1000);   

}




import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

import cc.arduino.*;

long start, finished, elapsed; //variable for the timer
int counter, total; 
int desireTime = 1;
int desireTime2 = 5;
boolean check = false;

Minim minim;
AudioPlayer song;
AudioPlayer song2;
AudioPlayer s0;
AudioPlayer s1;
AudioPlayer s2;
AudioPlayer s3;
AudioPlayer s4;
int index = int (random(0, 2));

int beginTime = 0;
// Example by Tom Igoe

import processing.serial.*;

Serial myPort;    // The serial port
PFont myFont;     // The display font
String inString;  // Input string from serial port
char i;
int lf = 10;      // ASCII linefeed

void setup() {
  size(400, 200);
  minim = new Minim(this);
  s0 = minim.loadFile("damn.mp3");
  s1 = minim.loadFile ("now.mp3");
  s2 = minim.loadFile ("per.mp3");
 // s1= minim.loadFile ("cheer.mp3");
 // s2= minim.loadFile ("littleblackman.mp3");
 // s3 = minim.loadFile ("ParkBusFace.mp3");
 // s4 = minim.loadFile ("ratface.mp3");
  // Make your own font. It's fun!
  //  myFont = loadFont("AgencyFB-Reg-48.vlw");
  //  textFont(myFont, 18);
  // List all the available serial ports:
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Keyspan adaptor, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, "COM6", 9600);
  myPort.buffer(3);
}

void draw() {

    
  if ( myPort.available() > -1) {  // If data is available,
    
    i = myPort.readChar();         // read it and store it in val
    myPort.clear();
  }
  background(255);
  
  
  println(i);
  
      
  if (i == '1' ) {
    timer();
    
  }
//   if (beginTime>0&& millis()-beginTime> 500){
  
  //if (inString!= null)
    //i = Float.valueOf(inString).floatValue();
       
  if (i == '2') {
//      delay(3000);
    timer2();
//    check = false;
  }
  
  if (i == '3'){
    timer3();
  }
//  else if(i<20 && i>90){
//    check = false;
//  }
 

}

/*void serialEvent(Serial myPort) {
  inString = myPort.readString();
  println("värde"+inString);
}*/


void stop()
{
  song.close();
  minim.stop();

  super.stop();
}

void timer() {

  //start=millis();
//  delay(3000);
  counter++;

//  if (counter>=desireTime && song.isPlaying() == false) {

    //    for (int i=0;i<10;i++) {
    //      
    //    s[index].play();
    //    delay(9500);
    //    song.pause();
    //    song.rewind();
    //    
    //SKRATT
    s0.play();
    delay(8100);
    s0.pause();
    s0.rewind();
    delay(2000);
  
}


void timer2() {

  
  counter++;

//  if (counter>=desireTime2 && song.isPlaying() == false) {
    
  //CHEER
    s1.play();
    delay(6000);
    s1.pause();
    s1.rewind();
    delay(5000);

//    //BUSFACE
//    s3.play();
//    delay(2500);
//    s3.pause();
//    s3.rewind();
//    delay (3000);
}

void timer3(){
  counter++;
    //Littleman
   s2.play();
   delay(9100);
   s2.pause();
   s2.rewind();
  
}



Zip File with all the files

Proximity Sensor:

Final Product:

Video!

Physical Prototyping: assignment 3 “Hydro Coaster”

Friday, March 30th, 2012

this assignment was one of my favorites, the idea was to build something with time. The assignment was named “Time Machine” We decide to create a coaster that reminds you when to drink water. We were aiming to the people that is sitting for long periodes of time in front of the computer and maybe forgets to drink water.

We calculate what we need to drink a zip every 5 minutes for 8 hours. So with the help of a light sensor when the bottle is put on the coaster a internal timer starts to run and when 5 minutes have past 6 lamps start to blink and a bip sound.

Picture:

Source CODE LRDsensor:




/*
 * Pablo Suzarte
 * Assignment 3 Hydro Coaster
 * Physical prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

int LDR = A2; // select the input pin for the LDR
int ledPin = 13;
int ledPin2 = 12;
int ledPin3= 11;
int ledPin4 = 10;
int ledPin5= 9;
int ledPin6 = 8;
int desireTime = 3;
int ldrStateCompare = 700;

// select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
int ldrState= 0;
int outputPin = 7;

unsigned long start, finished, elapsed; //variable for the timer
int counter, total;

void setup() {
  
  pinMode(outputPin, OUTPUT);  
  pinMode(LDR, INPUT); // declare the LDR as an INPUT
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  
// declare the ledPin as an OUTPUT

  Serial.begin(9600);

}

void loop() {
  
  
    ldrState = analogRead(LDR);
    val = analogRead(LDR); // read the value from the sensor
    
    if(ldrState > ldrStateCompare){
      timer();
        
}
    else{
        
        counter= 0;
        }
 
}

void timer(){

  start=millis();
  delay(1000);
  total=counter++;

  if(total>=desireTime){
    
    for(int i=0;i<10;i++){
      playSound();
          digitalWrite(ledPin, HIGH);
          digitalWrite(ledPin2, HIGH);
          digitalWrite(ledPin3, HIGH);
          digitalWrite(ledPin4, HIGH);
          digitalWrite(ledPin5, HIGH);
          digitalWrite(ledPin6, HIGH);
         delay(1);
          digitalWrite(ledPin, LOW);
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin3, LOW);
          digitalWrite(ledPin4, LOW);
          digitalWrite(ledPin5, LOW);
          digitalWrite(ledPin6, LOW);
    }

    }

}
void playSound(){
    digitalWrite(outputPin, HIGH);
    delayMicroseconds(1500);
    digitalWrite(outputPin, LOW);
    delayMicroseconds(1500);

}

Instructions:

PDF

Video!

Physical Prototyping: assignment 2 “Chess with a Twist”

Friday, March 30th, 2012

On this assignment we had to improve the game play of some classical table game. We choose Chess, the way that we “improve it” was by add some rules with lights (leds) and one button.
The idea was to make the game of chess a bit faster and stressy. Ones the player made a move it has to press the button and it will start the lights to randomly go on and off. The player has just 5 seconds to choose when to release the button. If is fast enough the lamp will stay under a piece of the opponent. This means the that piece has to leave the game. If the player don’t think fast can happen that the light will stay on one of his pieces. Pretty tricky game but really fun to develop.

We builded the whole game, just the pieces came from an existing old chess game.

Picture:

Source CODE CodeChessWithATwist:





/*
 * Pablo Suzarte
 * Assignment 2 chess with a twist
 * Physical prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */
int outputPin = 18; //Sound

int buttonPin = 19; 
int buttonState =0;

const int pinArray[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
int count = 0;
int randNumber;

int previous = LOW; 
int state = HIGH;
long time=100;
long debounce = 500;

  
void setup() {
   pinMode(outputPin, OUTPUT);  
  
  for ( count=0;count<16;count++){
    
    pinMode(pinArray[count], OUTPUT);
  }
  
  pinMode(buttonPin, INPUT);
  
  
}
 
void loop(){
  
  buttonState = digitalRead(buttonPin);
  
  if (buttonState  == LOW && millis() - time > debounce) {
    
    if (state == HIGH){
      
      state = LOW;
    }
    
    else{
      
      state = HIGH;
       randNumber = random(0, 16);
    }
    
     time = millis();    

for(int i=0; i<16; i++){
      digitalWrite(pinArray[i], LOW);
       playSound();
   } 
  }

 else  { 
        
    digitalWrite(pinArray[randNumber], HIGH);
    
    
 
  }
}
void playSound(){
    digitalWrite(outputPin, HIGH);
    delayMicroseconds(2500);
    digitalWrite(outputPin, LOW);
    delayMicroseconds(2500);

}

Instructions:
PDF

Here a video with some gameplay!

Physical Prototyping: assignment 1 “The bobbie”

Friday, March 30th, 2012

On this assignment we have to do a toy for adults using the Arduino The idea was to with help of a potentiometer turn on the leds on the bobbie.

Source CODE bobbie:




/*
 * Pablo Suzarte
 * Assignment 1
 * The Bobbie
 * Physical prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

int sensorPin = A0;    // select the input pin for the potentiometer
     
int fadeValue = 0;    

void setup() {
  
  // declare the ledPin as an OUTPUT:
  
   pinMode(3, OUTPUT); 
   pinMode(5, OUTPUT);   
   pinMode(6, OUTPUT); 
   pinMode(9, OUTPUT); 
   pinMode(10, OUTPUT);   
   pinMode(11, OUTPUT);  
     
}

void loop() {
  

  
    for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { 
        fadeValue = analogRead(sensorPin);    
            analogWrite(3, fadeValue/4);  
            analogWrite(5, fadeValue/4);
            analogWrite(6, fadeValue/4);
            analogWrite(9, fadeValue/4);  
            analogWrite(10, fadeValue/4);  
            analogWrite(11, fadeValue/4);  
  
            delay(fadeValue); 
            }   
   
    for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {  
        fadeValue = analogRead(sensorPin);    
            analogWrite(3, fadeValue/4); 
            analogWrite(5, fadeValue/4); 
            analogWrite(6, fadeValue/4);
            analogWrite(9, fadeValue/4); 
            analogWrite(10, fadeValue/4); 
            analogWrite(11, fadeValue/4);  
  
            delay(fadeValue);  
            }  
        }

Instructions & DIY Manual (2 PDfS)

DIY

How to use it

here an explanation of the process: