Making Things Interactive

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");}
}
Advertisements

March 25, 2008

assignment 9: Final Project Proposal of Fireflies in a Jar

Filed under: Assignments,Gee Kim — gskim @ 12:00 am
Tags:

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 fade out and 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 fireflies. The three fireflies will have different programs that will mimic the light of a firefly. The LED will start with a high intensity light and gradually fade out and turn off. This is going to give the pupil time to adjust in the dark to see better. Each light will also be programmed to have different time span 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 on/off 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.

All the switches used in this design will have a digital read, and the LEDs will have a analog output according to its corresponding switch. The switches will have a HIGH and LOW digital read. The brightness of the LEDs will be controlled using the “for” program code in the Loop Setup, and the “if” program code will be used to activate each firefly.

My final proposal of the Fireflies in a Jar project is a continuation from the midterm proposal. There are two aspects of the project that I would like to improve for a more finalized and presentable product.

The Program:
1. Change the code for the LED fireflies so that they mimic fireflies.
2. Have more than one loop program run at the same time. (The current mockup of the Fireflies in a Jar has three different loop programs for each LED firefly, and the each firefly light up one after the other. The first LED firefly program runs, then the next, then the last.)
3. Put in a code for interruption, so that when the jar opens when the program for an LED firefly is running, the LED firefly stops blinking, and only resumes when the jar is closed.

Aesthetics:
1. Use real jar
2. Clean up wiring
3. Make LED look like fireflies

Parts list: arduino, 3 yellow LED, wire, wiring tape, jar, plastic toy bugs, glue, 4switch 

Illustration: 

 

Wiring Diagram:

State Machine:

 

 

March 20, 2008

assignment 8: Personal Medication Tracker

Filed under: 8: State Machine,Assignments,Gee Kim — gskim @ 3:15 am

The state machine here shows how my Personal Medication Tracker works. This device is a tool that helps keep track of medication intake. So it begins by waiting for a patient. Once a patient stands on a mat (with a button sensor beneath it), the device recognizes that a patient is standing there, and prints onto the screen “Personal Medication Tracker, Name:, and Date:” Then it begins by asking a yes or no question on the screen, the answer would print onto the screen following the question. Then there is a delay until it is time to take the next medication. Then the next question is asked, and the answer in printed. Another delay until it is time to take the last medication. Then the last question is asked, and the answer is printed.

This information can be printed for the patient’s reference. There is also space for the patient to fill out their name and date.

(To refresh the device for the next day, simply press the refresh button on the arduino.)

medication-tracker-diagram.jpg


int switch1 = 5;  // patient sensor
int switch2 = 3;  // "yes" button
int switch3 = 6;  // "no" button
int led1 = 2;     // morning pill 1
int led2 = 1;     // morning pill 2
int led3 = 4;     // afternoon pill 1
int led4 = 7;     // dinner pill 1
int led5 = 8;     // dinner pill 2

void setup ()
{
  pinMode (switch1, INPUT);
  pinMode (switch2, INPUT);
  pinMode (switch3, INPUT);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  pinMode (led4, OUTPUT);
  pinMode (led5, OUTPUT);
  Serial.begin (9600);
}

void loop ()
{
  if (digitalRead(switch1==HIGH)){
    {
      Serial.println ("Personal Medication Tracker");
      Serial.println ("Name:");
      Serial.println ("Date:");
      Serial.println ("");
      Serial.println ("Did you take your morning pills?");
      YESorNOmorning ();
      Serial.println ("Did you take your afternoon pills?");
      YESorNOafternoon ();
      Serial.println ("Did you take your night pills?");
      YESorNOnight ();
    }
  }
}

void YESorNOmorning ()
{
  delay (5000);
  if (digitalRead(switch2==HIGH))
  {
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    Serial.println ("YES");
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))
   {
     digitalWrite(led1,LOW);
     digitalWrite(led2,LOW);
     Serial.println ("NO");
     Serial.println ("");
    }
     delay(5000);
}

void YESorNOafternoon ()
{
  delay (1000);
  if (digitalRead(switch2==HIGH))
  {
    digitalWrite(led3,HIGH);
    Serial.println ("YES");
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))
   {
     digitalWrite(led3,LOW);
     Serial.println ("NO");
     Serial.println ("");
    }
     delay(5000);
}

