For this project I created a vase that changes the song it plays depending the level of water contained inside. The water level is detected by the fsr placed beneath the vase. The basic pattern remains the same, but the notes change, as the water level increases or decreases. Dropping glass stones or pouring more water into the vase allows a user to change up the music. An LED illuminates the vase and pulses with the music.
Possible Uses: This vase could be used as a type of ambient media in a couple of use case. A variation of this vase could be made, with a small change to the code, such that the music plays only when the input to the fsr drops below a certain threshold, signaling that the water in the flower vase is low and needs to be replenished. When the buzzer is disconnected, the vase makes a nice nightlight, and the addition of a photocell could enable it to turn on only if the light level is very low.
I reused the music code from PlayMelody, as I am terribly untalented when it comes to making music.
Materials:
1 10k ohm Resistor
2 220 ohm Resistors
1 Blue LED
1 FSR
1 Piezzo buzzer
1 Arduino Uno
1 Breadboard
Jumper wires of varying lengths
Code
/*
* Resistive Sensor Input
* Takes the input from a resistive sensor, e.g., FSR or photocell
* Dims the LED accordingly, and sends the value (0-255) to the serial port
//Musical portion of code adapted from PlayMelody
*/
int sensorPin = 0; // select the input pin for the sensor
int ledPin = 13; // select the output pin for the LED
int val = 0; // variable to store the value coming from the sensor
int speakerPin = 7;
//From PlayMelody
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "2d2a1f2c2d2a2d2c2f2d";
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;
void setup() {
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}
void loop() {
digitalWrite(speakerPin, LOW);
val = analogRead(sensorPin); // read the value from the sensor, 0-1023
val = val*9;
analogWrite(ledPin, val/4); // analogWrite (dimming the LED) can be between 0-255
Serial.println(val);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
for (int i=0;i<8;i++){
tones[i] = tones[i]+val;
}
delay(30);
//From PlayMelody
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerPin,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerPin, 0);
delayMicroseconds(500);
}
}
}
}
}
- Login to post comments