Making Things Interactive

May 11, 2008

Pouring Light Bowl

Filed under: Assignments,Christopher Bridgman,Final Project — cbridgma @ 9:22 pm

This is a project that explores the idea of light transfer. This shows the process of 2 attempts at creating the pouring light table. The first exploration shows my first stab at the project, and the second shows some of the improvements. The idea behind this is to allow the user to create a mood that he/she wants. I envisioned this going into, say a night club table. This would allow the people to use the table to set their mood lighting. The bowl allows the user to vary the amount of light that they want within the bowl. You use the light cup, which has an infinite source of light to pour the light into the bowl until the desired light level is reached. Once you are done, or if you want to drain the light, you use the draining mechanisms to drain the bowl.

Version 1 Process photos:

1)LEDs soldered in Parallel Series2)Bread Board and Light Cup

3)Infinite Light Cup4)Final Effect of Table and Cup

5)Final Set Up6)Final Look

 

Captions:

1) Process photo showing how the LEDs are soldered together in parallel series, which reduces power drop off when the LEDs are lit.

2) A photo showing the final bread board set ups for the power transistors and the light cup.

3) A close up of the bread board set up of the light cup with the “infinite light source.”

4) A photo of the final effect for this first stab at the project.

5) A photo of the final set up of the LEDs and how the bread board fits within the box.

6) A photo of the final product of the first version of this product.

A Video of how this version of the Final Project Works:

Code For this Version:

int statusPin = 13;                // LED connected to digital pin 13
int ledRing1 = 11;                      // Ring 1 connected to analog 5
int ledRing2 = 10;                     // Ring 2 connected to analog 4
int ledRing3 = 6;                     // Ring 3  Connected to analog 3
int ledRing4 = 5;                    // Ring 4 Connected to analog 2
int tiltPin = 3;                 // tilt switch connected to 7
int switchPin = 2;                   // push switch connected to 6
int tiltval;
int switchval;
int Ring1val = 0;
int Ring2val = 0;
int Ring3val = 0;
int Ring4val = 0;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(ledRing1, OUTPUT);         // sets the digital pin as output
  pinMode(ledRing2, OUTPUT);      // sets the digital pin as output
  pinMode(ledRing3,OUTPUT);         // sets the digital pin as output
  pinMode(ledRing4,OUTPUT);        // sets the digital pin as output
  pinMode(tiltPin, INPUT);            // sets the pin as input
  pinMode(switchPin, INPUT);            // sets the pin as input
  Serial.begin(9600); 
}

void loop()                     // run over and over again
{
  tiltval = digitalRead(tiltPin);        // set tiltval egual to the tiltPin reading
  switchval = digitalRead(switchPin);        // set switchval equal to the switchPin reading

  Serial.print("Tilt Value: ");
  Serial.println(tiltval);    

  Serial.print("Switch Value: ");
  Serial.println(switchval);   

  digitalWrite(statusPin, HIGH);

  if ( tiltval == 0)
  {
    if ( Ring1val < 255)
    {
      analogWrite ( ledRing1, Ring1val++);    }
    if ( Ring1val == 255 && Ring2val < 255)
    {
      analogWrite (ledRing2, Ring2val++);    }
    if ( Ring1val == 255 && Ring2val == 255 && Ring3val < 255)
    {
      analogWrite (ledRing3, Ring3val++);    }
    if ( Ring1val == 255 && Ring2val == 255 && Ring3val == 255 && Ring4val < 255)
    {
      analogWrite (ledRing4, Ring4val++);    }
  }
 
  if ( switchval == 1)
  {
    if ( Ring4val > 0)
    {
      analogWrite ( ledRing4, Ring4val--);    }
    if ( Ring3val > 0 && Ring4val == 0)
    {
      analogWrite (ledRing3, Ring3val--);    }
    if ( Ring2val > 0 && Ring3val == 0 && Ring4val == 0)
    {
      analogWrite (ledRing2, Ring2val--);    }
    if ( Ring1val > 0 && Ring2val == 0 && Ring3val == 0 && Ring4val == 0)
    {
      analogWrite (ledRing1, Ring1val--);    }
  }

} 

 

