AuraFlora (AFB1) an Arduino based interactive sculpture

AuraFlora (AFB1)

an interactive or “robotic” flower.

 

 

AuraFlora Beta 1 is a scaled down version of AuraFlora for development purposes. The micro controller is an Arduino Uno R3. The purpose of this device is to be a first prototype for AuraFlora, and provide a platform on which to develop code. AF B1 has 2 inputs and 3 outputs. Inputs are in the form of a PIR motion detector and a Pingback distance sensor. If a servo was added to the ping back sensor, the machine might be able to “see” by using SAR – synthetic aperture radar. The outputs are in the form of audio (currently mono tones – working on including stereo wav’s, the SD shield is currently nonfunctioning), lights in the form of 2 banks of LED’s, and vibration created by a 1.5V motor, and amplified by the steel springs holding the glass petals. The code behavior does currently allow you to advance through ten stages to receive a reward, but the reward is a melody being played, not cash. Within the stages the machine reacts to distance and motion in an attempt to be enticing. There is still a lot of room for improvement.

 

 

Demonstration Video

 

Plans for full concept AuraFlora idea

 

Source Code

/*AuraFlora Source Code
Frank Appio
Rensselaer Polytechnic Institute
Arts 1020
October 2012

Description of project in comments at bottom

Code to advance through program: 2,4,6 (level 0) 3,5,7 (level 1)
*/

    //Include libraries
    #include "pitches.h" 

    //Declare global variables
    int notes[]={52,58,69,78,93,104,117,139,156,185,208,233,277,
    311,370,415,466,554,622,740,831,932,1109,1245,1480,1661};
    int notes2[]={NOTE_E1,NOTE_G1,NOTE_G3,NOTE_A3,NOTE_A4,NOTE_E6,NOTE_E7};
    int motionPin=2;
    unsigned char relayPin[4]={4,5,6,9};
    const int pingPin=7;
    int pwLight=0;
    int pLevel=0;
    int fLast=0;
    int fLaster=0;
    int fLastest=0;
    int firstRun=0;
    int duration=175;
    int spacing=200;

void setup(){

  //Set pins 
  pinMode (motionPin, INPUT);
  pinMode (relayPin[1], OUTPUT);
  pinMode (relayPin[2], OUTPUT);
  pinMode (relayPin[3], OUTPUT);
}

