Announcements

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

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

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


Lab 5

Project Members: 
Ethan DeYoung

Description

An extension of my lab 4 project, I added the speaker to the Pooh bear and now when he is squeezed (depending on how hard) his nose lights up and he 'screams.' 

Components Used


  • Arduino Board
  • Bread board
  • 1 220 ohm resistor
  • 1 10K ohm resistor
  • 1 LED
  • 1 FSR
  • 1 Piezo speaker 
  • wiring
  • 1 pooh bear
  •  
     

    Arduino Code 

     
    int potPin = 5;   // select the input pin for the potentiometer
    int speakerPin = 7;
    int ledPin = 9;   // select the pin for the LED
    int val = 0;      // variable to store the value coming from the sensor
    void setup() {
      pinMode(speakerPin, OUTPUT);
      Serial.begin(9600);
    }
    void loop() {
      digitalWrite(speakerPin, LOW);
      val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
      analogWrite(ledPin, val/4); // analogWrite can be between 0-255 (led brightness based on force)
      val = val*2; //used for delaying sound from speaker
      
      /*
      if (val > 512) {
        digitalWrite(speakerPin, HIGH);
      }
      else {
        digitalWrite(speakerPin, LOW);
      }
      */
      
      for(int i=0; i<500; i++) {  // play it for 50 cycles
        digitalWrite(speakerPin, HIGH);
        delayMicroseconds(val);
        digitalWrite(speakerPin, LOW);
        delayMicroseconds(val);
      }
      

    }  

     

    Images 

     


    AttachmentSize
    lab5_1.jpg65.62 KB
    lab5_2.jpg64.76 KB

    Powered by Drupal - Design by Artinet