void YESorNOnight ()
{
  delay (1000);
  if (digitalRead(switch2==HIGH))
  {
    digitalWrite(led4,HIGH);
    digitalWrite(led5,HIGH);
    Serial.println ("YES");
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))
   {
     digitalWrite(led4,LOW);
     digitalWrite(led5,LOW);
     Serial.println ("NO");
     Serial.println ("");
   }
   delay(5000);
}


revised code


int switch1 = 5;  // patient sensor
int switch2 = 3;  // "yes" button
int switch3 = 6;  // "no" button
int led1 = 2;     // morning pill 1
int led2 = 1;     // morning pill 2
int led3 = 4;     // afternoon pill 1
int led4 = 7;     // dinner pill 1
int led5 = 8;     // dinner pill 2

void setup ()
{
  pinMode (switch1, INPUT);
  pinMode (switch2, INPUT);
  pinMode (switch3, INPUT);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  pinMode (led4, OUTPUT);
  pinMode (led5, OUTPUT);
  Serial.begin (9600);
}

void loop ()
{
  if (digitalRead(switch1==HIGH)){  // start machine at 8:00 am
    {                               //
      Serial.println ("Personal Medication Tracker");
      Serial.println ("Name:");     //
      Serial.println ("Date:");     //
      Serial.println ("");          //
      Serial.println ("Did you take your morning pills?");
      YESorNOmorning ();            //
      delay (14400000);             // 12:00pm
      Serial.println ("Did you take your afternoon pills?");
      YESorNOafternoon ();          //
      delay (21600000);             // 6:00pm
      Serial.println ("Did you take your night pills?");
      YESorNOnight ();              //
      delay (50400000);             // 8:00am

    }
  }
}

void YESorNOmorning ()              // when it's morning
{
  delay (5000);                     // delay 5 seconds
  if (digitalRead(switch2==HIGH))   // when "yes" button is pressed
  {
    digitalWrite(led1,HIGH);        // morning medicine 1 taken, led goes on
    digitalWrite(led2,HIGH);        // morning medicine 2 taken, led goes on
    Serial.println ("YES");         // print "yes"
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))  // when "no" button is pressed
   {
     digitalWrite(led1,LOW);        // morning medicine 1 not taken, led stays off
     digitalWrite(led2,LOW);        // morning medicine 2 not taken, led stays off
     Serial.println ("NO");         // print "no"
     Serial.println ("");
    }
     delay(5000);                   // delay 5 seconds
}

void YESorNOafternoon ()           // when it's afternoon
{
  delay (5000);                    // delay 5 seconds
  if (digitalRead(switch2==HIGH))  // when "yes" button is pressed
  {
    digitalWrite(led3,HIGH);       // morning afternoon medicine 1 taken, led goes on
    Serial.println ("YES");        // print "yes"
    Serial.println ("");
   }
  if (digitalRead(switch3==HIGH))  // when "no" button is pressed
   {
     digitalWrite(led3,LOW);       // afternoon medicine 1 not taken, led stays off
     Serial.println ("NO");        // print "no"
     Serial.println ("");
    }
     delay(5000);                  // delay 5 seconds
}

void YESorNOnight ()               // when night
{
  delay (1000);
  if (digitalRead(switch2==HIGH))  // when "yes" button is pressed
  {
    digitalWrite(led4,HIGH);       // night medicine 1 taken, led goes on
    digitalWrite(led5,HIGH);       // night medicine 2 taken, led goes on
    Serial.println ("YES");        // print "yes"
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH)) // when "no" button is pressed
   {
     digitalWrite(led4,LOW);       // night medicine 1 not taken, led stays off
     digitalWrite(led5,LOW);       // night medicine 2 not taken, led stays off
     Serial.println ("NO");        // print "no"
     Serial.println ("");
   }
   delay(5000);                    // delay 5 seconds
}
//

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
         }
      }
   }
}
}

March 2, 2008

assignment 6: servo and brightness

Filed under: 6: More Motion,Assignments,Gee Kim — gskim @ 12:40 am

Pic of the circuit setup

The angle of the servo changes as I turn the potentiometer. And when the value of the servo is at its highest, or when the angle of the servo is turned to its highest value of 93, the LED will gradually get bright.