Final Version Photos:

1)Light Bowl2)LED detail

3)Final Bread Board4)Final Soldering

5)Cup Bread Board6)Light Tap

 

Captions:

1) A Final photo of the bowl which shows how the bowl is shaped and connected as well as the LEDs.

2) A detail shot showing how the LEDs fit into holes cut within the plexi-glass bowl.

3) A photo of the final bread board set up; what a mess of wires!

4) A photo of the final hardware set up of the soldering showing how it is set up in parallel series. This is done so the LEDs do not get dimmer due to power drop off.

5) The final set up for the cup bread board with the infinite red light source and the gravity/tilt switch.

6) A photo of the light tap from which the light pours out of the bowl.

A circuit diagram for the final product: final-mti-project-schematic

Video of the Final Product:

Code for the Final Product:


int tiltPin = 15;                 // tilt switch connected to 7
int tiltval;
int ledRing1R = 12;                // LED ring connected to digital pin 12
int ledRing2R = 9;                 // LED ring connected to digital pin 9
int ledRing3R = 10;                 // LED ring connected to digital pin 10
int ledRing4R = 11;                 // LED ring connected to digital pin 11
int redTap = 13;                    //Red Light for the tap
int Rswitch = 8;                    //tap switch for drainging red light
int switchRval;
int Rsource = 14;                    //endless sourse of red light for cup
int ledRing1Rval = 0;                // starting the value of LEDs at zero
int ledRing2Rval = 0;                 // starting the value of LEDs at zero
int ledRing3Rval = 0;                 // starting the value of LEDs at zero
int ledRing4Rval = 0;                   // starting the value of LEDs at zero

void setup()                    // run once, when the sketch starts
{
  pinMode(Rsource, OUTPUT);      // sets the digital pin as output
  pinMode(ledRing1R, OUTPUT);         // sets the digital pin as output
  pinMode(ledRing2R, OUTPUT);      // sets the digital pin as output
  pinMode(ledRing3R,OUTPUT);         // sets the digital pin as output
  pinMode(ledRing4R,OUTPUT);        // sets the digital pin as output
  pinMode(redTap, OUTPUT);           // sets the digital pin as output
  pinMode(tiltPin, INPUT);            // sets the pin as input
  pinMode(Rswitch, INPUT);            // sets the pin as input
  Serial.begin(9600); 
}

void loop()                     // run over and over again
{
  tiltval = digitalRead(tiltPin);        // set tiltval egual to the tiltPin reading
  switchRval = digitalRead(Rswitch);        // set switchval equal to the switchPin reading

  Serial.print("Tilt Value: ");
  Serial.println(tiltval);    

  Serial.print("Switch Value: ");
  Serial.println(switchRval);   

  digitalWrite(Rsource, HIGH);

  if ( tiltval == 0)                           // logic for the actual lighting for the project
  {                                            // basically, this logic states that if the cup is tilted,
    if ( ledRing1Rval < 255)                   // then to light up the rings in a progression starting lowest to highest.
    {                                          // the arduino looks to see which ring needs be lit up and then will light up the correct LED.
      digitalWrite ( ledRing1R, HIGH);
      delay(5);
      ledRing1Rval = ledRing1Rval +5;   }
    if ( ledRing1Rval >= 255 && ledRing2Rval < 255)
    {
      analogWrite (ledRing2R, ledRing2Rval);
      delay(5);
      ledRing2Rval = ledRing2Rval +5;   }
    if ( ledRing1Rval == 255 && ledRing2Rval == 255 && ledRing3Rval < 255)
    {
      analogWrite (ledRing3R, ledRing3Rval);
      delay(5);
      ledRing3Rval = ledRing3Rval +5;   }
    if ( ledRing1Rval == 255 && ledRing2Rval == 255 && ledRing3Rval == 255 && ledRing4Rval < 255)
    {
      analogWrite (ledRing4R, ledRing4Rval);
      delay(5);
      ledRing4Rval = ledRing4Rval +5;    }
  }
 
  if ( switchRval == 1)               // this line of logic does the opposite of the the tilt switch logic.
  {                                    // It looks at Tap switch and will draing the bowl when the tap is down, draining the bowl of the light.
    digitalWrite(redTap,HIGH);
   
    if ( ledRing4Rval > 0)
    {
      analogWrite ( ledRing4R, ledRing4Rval--);
      delay(5);    }
    if ( ledRing3Rval > 0 && ledRing4Rval == 0)
    {
      analogWrite (ledRing3R, ledRing3Rval);
      delay(5);
      ledRing3Rval = ledRing3Rval -5;    }
    if ( ledRing2Rval > 0 && ledRing3Rval == 0 && ledRing4Rval == 0)
    {
      analogWrite (ledRing2R, ledRing2Rval);
      delay(5);
      ledRing2Rval = ledRing2Rval -5;    }
    if ( ledRing1Rval > 0 && ledRing2Rval == 0 && ledRing3Rval == 0 && ledRing4Rval == 0)
    {
      digitalWrite (ledRing1R, LOW);
      delay(5);
      ledRing1Rval = ledRing1Rval -5;    }
  }
 if (switchRval == 0)           // Tells the arduino to light up the light below the tap to simulate the light pouring out of the tap.
 {digitalWrite(redTap,LOW);
 }
}
Advertisements

