Making Things Interactive

May 12, 2008

BOOMBOXES

Filed under: Assignments, Final Project, Jesse Chorng, Paul Castellana — paulcastellana @ 2:44 pm

Boomboxes is an environment designed to promote social interaction through music. It consists of a stationary hub, and five wireless modular seating units that can be moved and stacked to best fit the given social situation. Users can connect their mp3 players to an input jack in the hub to play music through all of the modular units. Each unit has a radio, RBG and white lights, a seat button that detects when someone is sitting down, and all are networked together using Xbee radio transmitters. Although a faulty seat button caused malfunctioning during the final presentation, the particular program we’re providing code for here changes the lighting of the boxes based on the number of people sitting down, so that when music is playing and the boxes are activated, the lights are white until all five boxes are in use, at which point each box lights a different color. If at this point, everyone stands up within 15 seconds of each other the colored lights dances to the music.

Project Website which is currently under construction. For now, check it out here

Here’s our proposal: Boomboxes Proposal

Part’s List: Boomboxes Parts List

Code:

/*
Boomboxes - Social Interaction Through Music
Small Undergraduate Research Grant

Paul Castellana
Jesse Chorng

*/

//----------- STATES ------------//
const int sWaiting = 0;          // The system is waiting for audio to be plugged in. Speakers/Lights are off
const int sActivate = 1;         // The system detects audio being played. Speakers/Lights are on
const int sAttract = 2;          // The system detects motion and inactive; lights turn to attract attention
const int sStandby = 3;          // If everyone sitting and someone stands up, wait 30 secs to see if everyone stands up
const int sParty = 4;            // If there's enough people around and people are moving, party time! Lights dance to music

int currentState = sWaiting;
int nextState = sActivate;

//----------- INPUTS ------------//
int audioIn = 1;                 // Audio signal in from stereo jack
int activateSwitch = 9;          // Switch to activate Boomboxes
int pirSensor = 8;               // PIR Motion swich, sends LOW when motion detected

int seat1 = 6;                   // Input Pin for Seat 1
int seat2 = 5;                   // Input Pin for Seat 2
int seat3 = 4;                   // Input Pin for Seat 3
int seat4 = 3;                   // Input Pin for Seat 4
int seat5 = 2;                   // Input Pin for Seat 5

//----------- OUTPUTS -----------//
int recModuleSwitch = 10;        // Seat switch to know when someone is sitting
int radioSwitch = 7;             // Activates radios in seats
int rgbLed = 12;                 // RGB LED
int whiteLed = 11;               // White LED

//---------- VARIABLES ----------//
int motionCount = 0;             // PIR Motion Count
int allSitting = 0;              // All sitting true (1) or false (0)
int allStanding = 0;             // All standing true (1) or false (0)
int audioVal;

//--------------------------- SETUP ---------------------------//
void setup()  {

    pinMode(audioIn, INPUT);
    pinMode(activateSwitch, INPUT);
    pinMode(pirSensor, INPUT);
    pinMode(seat1, INPUT);
    pinMode(seat2, INPUT);
    pinMode(seat3, INPUT);
    pinMode(seat4, INPUT);
    pinMode(seat5, INPUT);

    pinMode(recModuleSwitch, OUTPUT);
    pinMode(radioSwitch, OUTPUT);
    pinMode(rgbLed, OUTPUT);
    pinMode(whiteLed, OUTPUT);

    Serial.begin(9600);
}