pic of when servo val=93, and led gets brighter

And when the value of the servo is at its lowest, or when the angle of the servo is turned to its lowest value of 0, the LED will gradually get dim.

pic of when servo val=0, and led dims

here’s the circuit diagram: circuit diagram

here’s the code:


int servoPin = 3;     // connect servo to pin 3
int sensorPin = 2;    // connect potentiometer to pin 2
int brightness = 0;
int ledPin = 5;       // connect led to pin 5

void setup ()
{
  beginSerial (9600);            //
  pinMode (servoPin, OUTPUT);    // set servo as analog output
  pinMode (sensorPin, INPUT);    // set potentiometer as analog input
  pinMode (ledPin, OUTPUT);      // set led as analog output

}

void loop ()
{
   int val = analogRead(sensorPin) / 11;    // set "val" equal to the analog read of the sensor divided by 11
   Serial.println(val);                     // print the value of "val" on the serial monitor
   analogWrite(servoPin, val);              // as the value of the sensor changes, the servo should spin according to "val"

   if (analogRead(servoPin == 0))           // if the analogRead of the servoPin is 0
   {    for (brightness = 0; brightness > 255; brightness ++) // make LED get bright
        analogWrite (ledPin, brightness);
        delay (500);                       // delay for 0.5 seconds
   }
   if (analogRead(servoPin == 93))
   {    for (brightness = 255; brightness > 0; brightness --) // make LED dim
        analogWrite (ledPin, brightness);
        delay (500);                       // delay for 0.5 seconds
   }
}

February 27, 2008

Midterm Proposal: Fireflies in a Jar

Filed under: 7: Mid-Term Project,Assignments,Gee Kim — gskim @ 8:37 pm

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 fade out and 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 fireflies. The three fireflies will have different programs that will mimic the light of a firefly. The LED will start with a high intensity light and gradually fade out and turn off. This is going to give the pupil time to adjust in the dark to see better. Each light will also be programmed to have different time span 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 on/off 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.

All the switches used in this design will have a digital read, and the LEDs will have a digital output according to its corresponding switch. The switches will have a HIGH and LOW digital read. The brightness of the LEDs will be controlled using the “for” program code in the Loop Setup, and the “if” program code will be used to activate each firefly.

Parts List: Arduino, 3 LEDs (white), 4 on/off switch, jar with lid, 9V battery, circuit wire, wiring tape.

How to go about this project…

Step 1. Wire and program LED 1

Step 2. Wire and program LED 2

Step 3. Wire and program LED 3

Step 4. Wire 3 switches. Place each LED on its corresponding switch, and program it to activate when the LED is off of the switch.

Step 5. Wire the switch for the jar, and program so that the LEDs turn on when the jar switch is pressed and when the LED is off of its switch.

Step 6. Add an interruption code to the program, for when the jar is opens and closes.

Step 7. Test run design for error (different combination of LEDs in jar, and when jar opens and closes, etc.)

Step 8. Assemble parts for presentation.

February 21, 2008

assignment 5: solenoid & servo

Filed under: 5: Making Motion,Assignments,Gee Kim — gskim @ 6:11 pm

img_0533.jpg

I simply got my motors to work separately with two different sensors, but with one program.

The solenoid has a digital input from a photo sensor. The solenoid turns on and off depending on if it is dark or light.

The servo has a analog input from a potentiometer. The servo turns in ratio to the potentiometer.

here’s the code:


int servoPin = 3;     // connect servo to pin 3
int sensorPin = 2;    // connect potentiometer to pin 2
int solePin = 12;     // connect solenoid to pin 12
int photoPin = 4;     // connect photosensor to pin4

void setup ()
{
  beginSerial (9600);            //
  pinMode (servoPin, OUTPUT);    // set servo as analog output
  pinMode (sensorPin, INPUT);    // set potentiometer as analog input
  pinMode (solePin, OUTPUT);     // set solenoid as digital output
  pinMode (photoPin, INPUT);     // set photosensor as digital input
}

void loop ()
{
   int val = analogRead(sensorPin) / 11;    // set "val" equal to the analog read of the sensor divided by 11
   Serial.println(val);                     // print the value of "val" on the serial monitor
   analogWrite(servoPin, val);              // as the value of the sensor changes, the servo should spin according to "val"

   if (digitalRead(photoPin == HIGH))       // if digital read of photosensor is bright
   { digitalWrite(solePin, HIGH);}          // then turn solenoid on
   else                                     // otherwise
   { digitalWrite(solePin, LOW);}           // turn solenoid off
}