//The program
void loop (){

  //Power light + power up sound (level 1)
  if(firstRun==0){
    for (int i=30; i<1000; i=i+6){
     tone(8,i);
     delay(2); 
    }
    delay(200);
    for (int i=100; i<1200; i=i+10){
     tone(8,i);
     delay(2); 
    }
    delay(400);
    noTone(8);
    firstRun=1;
    pinMode (pwLight, OUTPUT);
    digitalWrite(pwLight, HIGH);
  }

  //Initial sensor delay
  delay(2000);

  //Read from motion sensor - triggers all behaviors
  int sensor_1 = digitalRead(motionPin);
  if (sensor_1 == HIGH){

      //If motion is detected get reading from distance sensor
      long duration, inches;
      int feet;
        pinMode(pingPin, OUTPUT);
        digitalWrite(pingPin, LOW);
        delayMicroseconds(2);
        digitalWrite(pingPin, HIGH);
        delayMicroseconds(5);
        digitalWrite(pingPin, LOW);

     //Calculate
      pinMode(pingPin, INPUT);
      duration = pulseIn(pingPin, HIGH);
      inches = microsecondsToInches(duration);
      feet = round(inches/12);

//Decisions and behaviors

    //Reciprocal of distance so reaction time increases when closer
    int vFlashes=20/feet;

    switch (pLevel){

      case 0:
        //All together
        for (int i=0; i<vFlashes; i++){
          digitalWrite(relayPin[2],HIGH);
          digitalWrite(relayPin[3],HIGH);
           delay(random(random(0,200),random(0,300)));
          digitalWrite(relayPin[3],LOW);  
          tone(8, notes[random(0,25)]);
           delay(random(0,100));
          noTone(8);
           delay(random(0,10));   
          digitalWrite(relayPin[2],LOW);
           delay(random(0,10));
          digitalWrite(relayPin[1],HIGH);  
          tone(8, notes2[random(0,6)]);
           delay(random(0,random(0,800)));
          noTone(8);
           delay(random(0,10));   
          digitalWrite(relayPin[1],LOW);
           delay(random(0,10));
         }
      break;

      case 1:
       //Lights
       for (int i=0; i<3*vFlashes; i++){
          digitalWrite(relayPin[2],HIGH);
           delay(feet*5);
          digitalWrite(relayPin[2],LOW);
           delay(feet*10);
          digitalWrite(relayPin[1],HIGH);
           delay(feet*5);
          digitalWrite(relayPin[1],LOW);
       }
       //Vibration
       for (int i=0; i<vFlashes; i++){
          digitalWrite(relayPin[3],HIGH);
           delay(25);
          digitalWrite(relayPin[3],LOW);
       }
       //Sound    
       for(int i=0; i<2*vFlashes; i++){
          tone(8, notes[random(0,25)]);
           delay(random(50,100));
          noTone(8);
        }
      break;

      case 2:
        digitalWrite(relayPin[2],HIGH);
        digitalWrite(relayPin[1],HIGH);
        //Play the trumpet notes from War - Lowrider
        while (pLevel==2){
          for (int i=0; i<2; i++){
            for (int i=0; i<5; i++) {
              tone(8, NOTE_B3, duration);
               delay(spacing);
            }
            tone(8, NOTE_C4, duration);
             delay(spacing);
            tone(8, NOTE_D4, duration+(duration/2));
             delay(spacing);
            digitalWrite(relayPin[2],LOW);
            digitalWrite(relayPin[1],LOW); 
            digitalWrite(relayPin[3],HIGH);
             delay(spacing);
            digitalWrite(relayPin[3],LOW);
            digitalWrite(relayPin[2],HIGH);
            digitalWrite(relayPin[1],HIGH); 
             delay(spacing+(spacing/2));          
            tone(8, NOTE_G3, duration/(3/2));
             delay(spacing);          
            tone(8, NOTE_B3, duration/(3/2));
             delay(spacing);            
            tone(8, NOTE_C4, duration/(3/2));
             delay(spacing);            
            tone(8, NOTE_B3, duration);
             delay(spacing);           
            tone(8, NOTE_G3, duration);
             delay(spacing); 
            digitalWrite(relayPin[2],LOW);
            digitalWrite(relayPin[1],LOW); 
            digitalWrite(relayPin[3],HIGH);
             delay(spacing);
            digitalWrite(relayPin[3],LOW);
            digitalWrite(relayPin[2],HIGH);
            digitalWrite(relayPin[1],HIGH); 
             delay(spacing);   
            digitalWrite(relayPin[2],LOW);
            digitalWrite(relayPin[1],LOW); 
            digitalWrite(relayPin[3],HIGH);
             delay(spacing);
            digitalWrite(relayPin[3],LOW);
            digitalWrite(relayPin[2],HIGH);
            digitalWrite(relayPin[1],HIGH); 
             delay(spacing);      
          }
           for (int i=0; i<5; i++) {
            tone(8, NOTE_F2, duration);
             delay(spacing);
          }       
            digitalWrite(relayPin[2],LOW);
            digitalWrite(relayPin[1],LOW); 
            digitalWrite(relayPin[3],HIGH);
             delay(spacing);
            digitalWrite(relayPin[3],LOW);
            digitalWrite(relayPin[2],HIGH);
            digitalWrite(relayPin[1],HIGH); 
             delay(spacing); 
           for (int i=0; i<5; i++) {
            tone(8, NOTE_F2, duration);
             delay(spacing);
          }       
            digitalWrite(relayPin[2],LOW);
            digitalWrite(relayPin[1],LOW); 
            digitalWrite(relayPin[3],HIGH);
             delay(spacing);
            digitalWrite(relayPin[3],LOW);
            digitalWrite(relayPin[2],HIGH);
            digitalWrite(relayPin[1],HIGH); 
             delay(spacing);               
            tone(8, NOTE_F2, duration);        
             delay(spacing);
            tone(8, NOTE_G3, duration*8);        
             delay(spacing*4);
        }
      break;

      default:
        tone(8,NOTE_G3);
         delay(5000);
        noTone(8);    
      break;
    }

    //Last 3 states
    fLastest=fLaster;
    fLaster=fLast;
    fLast=feet;

    //Check if code has been entered
    if ((pLevel==0)&&(fLast==6)&&(fLaster==4)&&(fLastest==2)){

      //Advance to next level!
      pLevel=1;
      //Power up sound (level 2)
      for (int i=0; i<2; i++){
       for (int i=30; i<1000; i=i+6){
        tone(8,i);
         delay(2); 
      }
      delay(200);
      for (int i=100; i<1200; i=i+10){
       tone(8,i);
        delay(2); 
      }
       delay(400);
      noTone(8);
      }
    }

    if ((pLevel==1)&&(fLast==7)&&(fLaster==5)&&(fLastest==3)){

      //Program completed!!
      pLevel=2; 
      //Power up sound (level 3)
      for (int i=0; i<3; i++){
       for (int i=30; i<1000; i=i+6){
        tone(8,i);
         delay(2); 
      }
      delay(200);
      for (int i=100; i<1200; i=i+10){
       tone(8,i);
        delay(2); 
      }
       delay(400);
      noTone(8); 
      }
    }

 }
}

//Function to convert distance sensor pulse to inches
long microsecondsToInches(long microseconds){
    return microseconds / 74 / 2;
}
Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: