Making Things Interactive

March 10, 2008

Midterm Project: Fireflies in a Jar

Filed under: 7: Mid-Term Project,Assignments,Gee Kim — gskim @ 2:00 am

Fireflies in a Jar is attaching tool for children who can’t sleep in the dark. This tool is going to help the child learn to adjust their pupils in the dark, and eventually get used to the darkenss of the room. Hopefully this will take away their fear of the dark.

_______________________

Here is how I set up the wiring from the arduino to the bread board to the jar:

img_0573.jpg

And here is the circuit diagram:

circuit3.jpg

As you can see from the image above, there is a master/mercury switch that is attached to the jar. There are also three LEDs that correspond to three different switches.

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 has a mercury switch, 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.

(for more info on this project, read “Midterm Proposal: Fireflies in a Jar”)

_______________________

Parts List: Arduino, 3 LEDs (white), 3 on/off switch, mercury switch, jar/box with lid, circuit wire, wiring tape

_______________________

Here are the links to the video demonstration of how it works:

int switchPin0 = 7;    // connect switch 0 to pin 0
int switchPin1 = 2;    // connect switch 1 to pin 1
int switchPin2 = 3;    // connect switch 2 to pin 2
int switchPin3 = 4;    // connect switch 3 to pin 3
int ledPin1 = 9;       // connect led 1 to pin 9
int ledPin2 = 10;      // connect led 2 to pin 10
int ledPin3 = 11;      // connect led 3 to pin 11
int brightness = 0;    //

void setup ()
{
  pinMode (switchPin0, INPUT);  // set switch 0 as digital input
  pinMode (switchPin1, INPUT);  // set switch 1 as digital input
  pinMode (switchPin2, INPUT);  // set switch 2 as digital input
  pinMode (switchPin3, INPUT);  // set switch 3 as digital input
  pinMode (ledPin1, OUTPUT);    // set led 1 as analog output
  pinMode (ledPin2, OUTPUT);    // set led 2 as analog output
  pinMode (ledPin3, OUTPUT);    // set led 3 as analog output
  //Serial.begin(9600);
}

void loop ()
{
 //Serial.println(digitalRead(switchPin0));
 if (digitalRead (switchPin0) == LOW){         // when switch 0 is low
    if(digitalRead (switchPin1) == HIGH){      // and when switch 1 is high
      { for (brightness = 0; brightness < 255; brightness ++)
         { analogWrite (ledPin1, brightness);  // make LED get bright
           delay (5);                          // delay for 0.5 seconds
         }
      }
      { for (brightness = 255; brightness > 0; brightness --)
         { analogWrite (ledPin1, brightness);  // then make LED dim
          delay (5);                           // delay for 0.5 seconds
         }
      }
   }
    if (digitalRead (switchPin2) == HIGH){     // and when switch 2 is high
      { for (brightness = 0; brightness < 255; brightness ++)
         { analogWrite (ledPin2, brightness);  // make LED get bright
           delay (5);                          // delay for 0.5 seconds
         }
      }
      { for (brightness = 255; brightness > 0; brightness --)
         { analogWrite (ledPin2, brightness);  // then make LED dim
          delay (5);                           // delay for 0.5 seconds
         }
      }
    }
   if (digitalRead (switchPin3) == HIGH){      // and when switch 3 is high
      { for (brightness = 0; brightness < 255; brightness ++)
         { analogWrite (ledPin3, brightness);  // make LED get bright
           delay (5);                          // delay for 0.5 seconds
         }
      }
      { for (brightness = 255; brightness > 0; brightness --)
         { analogWrite (ledPin3, brightness);  // then make LED dim
          delay (5);                           // delay for 0.5 seconds
         }
      }
   }
}
}
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: