Making Things Interactive

March 6, 2008

Midterm – Interactive Indo Board

Filed under: 7: Mid-Term Project, Assignments, Thomas Hendrickson — tphendrickson @ 9:33 pm

For my midterm project I remained with my original idea of adding interactive elements to my indo board. I originally had thought that my additions would reflect how many times the board was tipped, but realized that it is much more challenging (and more of a workout) to focus on keeping the board as flat as possible.

I used 18 LEDs in 9 columns of 2, in three different colors. Each column is controlled by a digital output on the arduino. The outputs are based on the status of two separate rolling ball tilt switches that are attached to the indo board. Each tilt switch reads if the board is tilted a certain amount on either side. If kept completely horizontal, the tilt switches are activated at 30 degrees, so the switches must be altered a little (bent less horizontal) so that it is feasible to keep the board level long enough to light up the LEDs.

The switches each complete a circuit that act as inputs to the arduino, and the LEDs light up (green to yellow to red) based on how long the switches are NOT activated. When the switches are not activated, that implies that the indo board is balanced. Each LED column lights up a second after the last one has lit up. A ‘while’ statement in the code checks that both switches are not activated, a counter increments every half second however long the switches are not activated, and a series of ‘if’ statements light up the LEDs based on the counter value.


int runPin = 13;      //arduino LED light
int ledPin_1 = 12;    //LED pins
int ledPin_2 = 11;
int ledPin_3 = 10;
int ledPin_4 = 9;
int ledPin_5 = 8;
int ledPin_6 = 7;
int ledPin_7 = 6;
int ledPin_8 = 5;
int ledPin_9 = 4;
int switchPin_1 = 2;  //tilt switch inputs
int switchPin_2 = 3;
int switchStatus_1;
int switchStatus_2;
int counter;   

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin_1, OUTPUT);
  pinMode(ledPin_2, OUTPUT);
  pinMode(ledPin_3, OUTPUT);
  pinMode(ledPin_4, OUTPUT);
  pinMode(runPin, OUTPUT);
  pinMode(switchPin_1, INPUT);
  pinMode(switchPin_2, INPUT);

}

void loop()
{
    counter = 0;

    digitalWrite(runPin, LOW);    //everything is turned off at the start of the loop
    digitalWrite(ledPin_1, LOW);
    digitalWrite(ledPin_2, LOW);
    digitalWrite(ledPin_3, LOW);
    digitalWrite(ledPin_4, LOW);
    digitalWrite(ledPin_5, LOW);
    digitalWrite(ledPin_6, LOW);
    digitalWrite(ledPin_7, LOW);
    digitalWrite(ledPin_8, LOW);
    digitalWrite(ledPin_9, LOW);

    switchStatus_1 = digitalRead(switchPin_1);
    switchStatus_2 = digitalRead(switchPin_2);

    while ((switchStatus_1 == LOW) && (switchStatus_2 == LOW))  //both switches are not activated for the LEDs to light up
    {
      digitalWrite(runPin, HIGH);      //checks that the while loop is working

      if (counter > 1)
      {
        digitalWrite(ledPin_1, HIGH);

        if (counter > 2)
        {
          digitalWrite(ledPin_2, HIGH);

          if (counter > 3)
          {
            digitalWrite(ledPin_3, HIGH);

            if (counter > 4)
            {
               digitalWrite(ledPin_4, HIGH);
            }

              if (counter > 5)
              {
               digitalWrite(ledPin_5, HIGH);
              }

                if (counter > 6)
                {
                 digitalWrite(ledPin_6, HIGH);
                }

                  if (counter > 7)
                  {
                   digitalWrite(ledPin_7, HIGH);
                  }

                    if (counter > 8)
                    {
                     digitalWrite(ledPin_8, HIGH);
                    }

                      if (counter > 9)
                      {
                       digitalWrite(ledPin_9, HIGH);
                      }
          }
        }
      }

        counter++;      //the counter increments
        switchStatus_1 = digitalRead(switchPin_1);
        switchStatus_2 = digitalRead(switchPin_2);

        delay(500);    //the while loop is delayed half a second before starting again

    }

}