May 1, 2008

“How I’d teach this class”

Filed under: Assignments,Christopher Bridgman,Final Writing Assignment — cbridgma @ 12:23 pm

I really thought the overall structure and how things were taught in this class were good, but I thought that there could be some overall improvements. I thought how the class started out was good, citing interactive examples, but I would suggest to take this further, maybe having more assignments or further investigations lasting throughout the semester to really get a grasp on interactivity. I feel that more overall discussions on what is interactive and what isn’t could possibly lead to richer final projects in the end.

All of the coding and circuit days within the class were really helpful. Sometimes the pace was a little fast for a new comer like me, but overall, I was able to pick up on most of it. I feel that hands on, in class workshops would have been helpful. Personally, I learn mostly from doing, not being lectured or reading, so I feel that, during the coding and circuits lectures, it could have been helpful for the students to be following along with Jet. I feel that physically putting together and coding simple programs would have been very helpful. This would help combat the tendency to understand things at the time of the lecture and conveniently forget what to do when its 2 am the night before an assignment is due.

I also feel that maybe having a series of optional assignments could be beneficial. Although I agree with having to do multiple assignments throughout the year, maybe doing ones that interest you would have a better effect. I think this could help a student become more proficient in one area, say LED’s or dc motors, than becoming average in an all around sense (which also has its benefits). A possible solution for this could be to have students meet a requirement for projects. For instance, you could prescribe out a set of 7 projects and students may only have to do 5 of them through the course of the semester and present them on a due date that you prescribe.

Overall, I felt that the course was taught well; I just feel that there were certain things that would have helped me. And if it could have helped me, I’m sure it could’ve helped other people as well. So in short, these would be my suggestions to make the course better. I would basically keep the scope and teaching of the course the same and add in these few suggestions.

March 26, 2008

Acceleromter Toy

Filed under: 8: State Machine,Assignments,Christopher Bridgman — cbridgma @ 11:02 pm

So here is the accelerometer toy. This toy exhibits 4 states. Off, attract, play, and angry. Basically, you use a potentiometer switch to turn it on. Once it is on, it goes into attract mode and blinks a blue light. Next, if the accelerometer detects movement, it will go into play mode, and an orange led will light up. And if the accelerometer detects too much movement, it will go into angry mode, where it will light up a red light and set a buzzer off denoting to stop playing so hard.

State machine toy diagram– Circuit Diagram for the final set up

SM Toy BB set up– Picture of the final bread board set up

Code:

