We were to do this in a team of two! My teammate for this assignment was Siddharth Shah!
This is our own home-made EDM music with disco lights!
For this assignment we made a circuit consisting of an FSR(Force Sensitive Resistor) sensor along with a LED and a peizo buzzer driven by PWM. The FSR was wired with a voltage dividor and it's voltage was read through an analog input. As this varies from 0 to 1023, we had to map this down to 0 to 255 in order to maintain appropriate brightness for the LED and sound for the buzzer. (Brightness range for LED is 0-255 and that for buzzer 200-450 Hz.
When the FSR has zero force on it (not pressed), the resistance offered was infinite and thus there was no current flowing through LED or buzzer. The following table shows the working of FSR at different conditions.
Following is the code for this:
const int numReadings = 10;
int readings[numReadings];
int readIndex = 0;
int total = 0;
int average = 0;
int speakerPin = 12;
int fsrPin = 0;
int ledPin = 9;
const float VCC = 5.0;
const float R_DIV = 1000.0;
void setup()
{
Serial.begin(9600);
for (int thisReading = 0; thisReading < numReadings; thisReading++)
{
readings[thisReading] = 0;
}
}
void loop()
{
int reading = analogRead(fsrPin);
Serial.println("Reading: " + String(reading));
total = total - readings[readIndex];
readings[readIndex] = reading;
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings)
{
readIndex = 0;
}
average = total / numReadings;
Serial.println("Average: " + String(average));
int output = map(average, 0, 750, 0, 255);
if(output==0)
noTone(speakerPin);
else
tone(speakerPin, 200+output);
analogWrite(9, output);
float fsrV = average * VCC / 1023.0;
Serial.println("Voltage: " + String(fsrV) + " volts");
float fsrR = R_DIV * (VCC / fsrV - 1.0);
Serial.println("Resistance: " + String(fsrR) + " ohms");
float force;
float fsrG = 1.0 / fsrR;
if (fsrR <= 600)
force = (fsrG - 0.00075) / 0.00000032639;
else
force = fsrG / 0.000000642857;
Serial.println("Force: " + String(force) + " g");
Serial.println();
delay(1000);
}
Following graphs show the result of applying the average filters.
This is one example of the Serial window output:
These are the fritzing and circuit diagrams: