Making Things Interactive

May 14, 2008

spiderbot

Filed under: 1: Post Something Interesting,Gaku Sato — ponkotsu @ 9:01 am

dies ist mein spiderbot.  i worked on it all semester.  i think it came out real good and i just wanted to show everyone.

http://www.andrew.cmu.edu/user/gsato/spiderbot.jpg

Washroom Penitentiary [term paper]

Filed under: Final Project,Gaku Sato,Term Paper — ponkotsu @ 8:52 am

[final paper]

[final paper appendix]

Final Project: PhytoBot “Augmenting Plant Behavior Through Robotics”

The PhytoBot is a semi-intelligent plant which responds to external stimulus (light intensity and light location) and responds to it as a phototropic plant would. Essentially it is designed as a piece of interactive artwork for operation over a long period of time. The motivation driving this was triggered by the lack of understanding & acceptance of plants as reactive living organisms. Many of us are so used to placing life on merely objects that have visual and audible external responses which can be seen by the naked eye. Plants on the other hand tend to be overlooked as their responses are more drawn out over time and hence we tend to see them as inanimate objects.

 

The PhytoBot has two degrees of freedom and motion, rotational and angular (from the normal). The rotational range of motion is 360 degrees whereas the vertical/angular range is approximately 70 degrees. The second component of the response is the pulsing lights on the face. The lights pulse from on to off in a smooth glowing fashion as if the plant was breathing. The variance in frequency is driven by the amount of light given to the plant. A fast pulse indicates that the plant is healthy, and a slow pulse indicates that the plant is in need of more light. There are two basic mechanical features within the PhytoBot. When the PhytoBot actively seeks light, it is oriented by two servos in the x and y axes. When the light has been located the plant will twitch depending on how far away the light source is. For example a closer point light will produce more twitching than if the Plant was facing the sun.  

Parts List:

– Plastic Laser Cut Structural Parts
– Foam Petals
– Foam core Box
– 4 Photo sensors
– 1 Green LED
– Wire (Solid core Flexible)
– Cable Wire
– 1 Standard Servo
– 1 Continuous rotation servo
– Screws
– 1 Arduino Microcontroller
– 4 100kOhm resistors
– Circuit boards for soldering components
– Acrylic glue

How it is Built: The PhytoBot is built primarily from laser cut acrylic parts. It was paramount to have my parts laser cut as they needed to fit correctly with minimal error. The whole plant can be divided up into 4 segments, the fixed base, rotating housing, stem and face. Each segment has their specific application and all working together complete the PhytoBot. The fixed base houses the rotational servo which in turn rotates the whole rotating housing. The rotating housing contains the stem servo. This stem servo is attached to the face via a cable wire through the stem. The stem supports the plant as it stands erect and also provides just the right amount of resistance to allow the plant to return to its erect position when not being pulled down. The face contains all the sensors and lights which provide the input and outputs of the whole plant. All the parts barring the petals were glues together using acrylic glue. This provided a strong hold and minimal movement/slop between the moving components.

Currently Im working on making a complete days time lapse video of my plant. Its a lot harder than I thought so the video isnt up as yet

May 13, 2008

Fireflies in a Jar

Filed under: Assignments,Final Project,Gee Kim,Students — gskim @ 2:46 am

    

Fireflies in a Jar is a teaching tool for children who can’t sleep in the dark. There’

s going to be three differently programmed fireflies and a jar where the child can place them in. Before going to bed, the child can place as many fireflies into the jar and close the lid to activate the light. You can adjust the luminosity of the jar by putting more or less fireflies in. The light from each firefly will eventually turn off within a certain time span. The child at this point will either be too tired to put in more fireflies, and end up sleeping in the dark, or still be awake. Then they have the option of putting more fireflies in to reactive the light or sleeping in the dark.

The program of the different combination of fireflies. The different combinations of fireflies will have different programs that will mimic the light of a firefly. The LED will blink or glow at different speeds with different delay times. Each light will also be programmed to have different time span for it to be on, keeping the fireflies spontaneous and fun for the child.