int statusPin = 13;                // LED connected to digital pin 13
int xPin = 3;                      // X input from accelerometer
int yPin = 4;                     // Y input from accelerometer
int zPin = 5;                     // Z input from accelerometer
int redPin = 9;                    // Red LED's connected to pin 6
int orangePin = 10;                 // Orange LED's connected to pin 7
int bluePin = 11;                   // Blue LED's connected to pin 5
int buzzPin = 12;                  // buzzer connected to pin 12
int potPin = 2;                    // potentiometer connected to pin 2
int xval;
int yval;
int zval;
int potval;
int val;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(redPin, OUTPUT);         // sets the digital pin as output
  pinMode(orangePin, OUTPUT);      // sets the digital pin as output
  pinMode(bluePin,OUTPUT);         // sets the digital pin as output
  pinMode(buzzPin,OUTPUT);        // sets the digital pin as output
  pinMode(xPin, INPUT);            // sets the analog pin as input
  pinMode(yPin, INPUT);            // sets the analog pin as input
  pinMode(zPin, INPUT);            // sets the analog pin as input
  pinMode(potPin, INPUT);          //sets the analog pin as input
  Serial.begin(9600); 
}

void loop()                     // run over and over again
{
  xval = analogRead(xPin);        // set xval egual to the xPin reading
  yval = analogRead(yPin);        // set yval equal to the yPin reading
  zval = analogRead(zPin);        // set zval equal to the zPin reading
  potval = analogRead(potPin);    // set potval equalt to the potentiometer reading

  Serial.print("X Value: ");
  Serial.println(xval);   

  Serial.print("Y Value: ");
  Serial.println(yval);  

  Serial.print("Z Value: ");
  Serial.println(zval);  

  Serial.print("Potentiometer:");
  Serial.println(potval);

  digitalWrite(statusPin, HIGH);
  delay(15);
  digitalWrite(statusPin, LOW);
  delay(15);

  if ( potval > 1000){
//ATTRACT
    if ( (xval < 560) && (yval < 560) && (zval < 560))    // if x-y-z values are
    {
      digitalWrite(bluePin,HIGH);
      digitalWrite(orangePin,LOW);
      digitalWrite(redPin,LOW);
      digitalWrite(buzzPin,LOW);
      Serial.print("Attract: Come Play With ME!!");
    }

//PLAY
    if ( (xval > 560) && (xval < 660))     // if x-y-z values are
    {
      digitalWrite(orangePin,HIGH);
      digitalWrite(bluePin,LOW);
      digitalWrite(redPin,LOW);
      digitalWrite(buzzPin,LOW);
      Serial.print("Play Play Play!!");
    }
    else {
      if ( (yval > 560) && (yval < 660))
      {
        digitalWrite(orangePin,HIGH);
        digitalWrite(bluePin,LOW);
        digitalWrite(redPin,LOW);
        digitalWrite(buzzPin,LOW);
        Serial.print("Play Play Play!!");
      }

      else {
        if ( (zval > 560) && (zval < 660))
        {
          digitalWrite(orangePin,HIGH);
          digitalWrite(bluePin,LOW);
          digitalWrite(redPin,LOW);
          digitalWrite(buzzPin,LOW);
          Serial.print("Play Play Play!!");
        }
      } 
    }
    //ANGRY
    if (xval>700) {
      digitalWrite(redPin,HIGH);
      digitalWrite(bluePin,LOW);
      digitalWrite(orangePin,LOW);
      digitalWrite(buzzPin,HIGH);
      Serial.print("STOP IT!!");
    }
    else {
      if (yval > 700)
      {
        digitalWrite(redPin,HIGH);
        digitalWrite(bluePin,LOW);
        digitalWrite(orangePin,LOW);
        digitalWrite(buzzPin,HIGH);
        Serial.print("STOP IT!!");
      }

      else{
        if (zval > 700)
        {
          digitalWrite(redPin,HIGH);
          digitalWrite(bluePin,LOW);
          digitalWrite(orangePin,LOW);
          digitalWrite(buzzPin,HIGH);
          Serial.print("STOP IT!!");
        }
      }
    }
  }
  //OFF
  else {
    digitalWrite(redPin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(orangePin,LOW);
    digitalWrite(buzzPin,LOW);
  }

}

March 25, 2008

Pouring Light Table

Filed under: Assignments,Christopher Bridgman — cbridgma @ 1:33 pm

So my idea for the final project is to use a cup and a table to pour light. The cup would be the source of the light and you would tilt the cup to pour the light onto the table. the table would then light up proportial to the amout of light poured from the cup. the table would stay lit up as long as the table was leve. and to drain the table, you would only need to tilt the table and the light would fall off the table. If i got really ambitious, i could use sensors to allow you to manipulate the light once it was on the table. But as of right now, i am not quite sure how i would do that. But here is a video of something similar, but it is from cup to cup.

March 20, 2008

Simple Accelerometer Toy

Filed under: 8: State Machine,Assignments,Christopher Bridgman — cbridgma @ 11:34 am

So my idea for this state machine is to build a simple toy that uses an accelerometer to gauge how violently a toy is being played with. The idea is that, after you turn the toy on, the toy will go into attract mode, where it will blink an LED. Then, when the accelerometer senses movement, it will go into play mode, blinking multiple LED’s. Now the fun part is, if you shake the toy too violently and the accelerometer crosses a thresh hold, then an alarm will go off signaling the user to put the toy down or slow down. It is a simple idea, but i wanted to further explore an accelerometer while using analog input instead of digital input.

Accelerometer Toy State Machine Diagram

March 5, 2008

Mid-term Project: Mood Cube

Filed under: 7: Mid-Term Project,Assignments,Christopher Bridgman — cbridgma @ 10:29 pm

So here is my finished Mid-term project as per my innitial proposal. The challenge in creating this mood light was using the accelerometer and getting the arduino to read all 3 inputs at one given time to achieve a desired output. The cube responds to motion through the use of the accelerometer. For this light, using a digital read of the accelerometer sufficed to measure the position of the cube in respect to an initial position. As the sensor readings changed, I programed the arduino to change the color of the lights so a specific set of values would equal a certain color in the cube, ie. 1,1,1 = white. The cube is pretty sensitive to movement, a tap can get it to change colors, due to a very short delay. Any longer delay seemed to make the cube go buggy and disco like. With the short delay, it was able to stay a constant color while in the static position. It is not very clear in the video, due to poor camera resolution, but the color progression goes from off to white, red, purple (red and blue), blue, orange, and back to off.

Pictures:  mood cube blue_red    mood cube blue

Here is the final circuit diagram:   Mood Cube Schematic

Parts List:

Arduino Microcontroller

Blue LED’s x4

Ultra Bright White LED’s x4

Red LED’s x4

Orange LED’s x4

TIP120/TIP3055 Transistor or equal x4

4″x4″ Plexiglass Pieces for outer cube

ADXL 3030 3 Axis Accelerometer

9 Volt External Power

100 Kohm Resistors x4 for LED’s

1 Kohm Resistors for TIP120 Transistors.

 Here is the code. Notice the use of the ‘&&’ to read all 3 inputs from the accelerometer at one time.


int statusPin = 13;                // LED connected to digital pin 13
int xPin = 9;                      // X input from accelerometer
int yPin = 10;                     // Y input from accelerometer
int zPin = 11;                     // Z input from accelerometer
int redPin = 6;                    // Red LED's connected to pin 6
int orangePin = 7;                 // Orange LED's connected to pin 7
int bluePin = 5;                   // Blue LED's connected to pin 5
int whitePin = 3;                  // White LED's connected to pin 3
int xval;
int yval;
int zval;
int val;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(redPin, OUTPUT);         // sets the digital pin as output
  pinMode(orangePin, OUTPUT);      // sets the digital pin as output
  pinMode(bluePin,OUTPUT);         // sets the digital pin as output
  pinMode(whitePin,OUTPUT);        // sets the digital pin as output
  pinMode(xPin, INPUT);            // sets the PWM pin as input
  pinMode(yPin, INPUT);            // sets the PWM pin as input
  pinMode(zPin, INPUT);            // sets the PWM pin as input
  Serial.begin(9600); 
}

