Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Revision of Dusk Houseplant from Fri, 10/05/2007 - 14:21

Project Members: 
Lora Oehlberg

Description

 "Dusk Houseplant" is a system embedded into a houseplant (already an ambient piece of many home and office decor).  Intended for use in my lab/office, "Dusk Houseplant" ambiently informs people in the lab when it is nighttime (and perhaps, when they should think about not working, going home, and having some dinner).  It uses the photosensor to detect the light levels (which can be adjusted using a global variable... for changing seasons).  As the light level dies down, the "moon" LED grows brighter, illuminating the plant and its pot.  Eventually, "crickets" begin to chirp from inside the plant, signaling to the people in the room that yes, it is dark outside and yes, they should think about going home.

Materials

  • LEDs (2, one for the moon and one for the cricket)
  • Photosensor
  • Breadboard
  • Resistors
  • Houseplant (relatively large so it can fit the Arduino and breadboard) 

Code

/* Dusk Plant
* BY: Lora Oehlberg
* Adapted From:
* Play Melody
 * -----------
 *
 * Program to play melodies stored in an array, it requires to know
 * about timing issues and about how to play tones.
 *
 * The calculation of the tones is made following the mathematical
 * operation:
 *
 *       timeHigh = 1/(2 * toneFrequency) = period / 2
 *
 * where the different tones are described as in the table:
 *
 * note     frequency     period     PW (timeHigh)   
 * c             261 Hz             3830     1915    
 * d             294 Hz             3400     1700    
 * e             329 Hz             3038     1519    
 * f             349 Hz             2864     1432    
 * g             392 Hz             2550     1275    
 * a             440 Hz             2272     1136    
 * b             493 Hz             2028    1014   
 * C            523 Hz            1912     956
 *
 * (cleft) 2005 D. Cuartielles for K3
 */
int photoPin = 0;   // select the input pin for photo sensor
int moonPin = 11;
int cricketPin = 13;
int speakerOut = 7;              
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; 
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 550, 600};
byte melody[] = "1C1b1C1b";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
//                                10                  20                  30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 10;
int statePin = LOW;
int i = 0; // delay system
int moon = 0;
int sun = 1;
int val = 0;        // variable to store the value coming from the sensor
int sun_threshold = 3;
// adjust based on ambient light levels
int sun_max = 40;
int sun_min = 0;
void setup() {
 Serial.begin(9600);
 pinMode(cricketPin, OUTPUT);
 pinMode(speakerOut, OUTPUT);
}
void loop() {
for (i=0; i<1000; i++){
//  Serial.println(i);
  sun = test_sun();
  moon = 255/((sun+1) * 6);
  Serial.println("MOON:");
  Serial.println(moon);
  analogWrite(moonPin, moon);  // analogWrite (dimming the LED) can be between 0-255
if ((i == 999) && (sun < sun_threshold)){
    Serial.print("go team!");
    i = 0;
    digitalWrite(cricketPin, statePin);
    chirpchirp();
    delay(350);
    chirpchirp();
    }
  }
}
int test_sun(void){
  val = analogRead(photoPin); // read the value from the sensor, 0-1023
//  Serial.println("SUN:");
//  Serial.println(val);
  return val;
}
void chirpchirp(void){
  digitalWrite(speakerOut, LOW);    
  for (count = 0; count < MAX_COUNT; count++) {
    statePin = !statePin;
    digitalWrite(cricketPin, statePin);
    for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
      for (count2=0;count2<8;count2++) {
        if (names[count2] == melody[count*2 + 1]) {      
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(tones[count2]);
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(tones[count2]);
        }
        if (melody[count*2 + 1] == 'p') {
          // make a pause of a certain size
          digitalWrite(speakerOut, 0);
          delayMicroseconds(500);
        }
      }
    }
  }
}

 

Photos

(pictures coming soon) 


Powered by Drupal - Design by Artinet