How will it work? Each firefly will have an LED attached to it. The fireflies will sit on its own on/off switch. Removing the firefly from the switch will let us know which firefly is being put into the jar and need to be on once the jar is closed. The jar will also have a mercury tilt sensor, attached to the lid, that will tell us when the jar is closed. Once a firefly is placed into the jar, and the jar is closed, the program for that firefly will run as long as the jar is closed. If the jar opens and closes, with the same firefly in the jar, the program of that firefly will restart. This works with all the fireflies.

Parts List: Arduino, circuit wire, conductive thread, tape, 3 LEDs, mercury tilt sensor, ribbon, wooden box, jar

Video Demonstration: 

Circuit diagram: 

Wiring:

    

code:


int tiltSensor = 3;    // connect tiltSensor to pin 3
int ffHome1 = 9;       // connect home1 to pin 9
int ffHome2 = 10;      // connect home2 to pin 10
int ffHome3 = 11;      // connect home3 to pin 11
int ffLite1 = 5;       // connect ff1 to pin 5
int ffLite2 = 6;       // connect ff2 to pin 6
int ffLite3 = 7;       // connect ff3 to pin 7
int count1 = 5;        // set glow to 5 times
int count2 = 3;        // set glow to 3 times
int count3 = 7;        // set glow to 7 times
int count4 = 4;        // set glow to 4 times
int count5 = 2;        // set glow to 2 times
int count6 = 5;        // set glow to 5 times
int count7 = 10;       // set glow to 10 times
int brightness = 0;    //

void setup ()
{
  pinMode (tiltSensor, INPUT);  // set switch 0 as digital input
  pinMode (ffHome1, INPUT);     // set switch 1 as digital input
  pinMode (ffHome2, INPUT);     // set switch 2 as digital input
  pinMode (ffHome3, INPUT);     // set switch 3 as digital input
  pinMode (ffLite1, OUTPUT);    // set led 1 as analog output
  pinMode (ffLite2, OUTPUT);    // set led 2 as analog output
  pinMode (ffLite3, OUTPUT);    // set led 3 as analog output
  Serial.begin(9600);           //
}

void ffOFF(int ff)         // when "ffOFF" is stated
 {                         //
 digitalWrite(ff, HIGH);   // ff don't glow
 }                         //

void glow(int ff, int slowness)           // when "glow" is stated
{                                         //
  for (brightness = 0; brightness < 255; brightness ++)
         { analogWrite (ff, brightness);  // make ff glow
           delay (slowness);              // delay
         }                                //
  for (brightness = 255; brightness > 0; brightness --)
         { analogWrite (ff, brightness);  // then make ff dim
          delay (slowness);               // delay
         }
 }

void glow2(int ff1, int ff2, int slowness) // when "glow2" is stated
{                                          //
  for (brightness = 0; brightness < 255; brightness ++)
         { analogWrite (ff1, brightness);  // make ff1 glow
           analogWrite (ff2, brightness);  // make ff2 glow
           delay (slowness);               // delay
         }                                 //
  for (brightness = 255; brightness > 0; brightness --)
         { analogWrite (ff1, brightness);  // then make ff1 dim
           analogWrite (ff2, brightness);  // then make ff2 dim
          delay (slowness);                // delay
         }
 }

void glow3(int ff1, int ff2, int ff3, int slowness)  // when "glow3" is stated
{                                                    //
  for (brightness = 0; brightness < 255; brightness ++)
         { analogWrite (ff1, brightness);  // make ff1 glow
           analogWrite (ff2, brightness);  // make ff2 glow
           analogWrite (ff3, brightness);  // make ff3 glow
           delay (slowness);               // delay
         }                                 //
  for (brightness = 255; brightness > 0; brightness --)
         { analogWrite (ff1, brightness);  // then make ff1 dim
           analogWrite (ff2, brightness);  // then make ff2 dim
           analogWrite (ff3, brightness);  // then make ff3 dim
          delay (slowness);                // delay
         }
 }