void loop()                     // run over and over again
{
  xval = digitalRead(xPin);        // set xval egual to the xPin reading
  yval = digitalRead(yPin);        // set yval equal to the yPin reading
  zval = digitalRead(zPin);        // set zval equal to the zPin reading
 

  Serial.print("X Value: ");
  Serial.println(xval);   

  Serial.print("Y Value: ");
  Serial.println(yval);  

  Serial.print("Z Value: ");
  Serial.println(zval);  

  digitalWrite(statusPin, HIGH);
  delay(15);
  digitalWrite(statusPin, LOW);
  delay(15);

  if ( (xval == 1) && (yval == 1) && (zval == 1))    // if x-y-z values are 1-1-1, light up the white LEDs
  {
    digitalWrite(redPin,LOW);
    digitalWrite(orangePin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,HIGH);
  }

  if ( (xval ==1) && (yval == 0) && (zval == 0))     // if x-y-z values are 1-0-0, turn all lights off
  {

    digitalWrite(redPin,LOW);
    digitalWrite(orangePin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,LOW);
  }

  if ( (xval == 1) && (yval == 1) && (zval == 0))    // if x-y-z values are 1-1-0, light up the orange LEDs
  {

    digitalWrite(redPin,LOW);
    digitalWrite(orangePin,HIGH);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,LOW);
  }

  if ((xval == 1) && (yval == 0) && (zval == 1))     // if x-y-z values are 1-0-1, light up the red LEDs
  {

    digitalWrite(redPin,HIGH);
    digitalWrite(orangePin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(whitePin,LOW);
  }

  if ((xval == 0) && (yval == 1) && (zval == 0))    // if x-y-z values are 0-1-0, light up the blue LEDs
  {

    digitalWrite(bluePin, HIGH);
    digitalWrite(redPin, LOW);
    digitalWrite(whitePin, LOW);
    digitalWrite(orangePin, LOW);
  }
 
    if ((xval == 0) && (yval == 0) && (zval == 0))   // if x-y-z values are 0-0-0, light up the red and blue LEDs creating purple
  {                                                 

    digitalWrite(bluePin, HIGH);
    digitalWrite(redPin, HIGH);
    digitalWrite(whitePin, LOW);
    digitalWrite(orangePin, LOW);
  }

}