//---------------------------- LOOP -----------------------------//
void loop()  {

  switch(currentState) {
       case sWaiting:                                            // Waiting to either activate or attract people
           Serial.println("Waiting");

           digitalWrite(radioSwitch, LOW);                       // Radios are off
           digitalWrite(recModuleSwitch, LOW);                   // Don't play "Boomboxes" sample
           digitalWrite(whiteLed, LOW);                          // No LED action
           digitalWrite(rgbLed, LOW);                            // No color LED action

           if (digitalRead(activateSwitch) == HIGH) {            // Check switch to activate
               currentState = sActivate;
           }

           motionCheck();                                        // Check for motion from PIR sensor
           if(motionCount > 30) {                                // If there's enough motion, go into Attract state
             currentState = sAttract;
           }
           break;

       case sAttract:
           Serial.println("Attract");

           digitalWrite(radioSwitch, HIGH);
           digitalWrite(recModuleSwitch, HIGH);
           digitalWrite(whiteLed, LOW);

           motionCount = 0;

           for(int h=0; h < 10; h++) {                            // When in attract mode, flash lights for 15 secs
             digitalWrite(rgbLed, HIGH);
             delay(500);
             digitalWrite(rgbLed, LOW);
             delay(500);
           }

           if(digitalRead(activateSwitch) == HIGH) {
             currentState =sActivate;
           } else {
             currentState = sWaiting;
           }

           break;

       case sActivate:                                            // Activated mode is simply white LEDs on
           Serial.println("Activated"); 

           digitalWrite(radioSwitch, HIGH);
           digitalWrite(recModuleSwitch, LOW);
           digitalWrite(whiteLed, HIGH);
           digitalWrite(rgbLed, LOW);

           if (digitalRead(activateSwitch) == LOW) {
             currentState = sWaiting;
           }       

           allSittingCheck();                                      // If all 5 seats are occupied, go to
           if(allSitting == 1) {                                   // Standby mode before Party state
             currentState = sStandby;
           }
           break;

       case sStandby:
           Serial.println("Standby to Party");

           digitalWrite(radioSwitch, HIGH);
           digitalWrite(recModuleSwitch, LOW);
           digitalWrite(whiteLed, LOW);
           digitalWrite(rgbLed, HIGH);

           allSittingCheck();

           if (allSitting == 0)  {                                  // If everyone is sitting there is
             for(int f=0; f<15; f++) {                              // 15 secs to go into Party State
               digitalWrite(whiteLed, HIGH);
               delay(500);
               digitalWrite(whiteLed, LOW);
               allStandingCheck();
               if(allStanding == 1) {
                 f = 15;
                 currentState = sParty;
               }
               delay(500);
             }
             allSittingCheck();
             if(allSitting == 0) {
               currentState = sActivate;
             }
           }

           if (digitalRead(activateSwitch) == LOW) {
           currentState = sWaiting;
           }

           break;

       case sParty:
           Serial.println("Party!");

           digitalWrite(radioSwitch, HIGH);
           digitalWrite(recModuleSwitch, LOW);
           digitalWrite(whiteLed, LOW);

           audioVal = analogRead(audioIn);

           if (audioVal <= 14) {                                    // Flash lights to music
             digitalWrite(rgbLed, LOW);
           } else {
             digitalWrite(rgbLed, HIGH);
           }

           allStandingCheck();

           if (allStanding == 0)  {
             currentState = sActivate;
           }
           if (digitalRead(activateSwitch) == LOW) {
             currentState = sWaiting;
           }
           break;

       default:
           Serial.println("ERROR: default state");
           currentState = sWaiting;
           nextState = sActivate;
           break;
   }
}

//------------------- PIR SENSOR MOTION CHECK -------------------//
void motionCheck()  {
  for (int j=0; j < 5; j++)  {
    if (digitalRead(pirSensor) == LOW)  {
      motionCount++;
      delay(500);
    }
  }
}

//----------------- EVERYONE SITTING DOWN CHECK -----------------//
void allSittingCheck()  {
  if (digitalRead(seat1) == HIGH and digitalRead(seat2) == HIGH and
      digitalRead(seat3) == HIGH and digitalRead(seat4) == HIGH and
      digitalRead(seat5) == HIGH) {
    allSitting = 1;
  } else  {
    allSitting = 0;
  }
}

//------------------- EVERYONE STANDING STANDING ----------------//
void allStandingCheck()  {
  if (digitalRead(seat1) == LOW and digitalRead(seat2) == LOW and
      digitalRead(seat3) == LOW and digitalRead(seat4) == LOW and
      digitalRead(seat5) == LOW) {
    allStanding = 1;
    Serial.println("All Standing");
  } else  {
    allStanding = 0;
  }
}

Overall, we were very satisfied with how the project turned out. It was well received at the Meeting of the Minds, and we even won a prize from the STUDIO for Creative Inquiry. We plan on continuing to develop Boomboxes as concept, further improving the design and functionality of the space. The next public forum in which we are hoping to present the project is the Outdoor Lounge Exhibition of Artscape 2008, in Baltimore, MD, which we are currently on the waitlist for.

The Amazing Booth Device

Filed under: Final Project, Lea — tovelet @ 10:23 am

 

 

The details are rather long-winded for this blog, so I’ve put some explanations here and the full source code here.

The Light-o-Stat

Filed under: Assignments, Brian Kish, Final Project, Term Paper — bkish @ 10:22 am

Hello All:

Please take a look at my final term paper for my Light-o-Stat Project by following the attached link.

final-paper1

The majority of my documentation can be seen in the paper, but here are some other things too.
    

 The Guts of the Project:                          The Mess that I made with an Arduino and Breadboard
The Guts of the ProjectThe Mess that I made with an Arduino and Breadboard
int servoPin = 2;     // Control pin for servo motor
int minPulse = 800;   // Minimum servo position
int maxPulse = 2300;  // Maximum servo position
int neutralPulse = 1500;  //neutral servo
int pulse = 0;        // Amount to pulse the servo
int prevPhotosensor;  //last reading of sensor-last state
int increment = 50;   //pwm changes
int goodLED= 6;
int darkLED= 7;
int brightLED = 5;

long lastPulse = 0;    // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses

int photoSensor = 0;  // the value returned from the analog sensor
int sensorPin = 1;    // the analog pin that the sensor's on
int average = 10;      // reads per cycle
int potSwitch = 0;     //potentiometer switch
int potMin = 0;
int potMax = 0;
int potPin = 0;

void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pinMode(potSwitch, INPUT);
  pinMode(goodLED, OUTPUT);
  pinMode(darkLED, OUTPUT);
  pinMode(brightLED, OUTPUT);
  pulse = neutralPulse;           // Set the motor position value to the minimum
  digitalWrite(goodLED, LOW);
  digitalWrite(darkLED, LOW);
  digitalWrite(brightLED, LOW);
  Serial.begin(9600);

}