After the circuits and code are completed, I cut about 4, 8 foot wires to keep the LEDs away from the indo board. The switches were placed on a smaller breadboard and duct taped down to the indo board, making sure the breadboard was level.Materials:

  • 11 1K Ohm resistors
  • 6 green LEDs
  • 6 yellow LEDs
  • 6 red LEDs
  • Jumper wire
  • 2 rolling ball tilt switches
  • Arduino

    MidTerm Project: Ventillated Jacket

    Filed under: 7: Mid-Term Project, Siddartha Butalia — sbutalia @ 9:10 pm

    Step-by-Step of how I reached my end results 

     Step 1. Attaching the thermistors to sense temperature: I began by creating a an input switch, tweaked to give a reasonable range of input voltages for the thermistor. This took a while to get right, as initially I was getting incoherent data. (below is a picture of the setup)


    Step 2. calibrating the thermistors (scaling): The scaling was performed with the assumption that the thermistors gave off a linear voltage-temperature output. With this I plotted 2 points approximately and ran a regression analysis to determine a trend line. This trendline i used to come up with my fahrenheit values. With this I attached a number LED which was wired and coded as shown below. this was done so I could walk around freely with a jacket and understand which temperatures were uncomfortable and comfortable. I found that values over 85 (Fahrenheit) seemed quite uncomfortable. I then decided to leave this as a variable in my code which could be defined whenever.


    Free Image Hosting at www.ImageShack.us

    sourcecode for the hardwiring of the LED (functions)

    void LEDOutput(int tempF){
      if(tempF > 0){
        if(tempF >10){
          if(tempF >20){
            if(tempF >30){
              if(tempF >40){
                if(tempF >50){
                  if(tempF>60){
                    if(tempF>70){
                      if(tempF>80){
                        if(tempF>90){
                          nine();
                        }
                        else{
                        eight();
                      }}
                      else{
                      seven();
                    }}
                    else{
                    six();
                  }}
                  else{
                  five();
                }}
                else{
                four();
              }}
              else{
              three();
            }}
            else{
            two();
          }}
          else{
          one();
        }}
        else{
        zero();
        }}
    }
    
    void nine()
    {
      allclear();
      half();
      digitalWrite(13,HIGH);
      digitalWrite(12,HIGH);
      digitalWrite(10,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7, HIGH);
      digitalWrite(6,HIGH);
    }
    
    void eight(){
      allclear();
      half();
      digitalWrite(13,HIGH);
      digitalWrite(12,HIGH);
      digitalWrite(11,HIGH);
      digitalWrite(10,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7,HIGH);
      digitalWrite(6,HIGH);
    }
    
    void seven(){
      allclear();
      half();
      digitalWrite(13,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7,HIGH);
      digitalWrite(6,HIGH);
    }
    
    void six(){
      allclear();
      half();
      digitalWrite(13,HIGH);
      digitalWrite(12,HIGH);
      digitalWrite(11,HIGH);
      digitalWrite(10,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7,HIGH);
    }
    
    void five(){
      allclear();
      half();
      digitalWrite(13,HIGH);
      digitalWrite(12,HIGH);
      digitalWrite(10,HIGH);
      digitalWrite(7,HIGH);
      digitalWrite(9,HIGH);
    }
    
    void four(){
      allclear();
      half();
      digitalWrite(13,HIGH);
      digitalWrite(12,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7,HIGH);
    }
    
    void three(){
      allclear();
      half();
      digitalWrite(12,HIGH);
      digitalWrite(10,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7,HIGH);
      digitalWrite(6,HIGH);
    }
    
    void two(){
      allclear();
      half();
      digitalWrite(12,HIGH);
      digitalWrite(11,HIGH);
      digitalWrite(10,HIGH);
      digitalWrite(7,HIGH);
      digitalWrite(6,HIGH);
    }
    
    void one(){
      allclear();
      half();
      digitalWrite(7,HIGH);
      digitalWrite(9,HIGH);
    }
    
    void zero()
    {
      allclear();
      half();
      digitalWrite(13,HIGH);
      digitalWrite(11,HIGH);
      digitalWrite(10,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7,HIGH);
      digitalWrite(6,HIGH);
    }
    
    void allclear(){
    for(int i=0; i < 8; i++){
      digitalWrite(6+i,LOW);
      }
    }
    
    void half(){
      if(int(tempF) % 10 > 5)
      {
        digitalWrite(8,HIGH);
      }
    }

    Step 3. experimenting with various ways to actuate fabric with muscle wire: Initially i wanted the vents to open and close as gills, this however was easier said and done. Finally i came upon using this method to actuate the flaps. I use the pushing nature of muscle wire, it is quite strong when enough current is applied to the wire. Understanding this I had to use a transistor which allowed large currents to flow through.

    Step 4. Assembly: the method of creating the jacket was as follows, I cut out the flaps in the two layer jacket. Then i fused the edges together with fabric fuser and an iron, after that I created the “muscles.” I created these by taking each end and crimping them into copper tubes. the other ends of the tubes were attached to outgoing wires. after doing all the attachments, i soldered in the edges for a tighter fit. In order to successfuly insulate the components from both themselves and the fabric, I used heat shrink tubing to encase the joints. all exposed joints where soldered for strength and conductivity as well as shrink tubed to eliminate as much malfunction as possible. the wires and other components were taped onto the inside layer of fabric which proved to be strong enough. The next step was to determine which wires to use etc. I ran the power supplies through the front pockets as to utilize space to the maximum. Below one will find how the whole jacket is wired in a simple system level diagram indicating components, inputs and outputs.

    
    int inputPin[3];      //declares array of analog inputs
    int outputPin = 8;    //declares pin attached to transistor
    float tempF[3];        //declares variable to store temperature values in
    float tempAVG;        //declares variable to store the average temp in
    int threshTemp = 95;  //defines the temperature at which the vents open
    
    void setup() {
      inputPin[0] = 5;              //defining the input pins
      inputPin[1] = 4;
      inputPin[2] = 3;
      pinMode(10, INPUT);          //defining input and output pins
      pinMode(outputPin, OUTPUT);
      pinMode(inputPin[0], INPUT);
      pinMode(inputPin[1], INPUT);
      pinMode(inputPin[2], INPUT);
      pinMode(13, OUTPUT);
    
      Serial.begin(9600);          
    
     }
    
    void loop(){
    
      tempF[0] = (0.236827*analogRead(inputPin[0])-3.962);  //storing the temperatures from all three thermistors
      tempF[1] = (0.236827*analogRead(inputPin[1])-3.962);
      tempF[2] = (0.236827*analogRead(inputPin[2])-3.962);
      tempAVG = (tempF[0]+tempF[1] + tempF[2])/3;          //calculating the avg temp
      Serial.print(int(tempF[0]));                          //output of values for debugging/checking
      Serial.print(int(tempF[1]));
      Serial.println(int(tempF[2]));
      Serial.println(int(int(tempAVG)));
    
      if((int(tempAVG) > threshTemp) || digitalRead(10) > LOW){  //checks whether temp is > than the threshold or if the manual override button has been pushed
        digitalWrite(outputPin,HIGH);
        digitalWrite(13,HIGH);
      }else{
      digitalWrite(outputPin,LOW);
    digitalWrite(13,LOW);
    }
    
    }

    note* after break I will try and post up some directions/hints for working with muscle wire in the context of my project

    Midterm – Light Piano

    Filed under: 7: Mid-Term Project, Lingshui Wang — lingshui @ 2:09 pm

    So, I built a prototype for this out of some chipboard, wires, LEDs, and 3 potentiometers. I was working with dimming and lighting the LEDs in arrays depending on the state of the potentiometer. Right now, as I am new to working with brightness etc (and my analog pins don’t seem to want to transmit voltage to the LEDs for some strange reason…), the potentiometers are basically still acting as simple switches, with the dimming and lighting on LEDs on a timed script depending on the buttonstate of the potentiometer. Here’s the source code, I’m currently working on a new one to see if I can get the lights to match up with the potentiometer values.

    
    int left1 = 3;                            //setting LED and potentiometer pins
    int left2 = 5;
    int leftSense = 0;
    int right1 = 6;
    int right2 = 9;
    int rightSense = 1;
    int bot1 = 10;
    int bot2 = 11;
    int botSense = 2;
    int brightness = 0;                        //setting brightness values
    int brightness1 = 0;
    int brightness2 = 0;
    int brightness3 = 0;
    int brightness4 = 0;
    int brightness5 = 0;
    int val;                                    //setting potentiometer values
    int val2;
    int val3;
    
    void setup()
    {
      Serial.begin (9600);                      //serial library for troubleshooting
      pinMode(left1, OUTPUT);                   //setting inputs and outputs
      pinMode(left2, OUTPUT);
      pinMode(leftSense, INPUT);
      pinMode(right1, OUTPUT);
      pinMode(right2, OUTPUT);
      pinMode(rightSense, INPUT);
      pinMode(bot1, OUTPUT);
      pinMode(bot2, OUTPUT);
      pinMode(botSense, INPUT);
    }
    
    void loop()
    {
      val = analogRead(leftSense);               //define "val"
      val2 = analogRead(rightSense);
      val3 = analogRead(botSense);
      Serial.println (val);                      //print values for troubleshooting
      Serial.println (val2);
      Serial.println (val3);
      if (val >= 500)                            //switch value over one half...
      {
        if (brightness < 255)                    //if brightness of array 1 is not maxed...
        {
        brightness ++;                           //increase brightness for array 1
        brightness1 --;                          //decrease brightness for array 2
        analogWrite(left1, brightness);
        analogWrite(left2, brightness1);
        delay(5);
        }
        else if (brightness == 255)              //however, if brightness of array 1 is maxed...
        {
        analogWrite(left1, 255);                 //stay constant at array 1 on, array 2 off
        analogWrite(left2, 0);
        brightness1 = 0;                         //reset brightness values so if switch is turned back, smooth transition
        }
      }
      else if (val < 500)                        //however, if switch value below one half...
      {
        if (brightness1 < 255)                   //brightness of array 2 not maxed...
        {
        brightness --;                           //array 1 dim
        brightness1 ++;                          //array 2 light
        analogWrite(left1, brightness);
        analogWrite(left2, brightness1);
        delay(5);}
        else if (brightness1 == 255)             //however, if brightness of array 2 is maxed...
        {
          analogWrite(left1, 0);                 //stay constant at array 1 off, array 2 on
          analogWrite(left2, 255);
          brightness = 0;                        //set value back to 0 to provide smooth transition
        }
      }
     if (val2 >= 500)                            //rinse and repeat for other sides...
      {
        if (brightness2 < 255)
        {
        brightness2 ++;
        brightness3 --;
        analogWrite(right1, brightness2);
        analogWrite(right2, brightness3);
        delay(5);
        }
        else if (brightness2 == 255)
        {
        analogWrite(right1, 255);
        analogWrite(right2, 0);
        brightness3 = 0;
        }
      }
      else if (val2 < 500)
      {
        if (brightness3 < 255)
        {
        brightness2 --;
        brightness3 ++;
        analogWrite(right1, brightness2);
        analogWrite(right2, brightness3);
        delay(5);}
        else if (brightness3 == 255)
        {
          analogWrite(right1, 0);
          analogWrite(right2, 255);
          brightness2 = 0;
        }
      }
       if (val3 >= 500)
      {
        if (brightness4 < 255)
        {
        brightness4 ++;
        brightness5 --;
        analogWrite(bot1, brightness4);
        analogWrite(bot2, brightness5);
        delay(5);
        }
        else if (brightness4 == 255)
        {
        analogWrite(bot1, 255);
        analogWrite(bot2, 0);
        brightness5 = 0;
        }
      }
      else if (val3 < 500)
      {
        if (brightness5 < 255)
        {
        brightness4 --;
        brightness5 ++;
        analogWrite(bot1, brightness4);
        analogWrite(bot2, brightness5);
        delay(5);}
        else if (brightness5 == 255)
        {
          analogWrite(bot1, 0);
          analogWrite(bot2, 255);
          brightness4 = 0;
        }
      }
    }

    Schematic:

    parts list:

    27 LEDs

    3 potetiometers / distance sensors

    wire + solder

    casing

    Midterm

    Filed under: 7: Mid-Term Project, Lea — tovelet @ 1:32 pm

    I made a “whisker” sensor out of a guitar string, a photoresistor, and some scrap copper. It has two ways of registering a “high” reading (which causes the sequenced motion to speed up), either by touching the spring wire to the edge of its hole, or by seeing light.

    The solenoids turned out to be poor at producing motion; the force holding the center rod in position is fairly strong once tripped, but it has a hard time overcoming the force of the spring. Possibly it could be mounted to bias the forces toward tripping the solenoid. In the meantime, I set up a simple LED version of the circuit, to see if I could get the code working.

    The LED charlieplexed circuit is the same as the one from the Instructables tutorial (here), and the sensors are in the simple circuit from the class notes (here).

    /*
     * CharlieBlink
     *
     * Cycling through six LEDs set up according to the diagram
     * at http://www.instructables.com/id/SYK7IERF1ZM4KLB/
     *
     */
    
    int pinA = 9;                //
    int pinB = 10;               //
    int pinC = 11;               //
    int buttonPin = 2;
    int photoPin = 3;
    int delayTime = 500;
    
    void setup()                   // setup
    {
       pinMode(buttonPin, INPUT);  // no need to set pinmode for light pins, since we do that later
    }
    
    void loop()                    // loop
    {
    
         lightNode(pinA, pinB, pinC);      //LED1, from http://www.instructables.com/file/FCRD7A6F1ZM4KO0/
         delay(delayTime);
         lightNode(pinB, pinA, pinC);      //LED2
         delay(delayTime);
         lightNode(pinB, pinC, pinA);      //LED3
         delay(delayTime);
         lightNode(pinC, pinB, pinA);      //LED4
         delay(delayTime);
         lightNode(pinA, pinC, pinB);       //LED5
         delay(delayTime);
         lightNode(pinC, pinA, pinB);      //LED6
         delay(delayTime);
    }
    
    void lightNode(int upPin, int downPin, int nullPin)
      {
        pinMode(upPin, OUTPUT);
        pinMode(downPin, OUTPUT);
        pinMode(nullPin, INPUT);
        digitalWrite(upPin, HIGH);
        digitalWrite(downPin, LOW);
        if (digitalRead(buttonPin) == HIGH) {delayTime = 100;}
        if (digitalRead(buttonPin) == LOW) {delayTime = 500;}
      }
    

    I need a better way to switch sequence directions. I had thought that putting each LED’s settings for up pin, down pin, and null pin into an array would be helpful, since I could then find a way of incrementing or decrementing between arrays, instead of listing the sequence. However, it seems that reading out values from the array is more trouble than the current method if I don’t have the benefit of easily switching from array to array.

    killbot 2

    Filed under: 7: Mid-Term Project, Gaku Sato — ponkotsu @ 4:55 am

    The code is finally working logically as far as I can tell.  This was much more difficult than my underestimate of how-hard-can-it-be.  It took a good while just planning out the action logic and figuring out coefficients to calibrate the photosensor inputs was another unexpected roadblock that backed up traffic for miles.  I got it to the point where it will theoretically chase light.  I haven’t added other parts of brain to it yet, since sadly, I can not physically test it beyond this computer screen due to shortcomings on the component purchasing side of things…  In my defense, every subsystem has one key component missing, all of which were bafflingly elusive.

    And without further adieu, my attempt at futility.

    int LightL = 4;   // input analog pin - photoresistor [left]
    int LightR = 5;   // input analog pin - photoresistor [right]
    int LightB = 2;   // input analog pin - photoresistor [back]
    int Prox = 3;     // input analog pin - ultrasonic transducer (proximity)
    int MotorL1 = 6;  // output digital pin - motor [left] - direction 1
    int MotorL2 = 7;  // output digital pin - motor [left] - direction 2
    int MotorL = 10;  // output analog pin - motor [left] - speed
    int MotorR1 = 8;  // output digital pin - motor [right] - direction 1
    int MotorR2 = 9;  // output digital pin - motor [right] - direction 2
    int MotorR = 11;  // output analog pin - motor [right] - speed
    
    int Lin;  // input - photoresistor [left]
    int Rin;  // input - photoresistor [right] * constant
    int Bin;  // input - photoresistor [back] * constant
    
    long Lout;  // output - motor [left]
    long Rout;  // output - motor [right]
    
    int LightMin = 400;    // light input MIN for motion
    int LightMax = 900;    // light input MAX for motion
    int LightShoot = 700;  // light input threshold to start shooting
    
    int SpeedLow = 20;    // motor output LOW
    int SpeedHigh = 200;  // motor output HIGH
    
    int msecond = 0;
    
    void setup()
    {
      Serial.begin(9600);
      pinMode(LightL, INPUT);
      pinMode(LightR, INPUT);
      pinMode(LightB, INPUT);
      pinMode(MotorL, OUTPUT);
      pinMode(MotorL1, OUTPUT);
      pinMode(MotorL2, OUTPUT);
      pinMode(MotorR, OUTPUT);
      pinMode(MotorR1, OUTPUT);
      pinMode(MotorR2, OUTPUT);
      analogWrite(MotorL, 0);
      digitalWrite(MotorL1, LOW);
      digitalWrite(MotorL2, HIGH);
      analogWrite(MotorR, 0);
      digitalWrite(MotorR1, LOW);
      digitalWrite(MotorR2, HIGH);
    }
    
    void loop()
    {
      Lin = analogRead(LightL);
      Rin = analogRead(LightR) *1.1;  // 1.26
      Bin = analogRead(LightB) *1.8;
    
      if(Bin>Lin+100 && Bin>Rin+100) { /*turn around*/ }
    
      if(LinLightMax) {Lout=255;}
        else if(Rin>LightMin)
        {  // Lout = (SpeedHigh-SpeedLow)*(Lin-LightMin)/(LightMax - LightMin)+SpeedLow
          Lout = SpeedHigh-SpeedLow;
          Lout *= Lin-LightMin;
          Lout /= LightMax - LightMin;
          Lout += SpeedLow;
        }
      }
      if(Lin>LightMax)
      {
        Lout=0;
        if(Rin>LightMin && Rin<LightMax)
        {  // Rout = (SpeedHigh-SpeedLow)*[1-(Rin-LightMin)/(LightMax - LightMin)]+SpeedLow
          Rout = SpeedHigh-SpeedLow;
          Rout *= LightMax - Rin;
          Rout /= LightMax - LightMin;
          Rout += SpeedLow;
        }
      }
      if(RinLightMax) {Rout=255;}
        else if(Lin>LightMin)
        {
          Rout = SpeedHigh-SpeedLow;
          Rout *= Rin-LightMin;
          Rout /= LightMax - LightMin;
          Rout += SpeedLow;
        }
      }
      if(Rin>LightMax)
      {
        Rout=0;
        if(Lin>LightMin && LinLightMin && LinLightMin && RinLightShoot && Rin>LightShoot && abs(Lin-Rin)<30)
      {
        /* shoot! */
      }
    
      analogWrite(MotorL, Lout);
      analogWrite(MotorR, Rout);
    
      msecond = millis()/1000;
      if(millis()-msecond*1000 == 0)  // display every second
      {
        Serial.print("L:i");
        Serial.print(Lin);
        Serial.print("-o");
        Serial.print(Lout);
        Serial.print("   R:i");
        Serial.print(Rin);
        Serial.print("-o");
        Serial.print(Rout);
        Serial.print("   B:");
        Serial.println(Bin);
        // Serial.println(analogRead(Prox));
      }
    }

    Mid-Term Project (Due March 6,2008)

    Filed under: 7: Mid-Term Project, Cat Adams — catadams @ 1:44 am

    Images/video pending, here is the schematic and code for my midterm project:

    Most of the notes for the project can be found in the code itself. The glass/plastic servo works perfectly, but the metal servo keeps jerking between the two values I set for it, probably because the arduino keeps reading the hall sensor
    ver and over. I need to write a code for the arduino to read the sensor only once as soon as a bottle is deposited.

    midterm-schem.pdfmidterm-schem.pdf

    
    /*
    
    Midterm Project
    Automatic Recycler
    Cat Adams
    
    NOTES:
    --need to tell servos to stay at 0 degrees until a bottle is dropped
    --need another sensor to tell if a bottle has been dropped (photosensor/switch/rangefinder)
    --need to tell the arduino to read the hall sensor only once (or once a bottle has been dropped)
    --when sorting glass/plastic, need to determine a delay time for the switch (after a certain time after glass/plastic has beens sorted from metal, if the button has not been pressed, the bottle is plastic
    */
    
    int HallPin = 12;        //Hall Sensor
    int servoMetal = 6;      //Metal sorting Servo PWM pin 6
    int servoGlass = 10;     //Glass-Plastic sorting servo PWM pin 10
    int switchGlass = 2;     //Glass-Plastic sorting switch pin 2
    int statusPin = 13;
    int switchVal;           //variable to store switch value (high or low)
    int HallVal;             //variable to store Hall Sensor reading (1 or 0)
    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
    
    void metal(){                            //function for servoMetal to sort metal from glass/plastic
    pulseWidth = (MAngle * 11) + 500;
    digitalWrite(servoMetal, HIGH);
    delayMicroseconds(pulseWidth);
    digitalWrite(servoMetal, LOW);
    delay(20 - (pulseWidth/1000));
    }
    
    void glass1(){                          //function for servoMetal to sort glass/plastic from metal
    pulseWidth = (GAngle * 11) + 500;
    digitalWrite(servoMetal, HIGH);
    delayMicroseconds(pulseWidth);
    digitalWrite(servoMetal, LOW);
    delay(20 - (pulseWidth/1000));
    }
    
    void glass2(){                         //function for servoGlass to sort glass from plastic
    
    pulseWidth = (GAngle2 * 11) + 500;
    digitalWrite(servoGlass, HIGH);
    digitalWrite(statusPin, HIGH);
    delayMicroseconds(pulseWidth);
    digitalWrite(servoGlass, LOW);
    digitalWrite(statusPin, LOW);
    delay (20 - (pulseWidth/1000));
    }
    
    void plastic(){                         //function for servoGlass to sort plastic from glass
    
    pulseWidth = (PAngle * 11) + 500;
    digitalWrite(servoGlass, HIGH);
    delayMicroseconds(pulseWidth);
    digitalWrite(servoGlass, LOW);
    delay (20 - (pulseWidth/1000));
    }
    
    void setup()                      //sets all the modes
    {
    
    pinMode(HallPin, INPUT);
    pinMode(servoMetal, OUTPUT);
    pinMode(servoGlass, OUTPUT);
    pinMode(switchGlass, INPUT);
    pinMode(statusPin, OUTPUT);
    }
    
    void loop()
    
    {
    
    HallVal = digitalRead(HallPin);        //read Hall sensor first
    if (HallVal == 1){
    metal();
    }
    
    if (HallVal == 0){                     //if there is no presence of metal then move to glass/plastic sorting functions
    glass1();
    switchVal = digitalRead(switchGlass); //read switch for presence of either glass or plastic
    if (switchVal == LOW) {                //if the switch is pressed, sort for glass
    glass2();
    
    }
    
    if (switchVal == HIGH) {              //if the switch is not pressed, sort for plastic
    
    plastic();
    
    }
    
    }
    
    }
    

    Mid-Term Project: Pushpin

    Filed under: 7: Mid-Term Project, Assignments, Nadeem Haidary — nhaidary @ 12:11 am

    The pushpin is fully assembled and working. A button on the front changes the color of an LED on the back of the pushpin, reflecting the light onto the wall. When you tilt the pushpin 90 degrees, a black square turns red, indicating that you can record audio. Tilting the pushpin back stops the recording and plays back the audio (as proof that it was recorded). Finally, when you click on the screen, it stores those audio files as .wav on to your computer. The device uses both Arduino and Processing software.

    Labels

    pushpin-solo_web.jpg
    pushpin-on-_web.jpg
    pushpinwiring_revised.jpg

    Arduino:

     /*
     *   PUSHPINS
     *   Midterm project
     *   Spring 2008
     *
     *   Nadeem Haidary
     */
    
    //LIBRARIES
    
    //GLOBAL VARIABLES
    //pins
    int switchPin = 3;               // switch is connected to pin 3
    int tiltPin = 2;                 // tilt sensor is connected to pin 2
    int ledPin1 = 12;                // red LED is connected to pin 12
    int ledPin2 = 11;                // green LED is connected to pin 11
    int ledPin3 = 10;                // blue LED is connected to pin 10 ???
    
    //reading the LED switch
    int Sval;                        // variable for reading the switchPin status
    int Sval2;                       // variable for reading the delayed switchPin status
    int SbuttonState;                // variable to hold the swithcPin button state
    
    //reading the tilt switch
    int Tval;                        // variable for reading the tiltPin status
    int Tval2;                       // variable for reading the delayed tiltPin status
    int TbuttonState;                // variable to hold the tiltPin button state 
    
    int lightMode = 0;               // What mode is the LED in?
    
    //---SETUP-------------------------------------------------------------->
    
    void setup() {
      pinMode(switchPin, INPUT);     // Set the switch pin as input
      pinMode(tiltPin, INPUT);       // Set the tilt switch as input
    
      pinMode(ledPin1, OUTPUT);      // Set the red LED pin as output
      pinMode(ledPin2, OUTPUT);      // Set the green LED pin as output
      pinMode(ledPin3, OUTPUT);      // Set the blue LED pin as output
    
      Serial.begin(9600);            // Set up serial communication at 9600bps
    
      SbuttonState = digitalRead(switchPin);     // read the initial state of the LED switch
      TbuttonState = digitalRead(tiltPin);       // read the initial state of the tilt switch
    }
    
    //---LOOP--------------------------------------------------------------->
    
    void loop(){
      LEDchanger();                              // Function: reads switch to change LED color
      tiltRecorder();                            // Function: reads tilt, data to Processing
    }
    
    //---FUNCTIONS----------------------------------------------------------->
    
    void LEDchanger() {
      Sval = digitalRead(switchPin);             // Read input value and store it in val
      delay(10);                                 // Wait before double-checking
      Sval2 = digitalRead(switchPin);            // Read the input again to check for bounces
      if (Sval == Sval2) {                       // If there readings are the same
        if (Sval != SbuttonState) {              // and the button state has changed
          if (Sval == LOW) {                     // check if the button is pressed
            if (lightMode == 0) {                // if LED is off
              lightMode = 1;                     // turn red LED on
            }
            else {
              if (lightMode == 1) {              // if red LED is on
                lightMode = 2;                   // switch to yellow LED
              }
              else {
                if (lightMode == 2) {            // if yellow LED is on
                  lightMode = 3;                 // switch to green LED
                }
                else {
                  if (lightMode == 3) {          // if green LED is on
                    lightMode = 0;               // turn LED off
                  }
                }
              }
            }
          }
        }
        SbuttonState = Sval;                     // save the new state of the switch
      }
      // Now do whatever the lightMode indicates
      if (lightMode == 0) {                      // LED is off
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
      }
      if (lightMode == 1) {                      // red
        digitalWrite(ledPin1, HIGH);
        digitalWrite(ledPin2, LOW);
      }
      if (lightMode == 2) {                      // yellow
        digitalWrite(ledPin1, HIGH);
        digitalWrite(ledPin2, HIGH);
      }
      if (lightMode == 3)  {                     // green
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, HIGH);
      }
    }  
    
    void tiltRecorder() {
    
      Tval = digitalRead(tiltPin);               // Reads tilt sensor
        //Serial.println(Tval);
      if (Tval == 1) {                           // If switch is ON
        Serial.print(1, BYTE);                   // send 1 to Processing
      }
      else {                                     // If the switch is not ON,
        Serial.print(0, BYTE);                   // send 0 to Processing
      }
      delay(100);                                // Wait 100 milliseconds
    }

    Processing:

    /**
    *
    * PUSHPINS
    * Nadeem Haidary
    * uses the serial and sonia Processing libraries
    *
    */
    
    //LIBRARIES
    import pitaru.sonia_v2_9.*;                     // Import the Sonia sound library for recording, playing, and saving audio
    import processing.serial.*;                     // Import the Serial library to communicate with Arduino
    
    //GLOBAL VARIABLES & OBJECTS
    //serial
    Serial port;                                    // Create object from Serial class
    int val;                                        // Data received from the serial port
    
    //audio
    int sampleCounter = 0;                          // the current sample we are recording/playing
    int numSamples = 100;                           // the total number of samples we can use
    Sample[] mySampleObj = new Sample[numSamples];  // The Sonia Sample object which we'll record into
    int startRecord = 0;                            // used to stop the loop from rerecording every frame
    int startPlay = 1;                              // used to stop the loop from replaying every frame
    
    //---SETUP-------------------------------------------------------------->
    
    void setup()
    {
    size(600, 600);
    frameRate(10);
    println(Serial.list());                           // Set up the serial communication
    port = new Serial(this, Serial.list()[1], 9600);  // Open the port that the board is connected to (in this case COM4 = [1])
    // and use the same speed (9600 bps)
    Sonia.start(this);                                // Set up sound library
    LiveInput.start();                                // set up audio recording
    int recTimeSec = 10;                              // Maximum recordable time
    for (int i = 0; i < numSamples; i++) {            // create 100 samples to record
    mySampleObj[i] = new Sample (44100*recTimeSec);
    }
    }
    
    //---LOOP--------------------------------------------------------------->
    
    void draw() {
    smooth();
    noStroke();
    
    if (0 < port.available()) {                       // If data is available,
    val = port.read();                                // read it and store it in val
    }
    
    //println(val);
    background(255);                                  // Set background to white
    if (val == 0) {                                   // If the serial value is 0,
    fill(0);                                          // set fill for rectangle to black
    
    if (startPlay == 0) {                             // Start playing (but prevent looping)
    LiveInput.stopRec(mySampleObj[sampleCounter]);    // stop recording
    mySampleObj[sampleCounter].play();                // play back last recording
    println("PLAY");                                  // print PLAY
    
    sampleCounter++;                                  // increment to next available sample
    startRecord = 0;                                  // enable recording
    startPlay = 1;                                    // disable playing (for loop)
    }
    }
    
    else {                                            // If the serial value is not 0,
    fill(255, 30, 30);                                // set fill to red
    
    if (startRecord == 0) {                           // Start recording (but prevent looping)
    LiveInput.startRec(mySampleObj[sampleCounter]);   // Record LiveInput data into the Sample object.
    // The recording will automatically end when all of the Sample's frames are filled with data.
    println("RECORD");                                // print RECORD
    
    startPlay = 0;                                    // enable playing
    startRecord = 1;                                  // disable recording (for loop)
    }
    }
    rect(100, 100, 400, 400);                         // draw square
    }
    
    //---FUNCTIONS----------------------------------------------------------->
    
    void mousePressed() {                             // If the mouse is clicked
    
    for (int i = 0; i < sampleCounter; i++){          // go through all the samples that have been recorded
    mySampleObj[i].saveFile("test" + (i + 1));        // and save them (takes some time)
    println("saving file" + (i + 1));                 // let us know when you saved each one
    }
    LiveInput.stop();                                 // stop audio recording
    Sonia.stop();                                     // stop Sonia
    exit();                                           // quit the Processing applet
    }
    

    Blog at WordPress.com.