here’s the circuit diagram:circuit1.jpg

February 2, 2008

counting code: where is everyone?

Filed under: 4: Counting Sensor Input,Assignments,Gee Kim — gskim @ 6:17 pm

This program has a input switch that counts how many people are in the room, and depending on the number of people in the room, the red and green LED will light up, and the computer will print a certain phrase.

The red LED stays lit and the computer prints “WHERE IS EVERYONE?!?” when the switch is hit 5 or less times.

The red LED turns off, the green LED lights up, and the computer prints “HOORAH! everyone is here.” when the switch is hit for the 6th to 10th time.

The green LED turns off, the red LED turns back on, and the computer prints “GET OUT! there are too many ppl here.” when the switch is hit more than 10 times.

  

/*
* Where is everyone? (count code)
*/

int switchPin = 2;          // switch connected to digital pin 2
int count = 0;
int ledPin = 8;             // red led connected to digital pin 8
int ledPin2 = 10;           // green led connected to digital pin 10

void setup()                // run once, when the sketch starts
{
Serial.begin(9600);         // set up Serial library at 9600 bps
pinMode(switchPin, INPUT);  // sets the digital pin as input to read switch
pinMode(ledPin, OUTPUT);    // sets the digital pin as output to read pin
pinMode(ledPin2, OUTPUT);   // sets the digital pin as output to read pin 2
}

void loop()                                         // run over and over again
{
int newCount = count + digitalRead(switchPin);      // show count only when +1 than previous count
if( (newCount == count + 1)) {                      // if newCount is +1 than previous count
Serial.print("Number of ppl in the room: ");        // than print "Number of ppl in the room:"
Serial.println(newCount);                           // print the value of new count
count = newCount;                                   //
if (count <= 5) {                                   // if count <= 5
digitalWrite(ledPin, HIGH);                         // than turn on red led
Serial.println("WHERE IS EVERYONE?!?");             // and print "WHERE IS EVERYONE?!?"
}
else if ((count >= 6) && (count <= 10)) {           // if count is >= 6 AND <= 10
digitalWrite(ledPin, LOW);                          // than turn off red led
digitalWrite(ledPin2, HIGH);                        // and turn on green led
Serial.println("HOORAH! everyone is here.");        // and print "HOORAH! everyone is here."
}
else if (count >=11) {                              // if count is >= 11
digitalWrite(ledPin2, LOW);                         // than turn off green led
digitalWrite(ledPin, HIGH);                         // and turn on red led
Serial.println("GET OUT! too many ppl here!");      // and print "GET OUT! too many ppl here!"
}
}
delay(2000); // read every 2 seconds
}

February 1, 2008

Sleeping in the Dark

Filed under: 2: Term Project Idea,Assignments,Gee Kim — gskim @ 5:24 pm

So my new ideas for the final project…  I want to make a product that’s going to help children learn to sleep in the dark.

Catching Fireflies 

So for this project, I imagine a led light (aka firefly) that you can put into a clear jar.  The firefly will light up, and slowly dim out.  This will give time for your pupils to adjust in the dark, and for children to fall asleep as it gets darker in the room.  If the child needs more light, more fireflies can be placed into the jar.  Eventually, I would think that the child would be too tired to get up to put another firefly in the jar for more light… and so they would end up sleeping in the dark.

 Reading in the Dark

This would be a bedtime story book that adults can read to children right before they fall asleep.  It would be a book that lights up (around a certain radius of your finger) as you scroll through the text.  The book only lights up in the dark, so it encourages children to want to turn the light off for their bedtime story.  Eventually the child will fall asleep in the dark after their story, and if not, they can play with the book using it as a night light.

My Codes

Filed under: 3: LadyAda Tutorials,Assignments,Gee Kim — gskim @ 5:11 pm

My Blink

img_0446.jpg

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
digitalWrite(ledPin, HIGH);   // sets the LED on
delay(500);                  // waits for a second
digitalWrite(ledPin, LOW);    // sets the LED off
delay(900);                  // waits for a second
}

Alternating Green and Red