February 27, 2008

Midterm Project: Mood Cube

Filed under: 7: Mid-Term Project,Assignments,Christopher Bridgman — cbridgma @ 9:56 pm

For my midterm project, I want to create a small interactive mood light. The light is a small, discrete object that can be used to subtly light a space. However, depending on the mood you are trying to set, the light can change from off to white, red, orange, or blue, depending on how you place it. The light will be contained in a frosted plexi-glass cube, so it can be placed on multiple sides, each side providing a different lighting condition. The project will work through the use of a 3 axis accelerometer. By using analog output, the accelerometer will have set readings which will set off different colored lights as you position it in different ways.

 

This idea was inspired by a student in last semester’s Making Furniture Interactive course where the student made a light that just turned on and off through the use of a tilt sensor. I really liked this idea, and for the midterm project, I wanted to take it further.

Basically, the accelerometer will be able to tell what orientation the cube is, and be like “hey, I’m oriented this way, I’ll light up the blue LED’s.” or the arduino might say, “the cube is oriented in this other way, so I’ll light up the orange LED’s.” this will happen for all 4 colors as well as well as the off position.

 

Parts List:

 

4 Ultra Bright White LED’s

4 Ultra Bright Blue LED’s

4 Red LED’s

4 Orange LED’s

TIP 3055 Transistor x2

TIP 120 Transistor x2

100 Kohm Resistors

3-Axis Accelerometer

Mood Cube Schematic

Mood Cube Representation

February 19, 2008

Solenoid/Servo Target Shooter

Filed under: 6: More Motion,Assignments,Christopher Bridgman — cbridgma @ 2:00 am

So, for this assignment, i wanted to create a target shooting device out of the solenoid so it would hit a target on the servo motor. i guess this was my interpretation of making the components do something. So here it finally is. This was done by using a simple tilt switch to fire the solenoid to try and hit the servo motor which operated off a simple time delay. However, after hooking all of this stuff up together, the sensor responded very slowly and im not sure why. It made it hard to actually hit the target. But anyways, here is the video.