void loop() {
  delay(100);
  int x;
  int photoTotal;
  photoTotal = 0;
  for (x = 0; x<average; x++) {
    photoSensor = analogRead(sensorPin);      // read the analog input
    potSwitch = analogRead(potPin);         //pulse = (photoSensor *19)/10 + minPulse;
    photoTotal = photoSensor + photoTotal;  // convert the analog value
  }
  photoSensor = photoTotal/average;   //average of photo sensor readings

  potMin = potSwitch-25;
  potMax = potSwitch+50;

  Serial.print("Amount of Light = ");
  Serial.println((int)photoSensor);
  Serial.print("Desired amount of light = ");
    Serial.println((int)potSwitch);        

  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }

  //good State
  if(photoSensor <= potMax && photoSensor >= potMin){  //if light value is in desired range, do the following
    digitalWrite(goodLED, HIGH);
    digitalWrite(darkLED, LOW);
    digitalWrite(brightLED,LOW);
    Serial.println("Light is good");
    //do nothing with pulse;
  }
  // bright State
  if(photoSensor < potMin){   // if the actual light is greater than desired, do this...remember that the values are reversed, larger number=darker and smaller number = brighter
    digitalWrite(goodLED, LOW);
    digitalWrite(darkLED, LOW);
    digitalWrite(brightLED,HIGH);
    Serial.println("Too Bright");

    //pulse clockwise
    if(prevPhotosensor > photoSensor) {  // if moving the shades makes it darker, it i doing the right thing, continue in this direction
      prevPhotosensor = photoSensor;
      pulse = pulse - increment;
      if (pulse < minPulse)
        pulse = minPulse;
    }

  }

  // dark State
  if(photoSensor > potMax){              // if level of light is below the minimum desired, it is too dark
    digitalWrite(goodLED, LOW);
    digitalWrite(darkLED, HIGH);
    digitalWrite(brightLED,LOW);
    Serial.println("Too Dark");
    //pulse counter-clockwise
    if(prevPhotosensor < photoSensor) {   //if moving the shades makes it lighter, it is doin the right thing
      prevPhotosensor = photoSensor;
      pulse = pulse + increment;
      if (pulse > maxPulse)
        pulse = maxPulse;
    }

  }
}

<pre>

Magic Lantern

Filed under: Assignments — tyang1 @ 8:15 am

Many times in a hotel room or even your own room, when you turn off the lights before going to bed you stumble over a few things before reaching your bed.  This is a night table next to your bed that will light up depending on what you are doing in the room.  The different states are:

1.  Turn off lights, leave the room:  night table lights off

2.  Turn off lights, stay in room but not going to bed yet (checking last minute email, etc): night table lights on

3.  Turn off lights, go to bed to read: night table lights on

4.  Turn off lights, go to bed to sleep: night table lights off

If at any time the room is bright, the night table lights will remain off no matter what your motions are.  

The sensors I used are: PIR sensor (very fickle!), ultrasonic sensor and photosensor. 

Photosensor: used to detect overhead light

PIR sensor: detects motion in the room

ultrasonic sensor: angled to detect if someone is sitting up in bed or not (sometimes when you read there is not enough motion for the PIR sensor to detect that someone is in the room)


 

int photoPin = 1;

int light;

float sens = 0.85;

int val = 0;

int pirPin = 3;

int calibrateTime = 60;                          // time given to PIR sensor to calibrate (10 -60 secs according to datasheet)

unsigned long lowIn;                         // the time when the sensor outputs a low impulse

unsigned long pause = 60000;                              // millisecondes the sensor has to be low before we assume all motion has stopped

boolean lockLow = true;

boolean takeLowTime;

int ultraPin = 5;                                // sets ultrasonic range finder to digital pin 5

int timecount = 0; 

int ultraVal = 0;

int ledPin = 11;                                 // sets LEDs in table to digital pin 11;

int ledActive = 12;                              // sets LED to digital pin 12; blinks when PIR sensor finishes calibrating

 

void setup() {

 

  pinMode(photoPin, INPUT);                      // declares photosenor as INPUT

  pinMode(pirPin, INPUT);                        // declares PIR sensor as INPUT

  digitalWrite(pirPin, LOW);                     // initially sets PIR sensor to LOW = no motion

  pinMode(ledPin, OUTPUT);                       // declares LEDs in table as OUTPUT

  pinMode(ledActive, OUTPUT);                    // declares calibration LED as OUTPUT

  Serial.begin(9600);                       

  val = analogRead(photoPin);                     // reads value of photosensor

  

  // Gives sensor some time to calibrate

  Serial.println("Calibrating PIR sensor ");      

  for (int i = 0; i < calibrateTime; i++) {       

    Serial.print(".");

    delay(1000);

  }

  Serial.println(" SENSOR ACTIVE");               // notifies user when PIR is finished calibrating

  digitalWrite(ledActive, HIGH);                  // blinks LED when PIR finishes calibrating 

  delay(1000);

  digitalWrite(ledActive, LOW);

  delay(1000);

  digitalWrite(ledActive, HIGH);

  delay(1000);

  digitalWrite(ledActive, LOW);

}

 