int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11

void setup()                      // run once, when the sketch starts
{
pinMode(redPin, OUTPUT);        // sets the digital pin as output
pinMode(greenPin, OUTPUT);      // sets the digital pin as output
}

void loop()                       // run over and over again
{
digitalWrite(redPin, HIGH);     // sets the Red LED on
digitalWrite(greenPin, LOW);   // sets the Green LED on
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);      // sets the Red LED off
digitalWrite(greenPin, HIGH);    // sets the Green LED off
delay(500);                     // waits for half a second
}

int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int bluePin = 10;

void setup()                      // run once, when the sketch starts
{
pinMode(redPin, OUTPUT);        // sets the digital pin as output
pinMode(greenPin, OUTPUT);      // sets the digital pin as output
pinMode(bluePin, OUTPUT);
}

void loop()                       // run over and over again
{
digitalWrite(redPin, HIGH);     // sets the Red LED on
digitalWrite(greenPin, HIGH);   // sets the Green LED on
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);      // sets the Red LED off
digitalWrite(greenPin, LOW);    // sets the Green LED off
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
}

Color Mixing

img_0451.jpg

int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int bluePin = 10;

void setup()                      // run once, when the sketch starts
{
pinMode(redPin, OUTPUT);        // sets the digital pin as output
pinMode(greenPin, OUTPUT);      // sets the digital pin as output
pinMode(bluePin, OUTPUT);
}

void loop()                       // run over and over again
{
digitalWrite(redPin, HIGH);     // sets the Red LED on
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);     // sets the Red LED on
delay(500);                     // waits for half a second
digitalWrite(redPin, HIGH);     // sets the Red LED on
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);     // sets the Red LED on
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
digitalWrite(greenPin, HIGH);    // sets the Green LED off
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(greenPin, LOW);    // sets the Green LED off
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
digitalWrite(greenPin, HIGH);    // sets the Green LED off
delay(500);                     // waits for half a second
digitalWrite(greenPin, LOW);    // sets the Green LED off
delay(500);                     // waits for half a second
digitalWrite(greenPin, HIGH);    // sets the Green LED off
digitalWrite(redPin, HIGH);     // sets the Red LED on
delay(500);                     // waits for half a second
digitalWrite(greenPin, LOW);    // sets the Green LED off
digitalWrite(redPin, LOW);     // sets the Red LED on
delay(500);                     // waits for half a second
}

HelloWorld

void setup()                    // run once, when the sketch starts
{
Serial.begin(9600);           // set up Serial library at 9600 bps
Serial.println(“Hello world!”);  // prints hello with ending line break
}

void loop()                       // run over and over again
{
// do nothing!
}

HelloWorld 20 Times with Delay

void setup()                    // run once, when the sketch starts
{
Serial.begin(9600);           // set up Serial library at 9600 bps

}

void loop()                       // run over and over again
{
Serial.println(“Hello world!”);  // prints hello with ending line break
delay(1000);
}

DriveCalc


/*
* Drive size calculator!
*/

int drive_gb = 100;
long drive_mb;
long drive_kb;
long real_drive_mb;
long real_drive_kb;

void setup()                    // run once, when the sketch starts
{
Serial.begin(9600);           // set up Serial library at 9600 bps

Serial.print(“Your HD is “);
Serial.print(drive_gb);
Serial.println(” GB large.”);

drive_mb = drive_gb;
drive_mb = drive_mb * 1024;
drive_kb = drive_mb * 1024;

Serial.print(“In theory, it can store “);
Serial.print(drive_mb);
Serial.print(” Megabytes, “);
Serial.print(drive_kb);
Serial.println(” Kilobytes.”);

real_drive_mb = drive_gb;
real_drive_mb = real_drive_mb * 1000;
real_drive_kb = real_drive_mb * 1000;

Serial.print(“But it really only stores “);
Serial.print(real_drive_mb);
Serial.print(” Megabytes, “);
Serial.print(real_drive_kb);
Serial.println(” Kilobytes.”);

Serial.print(“You are missing “);
Serial.print(drive_kb – real_drive_kb);
Serial.println(” Kilobytes!”);
}

void loop()                       // run over and over again
{
}

Turning on LED with Switch

img_0455.jpg

Next Page »

Blog at WordPress.com.