int statusPin = 13;                // LED connected to digital pin 13
int switchPin = 6;                 // Gravity switch connected to pin 6
int servoPin = 11;                 //servo connected to pin 11
int solenoid = 2;                 //solenoid connected to pin 2
int val;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(servoPin, OUTPUT);       //sets the analog pin as output
  pinMode(solenoid, OUTPUT);       //sets the digital pin as output
  pinMode(switchPin, INPUT);       //sets the digital pin as input
  Serial.begin(9600); 
}

void loop()                     // run over and over again
{
  val = digitalRead(switchPin);

  Serial.print("Value: ");
  Serial.println(val);   

  analogWrite(servoPin,16); 
  delay(1000);
  analogWrite(servoPin,96);
  delay(1000);
 
  if (val == 1)
  {
      digitalWrite(solenoid,HIGH);
      digitalWrite(statusPin,HIGH);
    }
  if (val == 0)
  {
    digitalWrite(solenoid,LOW);
    digitalWrite(statusPin, LOW);
  }
}

tilt sensor servo motor

Filed under: 5: Making Motion,Assignments,Christopher Bridgman — cbridgma @ 1:44 am

so, i guess this is a continuation of the making motion assignment. in my first attempt at this making motion, i tried using a simple button switch which when activated, sent a power surge into my usb port. me and a couple other students tried again to get a solenoid working, but we think that it is trying to send power into the arduino, not ground, and thus not working. so to complete the making motion assignment, i used a tilt sensor to control where the servo motor goes to. the servo motor goes to a certain position when the tilt sensor is HIGH, and to another position when the sensor is LOW.

int statusPin = 13;                // LED connected to digital pin 13
int switchPin = 6;                 // Gravity switch connected to pin 6
int servoPin = 11;                 //servo connected to pin 11
int val;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(servoPin, OUTPUT);
  pinMode(switchPin, INPUT);
  Serial.begin(9600);  //sets the digital pin as input
}

void loop()                     // run over and over again
{
  val = digitalRead(switchPin);

  Serial.print("Value: ");
  Serial.println(val);    

  if (val == 1)
  {
      analogWrite(servoPin,16);
      digitalWrite(statusPin,HIGH);
    }
  if (val == 0)
  {
    analogWrite(servoPin,96);
    digitalWrite(statusPin, LOW);
  }
}

February 5, 2008

Switch/Counter 3 Way Light

Filed under: 4: Counting Sensor Input,Assignments,Christopher Bridgman — cbridgma @ 12:32 am

So, originally, I wanted to do this with a tilt sensor, but due to time, I was unable to get one. So what I did was create a switch that would toggle between 4 different light settings. I could imagine taking a light with a tilt sensor and programming this to light up each mode to a different angle (this kicked my butt enough!) I know to some people, this would be easy, but I had a hard time. It was really only because i tried doing it on my own instead of trying to look things up on the Ladyada site. That did wonders for me. But any way. Here is a video of the final product and code.



int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int bluePin = 10;                   // Blue LED connected to digital pin 10
int switchPin = 9;                   // Swtitch Connected to digital pin 9                        
int val;
int val2;
int buttonState;
int lightMode = 0;

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);       // sets the digital pin as output
  pinMode(switchPin, INPUT);      // sets the digital pin as input
  
  buttonState = digitalRead(switchPin);
}

void loop()                       // run over and over again
{
  val = digitalRead(switchPin); //Read the pin
  delay(10);
  val2 = digitalRead(switchPin);
  if (val == val2)
  {
    if (val !=buttonState)
    {
      if (val == LOW)
      {
        if (lightMode == 0) {          // if its off
          lightMode = 1;               // turn red light on
        } else {
          if (lightMode == 1) {        // if red light on
            lightMode = 2;             // turn green light on
          } else {
            if (lightMode == 2) {      // if green light on
              lightMode = 3;           // turn blue light on
            } else {
			  if (lightMode == 3) { //  if blue light on 
                lightMode = 0;           // turn light off!

}}}}}}
        buttonState = val;
}
  if (lightMode == 0) {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }
  
 
  if (lightMode == 1) {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }


  if (lightMode == 2) {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
    digitalWrite(bluePin, LOW);
  
  
  }
  if (lightMode == 3) {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
  }
}
Next Page »

Create a free website or blog at WordPress.com.