int getPing() {                                    // sends a 10us pulse to activate the sonar

  pinMode(ultraPin, OUTPUT);                       // sets ultrasonic sensor to OUTPUT

  digitalWrite(ultraPin, LOW);                     // sends a LOW pulse  

  delayMicroseconds(2);                            // wait 2 microseconds

  digitalWrite(ultraPin, HIGH);                    // sends a HIGH pulse

  delayMicroseconds(5);                            // wait for 5 microseconds

  digitalWrite(ultraPin, LOW);                     // holdoff

  pinMode(ultraPin, INPUT);                        // switches signal pin to INPUT to listen for echo pulse

  return pulseIn(ultraPin, HIGH);                  //  returns echo singal i.e. object's distance

}

 

void loop() {

 

  light = analogRead(photoPin);                    // reads photosensor value and sets it to light variable

  ultraVal = getPing();                            // writes value of ultrasonic sensor from getPing to ultraVal variable

  Serial.println("pir value");

  Serial.println(digitalRead(pirPin));

  delay(1000);

 

  if ((light < val * sens) || (light <= 250)) {              // if the room becomes darker or the amount of light is below threshold...

 

    if (digitalRead(pirPin) == HIGH) {                       // ... and there is MOTION 

      if(lockLow){

        lockLow = false; 

        delay(50);

      }

      takeLowTime = true;

      if (ultraVal <= 2000) {                                // ... and the person is sitting up 

        digitalWrite(ledPin, HIGH);                          // ... LIGHTS ON

        delay(60000);

      }

      else if (ultraVal > 2000) {                            // ... and the person is lying down

        digitalWrite(ledPin, LOW);                           // ... LIGHTS OFF

      }

    }

    else if (digitalRead(pirPin) == LOW) {                   // ... and there is NO MOTION

      digitalWrite(ledPin, LOW);                             // ... LIGHTS OFF

      if (takeLowTime){

        lowIn = millis();

        takeLowTime = false; 

      }

      if(!lockLow && millis() - lowIn > pause){  

        //makes sure this block of code is only executed again after 

        //a new motion sequence has been detected

        lockLow = true;  

        delay(50);

      }

    }

  }

  else if (light <= 250 && ultraVal <= 2000) {                // my PIR is finicky....so this is saying if there is someone in bed sitting up even if it detects no motion, then the lights will be on

    digitalWrite(ledPin, HIGH);

  }

  

  else if (light > val * sens) {

    digitalWrite(ledPin, 0);

  }

  else {                                                      // not really needed since the previous else statement should cover                                                                       all other logic but this is insurance

   digitalWrite(ledPin, 0);

 }

}

 

 

Final prototype of Magic Lantern

Location of sensors on table topHow the electronics are fitted inside the table

Small models of tables whose forms would hide/embed the sensors better.

Washroom Penitentiary [final]

Filed under: Final Project, Gaku Sato — ponkotsu @ 3:41 am

  this is a bathroom concept intended for consideration of possible implementation in the near future or at least further testing.  it is a sensor-driven room that advocates cleanliness by locking you in when you use it and telling you to wash your hands.  of course the lock can be manually disengaged (for legal reasons) and the sign can be ignored, but if you choose to do so, as you leave a sign and alarm will notify everyone around you that you have not washed your hands.  of course, if you do wash your hands (whether you used the bathroom or not), you will be thanked and rewarded with sounds of success as you leave.

  additionally, rinsing does not count as washing as they are two separate entities.  and you will be hounded similarly for not flushing the toilet if you use it and don’t flush.

prototype details and photo scenario:
  [Scenario.pdf]

state diagram, wiring schematic, and message list:
  [Schematic v2.pdf]

reviews:
  “great idea!”  -man at demo
  “we need this!”  -hospital worker
  “totally fascist!”  -g. levin
  “adorable!”  -l. albaugh

code:

#include <Servo.h>

// PINS //
int soapLED_R = 10; // warning light
int soapLED_G = 9;  // indicates soap being dispensed
int soapLED_B = 8;  // standard light [GB=white]
int sinkLED = 11;   // indicates running water [B]

int soapsensor = 0;
int sinksensor = 1;

int toiletswitch = 12; // indicates motion detected [in toilet!]
int flushbutton = 13;
int lockbutton = 7;
int doorswitch = 4;

int signservo = 3;
int locksolenoid = 2;
int speaker = 5;
int bell = 6;

Servo sign;

// STATES //
int State = 0;
const int Blank = 0;
const int Locked = 1;
const int Wash = 2;
const int LockWash = 3;
const int Flush = 4;
const int Toilet = 5;
const int DUnlock = 6;
const int DLeaving = 7;
const int DSoap = 8;
const int DRinse = 9;
const int Clean = 10;
const int CLeaving = 11;
const int TUnlock = 12;
const int TLeaving = 13;
const int TSoap = 14;
const int TWater = 15;

