Description
In this lab we utilized the phenomena of compressing air in a enclosed space to create sound through a Piezo Speaker. As the material inside the plastic casing flexes due to the changing currents running through the material the air inside the plastic container escapes the single hole at different pressures creating different sound-wave frequencies resulting in different musical notes. We then used pre-written code to use serial inputs to create musical melodies. I then hooked up the force sensor to the Arduino so that I could change the sounds using the pressure sensor. After this our task was to create some kind of input-output-coincidence device that takes inputs and gives outputs in the same location. For this I stabbed my pot into a previously existing battery powered candle (battery was dead) and hooked up my LED to some wires to allow the LED to be more mobile. Now whenever I twist the candle the LED brightens and fades giving me more control over the brightness of my candle.
Components
1 Arduino Uno
1 Breadboard
1 potentiometer
1 10k resistor
1 piezo speaker
Guage wires
1- candle
1- diffusor
1- scotch tape
Code
Music:
/* Theremin
* --------
*
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
int potPin = 0; // select the input pin for the potentiometer
int speakerPin = 11;
int val = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
Serial.println("ready");
}
void loop() {
digitalWrite(speakerPin, LOW);
val = analogRead(potPin); // read value from the sensor
val = val*2; // process the value a little
//val = val/2; // process the value a little
for( int i=0; i<50; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}
Input-output-coincidence
/*
* one pot fades one led
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int potPin = 2; // select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
analogWrite(ledPin, val/4); // analogWrite can be between 0-255
}
- Login to post comments