void loop ()
{
  Serial.println(digitalRead (tiltSensor));
 if (digitalRead (tiltSensor) == HIGH) {  // when jar is closed
  Serial.println ("the jar is closed, fireflies awake");  

    if(digitalRead (ffHome1) == LOW)      // and when ff1 is not home
    {if (count1 > 0) {                    //
       glow (ffLite1, 5);                 // glow ff1
       count1 = count1 - 1;}}             // 5 times.
    else                                  //
      {ffOFF(ffLite1);                    // when ff1 is home, don't glow
       count1 = 5; }                      // set glow back to 5 times. 

    if(digitalRead (ffHome2) == LOW)      // and when ff2 is not home
    {if (count1 > 0){                     //
       glow (ffLite2, 5);                 // glow ff2
       count2 = count2 - 1;}}             // 3 times.
     else                                 //
       {ffOFF(ffLite2);                   // when ff2 is home, don't glow
       count2 = 3;}                       // set glow back to 3 times.

    if(digitalRead (ffHome3) == LOW)      // and when ff3 is not home
    {if (count1 > 0){                     //
       glow (ffLite3, 5);                 // glow ff3
       count3 = count3 - 1;}}             // 7 times.
     else                                 //
       {ffOFF(ffLite3);                   // when ff3 is home, don't glow
       count3 = 7;}                       // set glow back to 7 times.

    if(digitalRead (ffHome1) == LOW && digitalRead (ffHome2) == LOW )  // and when ff1 and ff2 is not home
    {if (count1 > 0){                     //
       glow2 (ffLite1, ffLite2, 5);       // glow ff1 and ff2
       count4 = count4 - 1;}}             // 4 times.
     else                                 //
      {ffOFF(ffLite1);                    // when ff1 is home, don't glow
       ffOFF(ffLite2);                    // when ff1 is home, don't glow
       count4 = 4;}                       // set glow back to 4 times. 

    if(digitalRead (ffHome1) == LOW && digitalRead (ffHome3) == LOW )  // and when ff1 and ff3 is not home
    {if (count1 > 0){                    //
       glow2 (ffLite1, ffLite3, 5);      // glow ff1 and ff3
       count5 = count5 - 1;}}            // 2 times.
    else                                 //
      {ffOFF(ffLite1);                   // when ff1 is home, don't glow
       ffOFF(ffLite3);                   // when ff3 is home, don't glow
       count5 = 2;}                      // set glow back to 4 times.  

    if(digitalRead (ffHome2) == LOW && digitalRead (ffHome3) == LOW )  // and when ff2 and ff3 is not home
    {if (count1 > 0){                    //
      glow2 (ffLite2, ffLite3, 5);       // glow ff2 and ff3
      count6 = count6 - 1;}}             // 5 times.
    else                                 //
      {ffOFF(ffLite2);                   // when ff2 is home, don't glow
       ffOFF(ffLite3);                   // when ff3 is home, don't glow
       count6 = 5;}                      // set glow back to 5 times. 

    if(digitalRead (ffHome1) == LOW && digitalRead (ffHome2) == LOW && digitalRead (ffHome3) == LOW )  // and when ff1, ff2, and ff3 is not home
    {if (count1 > 0){                        //
      glow3 (ffLite1, ffLite2, ffLite3, 5);  // glow ff1, ff2, and ff3
      count7 = count7 - 1;}}                // 10 times.
    else                                     //
      {ffOFF(ffLite1);                       // when ff1 is home, don't glow
       ffOFF(ffLite2);                       // when ff2 is home, don't glow
       ffOFF(ffLite3);                       // when ff3 is home, don't glow
       count7 = 10;}                         // set glow back to 10 times.
 }
 if (digitalRead (tiltSensor) == LOW)        // when jar is opened
 {ffOFF(ffLite1);                            // ff1 don't glow
  ffOFF(ffLite2);                            // ff2 don't glow
  ffOFF(ffLite3);                            // ff3 don't glow
  Serial.println("the jar is OPEN; fireflies asleep");}
}

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; } } [/sourcecode]

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

// 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)dooropenmax)
{ dooropentime=0; State=Blank; }
if(analogRead(soapsensor)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)

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; } } [/sourcecode]

Next Page »

Blog at WordPress.com.