int LockState = 0;
const int Auto = 0;
const int Manual = 1;

// OUTPUT CONDITIONS //
int Reward = 0;
const int Off = 0;
const int On = 1;
int Buzzer = 0;
int Sign = 0;
const int Bl_Bl = 126; // in: blank   out: blank
const int Wa_Bl = 110; // in: wash    out: blank
const int Wa_Di = 89;  // in: wash    out: dirty
const int Ri_Bl = 71;  // in: rinse   out: blank
const int Fl_Bl = 55;  // in: flush   out: blank
const int Fl_Fl = 34;  // in: flush   out: flush
const int Th_Cl = 15;  // in: thanks  out: clean!
int Soap = 0;
const int White = 0;  // standard light
const int Red = 1;    // warning light
const int Green = 2;  // indicates soap being dispensed
int Sink = 0;
int Lock = 0;

// ANALOG INPUT THRESHOLDS //
int soapmin = 50;
int soapmax = 100;
int sinkmin = 100;
int sinkmax = 300;

// OTHER //
int lockbuttonpress = 0;
int dooropentime = 0;
int dooropenmax = 5000;

void setup()
{
  Serial.begin(9600);

  pinMode(soapLED_R, OUTPUT); // digital
  pinMode(soapLED_G, OUTPUT); // digital
  pinMode(soapLED_B, OUTPUT); // digital
  pinMode(sinkLED, OUTPUT);   // digital
  pinMode(soapsensor, INPUT); // analog
  pinMode(sinksensor, INPUT); // analog
  pinMode(toiletswitch, INPUT);  // digital
  pinMode(flushbutton, INPUT);   // digital
  pinMode(lockbutton, INPUT);    // digital
  pinMode(doorswitch, INPUT);    // digital: LOW when closed, HIGH when open
  pinMode(signservo, OUTPUT);    // digital: PWM
  pinMode(locksolenoid, OUTPUT); // digital
  pinMode(speaker, OUTPUT);      // digital
  pinMode(bell, OUTPUT);         // digital

  State = Blank;
  LockState = Auto;
  Reward = Off;
  Buzzer = Off;
  Sign = Bl_Bl;
  Soap = White;
  Sink = White;
  Lock = Off;

  lockbuttonpress = 0;
  dooropentime = 0;

  sign.attach(signservo);
  sign.setMaximumPulse(2400);
  sign.setMinimumPulse(544);
  sign.write(Bl_Bl);
}

void loop()
{
  // SWITCH STATES //
  switch(State)
  {
    case Blank:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH && digitalRead(doorswitch)==LOW)
      { lockbuttonpress=1; State=Locked; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(analogRead(soapsensor)<soapmin) {State=Wash;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case Locked:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=Blank; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(analogRead(soapsensor)<soapmin) {State=LockWash;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case Wash:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH && digitalRead(doorswitch)==LOW)
      { lockbuttonpress=1; State=LockWash; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH) {State=Blank;}
      if(analogRead(sinksensor)<sinkmin) {State=Clean;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case LockWash:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=Wash; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH) {State=Blank;}
      if(analogRead(sinksensor)<sinkmin) {State=Clean;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case Flush:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=DUnlock; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH)
      { dooropentime=0; State=DLeaving; }
      if(analogRead(soapsensor)<soapmin) {State=DSoap;}
      if(analogRead(sinksensor)<sinkmin) {State=DRinse;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case Toilet:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=TUnlock; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH) {dooropentime=0; State=TLeaving;}
      if(analogRead(soapsensor)<soapmin) {State=TSoap;}
      if(analogRead(sinksensor)<sinkmin) {State=TWater;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      break;
    case DUnlock:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH && digitalRead(doorswitch)==LOW)
      { lockbuttonpress=1; State=Flush; LockState=Manual;}
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH)
      { dooropentime=0; State=DLeaving; }
      if(analogRead(soapsensor)<soapmin) {State=DSoap;}
      if(analogRead(sinksensor)<sinkmin) {State=DRinse;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case DLeaving:
      dooropentime++;
      if(digitalRead(doorswitch)==LOW || dooropentime>dooropenmax)
      { dooropentime=0; State=Blank; }
      if(analogRead(soapsensor)<soapmin) {State=DSoap;}
      if(analogRead(sinksensor)<sinkmin) {State=DRinse;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case DSoap:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=DUnlock; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH)
      { dooropentime=0; State=DLeaving; }
      if(analogRead(sinksensor)<sinkmin) {State=Clean;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case DRinse:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=DUnlock; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH)
      { dooropentime=0; State=DLeaving; }
      if(analogRead(soapsensor)<soapmin) {State=DSoap;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case Clean:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1;
        if(LockState==Manual) {LockState=Auto;}
        /*if(LockState==Auto && digitalRead(doorswitch)==LOW) {LockState=Manual;} */}
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH)
      { dooropentime=0; State=CLeaving; }
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case CLeaving:
      dooropentime++;
      if(digitalRead(doorswitch)==LOW || dooropentime>dooropenmax)
      { dooropentime=0; State=Blank; }
      break;
    case TUnlock:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH && digitalRead(doorswitch)==LOW)
      { lockbuttonpress=1; State=Toilet; LockState=Manual; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH) {dooropentime=0; State=TLeaving;}
      if(analogRead(soapsensor)<soapmin) {State=TSoap;}
      if(analogRead(sinksensor)<sinkmin) {State=TWater;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case TLeaving:
      dooropentime++;
      if(digitalRead(doorswitch)==HIGH || dooropentime<50)
      { dooropentime=0; State=Blank; }
      if(analogRead(soapsensor)<soapmin) {State=TSoap;}
      if(analogRead(sinksensor)<sinkmin) {State=TWater;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case TSoap:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=TUnlock; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH)
      { dooropentime=0; State=TLeaving; }
      if(analogRead(sinksensor)<sinkmin) {State=TWater;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
    case TWater:
      if(lockbuttonpress==0 && digitalRead(lockbutton)==HIGH)
      { lockbuttonpress=1; State=TUnlock; }
      if(digitalRead(lockbutton)==LOW) {lockbuttonpress=0;}
      if(digitalRead(doorswitch)==HIGH)
      { dooropentime=0; State=TLeaving; }
      if(analogRead(soapsensor)<soapmin) {State=TSoap;}
      if(digitalRead(flushbutton)==HIGH) {State=Flush;}
      if(digitalRead(toiletswitch)==HIGH) {State=Toilet;}
      break;
  }

  // SET CONDITIONS //
  switch(State)
  {
    case Blank:
      dooropentime = 0;
      Reward = Off; Buzzer = Off;
      Sign = Bl_Bl;
      Soap = White; Sink = Off;
      Lock = Off;   LockState = Auto;
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      break;
    case Locked:
      Reward = Off; Buzzer = Off;
      Sign = Bl_Bl;
      Soap = White; Sink = Off;
      Lock = On;    LockState = Manual;
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      break;
    case Wash:
      Reward = Off; Buzzer = Off;
      Sign = Bl_Bl;
      Soap = White; Sink = Off;
      Lock = Off;   LockState = Auto;
      if(analogRead(soapsensor)<soapmin) {Soap = Green;}
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      break;
    case LockWash:
      Reward = Off; Buzzer = Off;
      Sign = Bl_Bl;
      Soap = White; Sink = Off;
      Lock = On;    LockState = Manual;
      if(analogRead(soapsensor)<soapmin) {Soap = Green;}
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      break;
    case Flush: // do not set LockState
      Reward = Off; Buzzer = Off;
      Sign = Wa_Bl;
      Soap = Red;   Sink = Off;
      Lock = On;
      break;
    case Toilet: // do not set LockState
      Reward = Off; Buzzer = Off;
      Sign = Fl_Bl;
      Soap = White; Sink = Off;
      Lock = On;
      break;
    case DUnlock:
      Reward = Off; Buzzer = Off;
      Sign = Wa_Di;
      Soap = Red;   Sink = Off;
      Lock = Off;   LockState = Auto;
      break;
    case DLeaving:
      Reward = Off; Buzzer = On;
      Sign = Wa_Di;
      Soap = Red;   Sink = Off;
      Lock = Off;   LockState = Auto;
      break;
    case DSoap: // do not set LockState
      Reward = Off; Buzzer = Off;
      Sign = Wa_Bl;
      Soap = Red;   Sink = Off;
      Lock = On;
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      if(analogRead(soapsensor)<soapmin) {Soap = Green;}
      break;
    case DRinse: // do not set LockState
      Reward = Off; Buzzer = Off;
      Sign = Ri_Bl;
      Soap = Red;   Sink = Off;
      Lock = On;
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      break;
    case Clean:
      Reward = Off; Buzzer = Off;
      Sign = Th_Cl;
      Soap = White; Sink = Off;
      if(analogRead(soapsensor)<soapmin) {Soap = Green;}
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      if(LockState==Auto) {Lock = Off;} else {Lock = On;}
      break;
    case CLeaving:
      Reward = On; Buzzer = Off;
      Sign = Th_Cl;
      Soap = White; Sink = Off;
      Lock = Off; LockState = Auto;
      break;
    case TUnlock:
      Reward = Off; Buzzer = Off;
      Sign = Fl_Fl;
      Soap = White; Sink = Off;
      Lock = Off;   LockState = Auto;
      break;
    case TLeaving:
      Reward = Off; Buzzer = On;
      Sign = Fl_Fl;
      Soap = White; Sink = Off;
      Lock = Off;   LockState = Auto;
      break;
    case TSoap: // do not set LockState
      Reward = Off; Buzzer = Off;
      Sign = Fl_Bl;
      Soap = White; Sink = Off;
      Lock = On;
      if(analogRead(soapsensor)<soapmin) {Soap = Green;}
      break;
    case TWater: // do not set LockState
      Reward = Off; Buzzer = Off;
      Sign = Fl_Bl;
      Soap = White; Sink = Off;
      Lock = On;
      if(analogRead(sinksensor)<sinkmin) {Sink = On;}
      break;
  }

  // EXECUTE CONDITIONS //
  if(Reward==On) {digitalWrite(bell, HIGH);}
  else {digitalWrite(bell, LOW);}
  if(Buzzer==On) {digitalWrite(speaker, HIGH);}
  else {digitalWrite(speaker, LOW);}
  switch(Sign)
  {
    case Bl_Bl: sign.write(Bl_Bl); break;
    case Wa_Bl: sign.write(Wa_Bl); break;
    case Wa_Di: sign.write(Wa_Di); break;
    case Ri_Bl: sign.write(Ri_Bl); break;
    case Fl_Bl: sign.write(Fl_Bl); break;
    case Fl_Fl: sign.write(Fl_Fl); break;
    case Th_Cl: sign.write(Th_Cl); break;
  }
  Servo::refresh();
  switch(Soap)
  {
    case White:
      digitalWrite(soapLED_R, LOW);
      digitalWrite(soapLED_G, HIGH);
      digitalWrite(soapLED_B, HIGH);
      break;
    case Red:
      digitalWrite(soapLED_R, HIGH);
      digitalWrite(soapLED_G, LOW);
      digitalWrite(soapLED_B, LOW);
      break;
    case Green:
      digitalWrite(soapLED_R, LOW);
      digitalWrite(soapLED_B, HIGH);  // B & G pins reversed?
      digitalWrite(soapLED_G, LOW);
      break;
  }
  if(Sink==On) {digitalWrite(sinkLED, HIGH);}
  else {digitalWrite(sinkLED, LOW);}
  if(Lock==On && digitalRead(doorswitch)==LOW) {digitalWrite(locksolenoid, HIGH);}
  else {digitalWrite(locksolenoid, LOW);}
}

 

Filed under: Assignments, Cat Adams, Final Project — catadams @ 12:04 am

The automatic recycling machine is designed to bring a process that is currently only done on an industrial sale, that is, the sorting of recyclables to a smaller and more personal scale. I intend for this machine to be used primarily on college campuses and areas of high traffic. I hope for people to understand the importance of recycling by being more involved in the process.

Overall View of the Recycle-Tron

View of the interior wiring

Video of a glass bottle being recycled

Video of the Recycle-Tron getting angry at someone who doesn’t recycle

Code:


/*
         ---Automatic Recycling Sorter---
--Making Things Interactive Spring 08 Final Project--
                 ---Cat Adams---
*/

//states
static int Idle = 0;                        //name for Idle state
static int Excited = 1;                      //name for Excited state
static int Angry = 2;                        //name for Angry state
static int BigReward = 3;                    //name for the post-recycling Big Reward state
static int SmallReward = 4;                  //name for the post-recycling Big Reward state

//regular ints
int redLED = 2;                              //red LED connected to digital pin 2
int blueLED = 3;                             //blue LED connected to digital pin 3
int greenLED = 4;                            //green LED connected to digital pin 4
int siren = 7;                               //buzzer connected to digital pin 7
int pir = 8;                                 //pir sensor connected to digital pin 8
int currentState = Idle;                     //sets the beginning state to Idle
int numberCycle = 0;                         //sets the number of items recycled to zero

//recycling ints
int servoM = 10;                             //Metal sorting Servo
int Mangle;                                  //angle at which to turn servoM, set later
int servoG = 9;                              //Glass-Plastic sorting servo
int Gangle;                                  //angle at which to turn servoG, set later
int switchMetal = 12;                        //Metal sensing wires
int switchGlass = 11;                        //Glass-Plastic sorting swtich analog pin 1
int bottlesense = 13;                        //button switch sensing presence of a bottle
int GAngle2 = 45;                            //angle for servo to sort out glass (from plastic)
int PAngle = 90;                             //angle for servo to sort out plastic
int GAngle = 90;                             //angle to sort glass/plastic from metal
int MAngle = 45;                             //angle to sort metal
int pulseWidth;                              //servo variable 

//program for moving the metal servo
void metalPulse(int servoM, int Mangle){
  pulseWidth = (Mangle * 11) + 500;
  digitalWrite(servoM, HIGH);
  delayMicroseconds(pulseWidth);
  digitalWrite(servoM, LOW);
  delay(20);
}

//program for moving the glass/plastic servo
void glassPulse(int servoG, int Gangle){
  pulseWidth = (Gangle * 11) + 500;
  digitalWrite(servoG, HIGH);
  delayMicroseconds(pulseWidth);
  digitalWrite(servoG, LOW);
  delay(20);
}

//program for pulsing just one LED at a time
void PulseOne (int pin) {
  for (int i=0; i<=255; i++) {
    analogWrite(pin, i);
    delay(2);
  }
  for (int i=255; i>=0; i--) {
    analogWrite(pin, i);
    delay(1);
  }
}

void setup(){
  pinMode(switchMetal, INPUT);
  pinMode(servoM, OUTPUT);
  pinMode(servoG, OUTPUT);
  pinMode(switchGlass, INPUT);
  pinMode(siren, OUTPUT);
  pinMode(redLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(pir, INPUT);
  pinMode(bottlesense, INPUT);
  Serial.begin(9600);
}

void loop(){

  //Idle State: all LED's off, print "Idle" on computer screen
  if (currentState == Idle) {
    Serial.println("Idle");
    //turn all the LEDs off (in case a later state does not turn an led off)
    digitalWrite(blueLED, LOW);
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, LOW);

    delay(2000);

    if (digitalRead(pir) == LOW){                //if the pir sensor is tripped, a person is near and the machine goes into Excited mode
      currentState = Excited;
    }
    else{                                        //if no one is around, do nothing
      currentState = Idle;
    }
  }
  //Excited State: pulse all three LED's, print "Excited"
  if (currentState == Excited){
    Serial.println("Excited");
    delay(2000);
    digitalWrite(blueLED, HIGH);
    digitalWrite(greenLED, HIGH);
    delay(1000);
    digitalWrite(blueLED, LOW);
    digitalWrite(greenLED, LOW);
    delay(1000);
    digitalWrite(blueLED, HIGH);
    digitalWrite(greenLED, HIGH);
    delay(1000);
    digitalWrite(blueLED, LOW);
    digitalWrite(greenLED, LOW);
    delay(2000);

    if (digitalRead(bottlesense) == HIGH){             //if the bottle-sensing button is pressed, the bottle is either glass or plastic
      Serial.println("glass1");
      for (Mangle=20; Mangle<=105; Mangle++){
        metalPulse(servoM, Mangle);
      }
      delay (1000);
      if (digitalRead(switchGlass) == HIGH){           //if the glass/plastic sorting button is pressed, the servo tilts and places the bottle in the glass bin
        Serial.println("glass2");
        for (Gangle=50; Gangle<=95; Gangle++){
          glassPulse(servoG, Gangle);
        }
        delay (1000);
        numberCycle++;                                //add one to the current numberCycle count
        if (numberCycle <=5) {                        //if the new numberCycle count is less than 6, go to Small Reward state
          currentState = SmallReward;
        }
        else{                                         //if the numberCycle count exceeds 5, go to the Big Reward state
          currentState = BigReward;
        }
      }
      else{                                           //if the glass/plastic sorting button is NOT pressed, the servo tilts and places the bottle in the plastic bin
        plastic();
        numberCycle++;
        if (numberCycle <=5) {
          currentState = SmallReward;
        }
        else{
          currentState = BigReward;
        }
      }
    }
    else{                                             //if the bottle sensing button is NOT pressed
      if (digitalRead(switchMetal) == HIGH){          //but if the switchMetal circuit is connected, there is a metal can
        metal();
        numberCycle++;
        if (numberCycle<=5){
          currentState = SmallReward;
        }
        else{
          currentState = BigReward;
        }
      }
      else{                                           //if neither the button sensing switch or the switchMetal circuit is connected, then
        currentState = Angry;                         //the person is not recycling, so the machine becomes angry
      }
    }
  }
  //Angry State: pulse red LED and print "Angry!!"

  if (currentState == Angry){
    Serial.println("Angry!!");
    delay(2000);
    digitalWrite(siren, HIGH);
    PulseOne(redLED);
    digitalWrite(siren, LOW);
    PulseOne(redLED);
    digitalWrite(siren, HIGH);
    PulseOne(redLED);
    digitalWrite(siren, LOW);
    delay(2000);

    if (digitalRead(bottlesense) == HIGH){          //the person has a second chance to recycle... see above for comments
      Serial.println("glass1");
      for (Mangle=20; Mangle<=105; Mangle++){
        metalPulse(servoM, Mangle);
      }
      delay (1000);
      if (digitalRead(switchGlass) == HIGH){
        Serial.println("glass2");
        for (Gangle=50; Gangle<=95; Gangle++){
          glassPulse(servoG, Gangle);
        }
        delay (1000);
        numberCycle++;
        if (numberCycle <=5) {
          currentState = SmallReward;
        }
        else{
          currentState = BigReward;
        }
      }
      else{
        plastic();
        numberCycle++;
        if (numberCycle <=5) {
          currentState = SmallReward;
        }
        else{
          currentState = BigReward;
        }
      }
    }
    else{
      if (digitalRead(switchMetal) == HIGH){
        metal();
        numberCycle++;
        if (numberCycle<=5){
          currentState = SmallReward;
        }
        else{
          currentState = BigReward;
        }
      }
      else{
        currentState = Idle;
      }
    }
  }
  //Small Reward: print "Small Reward" and pulse the blue LED then the green LED

  if (currentState == SmallReward){
    Serial.println("Small Reward");
    PulseOne(blueLED);
    PulseOne(greenLED);
    PulseOne(blueLED);
    PulseOne(greenLED);

    currentState = Idle;
  }

  //Big Reward: print "Big Reward" and pulse the blue then green then red LED
  if (currentState == BigReward){
    Serial.println("Big Reward");
    PulseOne(blueLED);
    PulseOne(greenLED);
    PulseOne(redLED);
    PulseOne(blueLED);
    PulseOne(greenLED);
    PulseOne(redLED);
    currentState = Idle;
  }
}

Blog at WordPress.com.