Velostat pressure sensor and speaker help

I am creating a project where I am using a pressure sensor made out of velostat and two strings of conductive thread on both sides of it. I want to use arduino to code a conditional statement that basically makes it so when pressure is applied to the sensor, the speaker stops. I am using the adafruit wearable FLORA device and I have no idea how to code this. PLEASE HELP!
Thank you!

(deleted)

Okay I know I can make the speaker turn on using this code (which is just an example code i found):

/*
Pitch follower

Plays a pitch that changes based on a changing analog input

circuit:

  • 8-ohm speaker on digital pin 9
  • photoresistor on analog 0 to 5V
  • 4.7K resistor on analog 0 to ground

created 21 Jan 2010
modified 31 May 2012
by Tom Igoe, with suggestion from Michael Flynn

This example code is in the public domain.

*/

void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
}

void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the analog input range (in this case, 400 - 1000 from the photoresistor)
// to the output pitch range (120 - 1500Hz)
// change the minimum and maximum input numbers below
// depending on the range your sensor's giving:
int thisPitch = map(sensorReading, 400, 1000, 120, 1500);

// play the pitch:
tone(9, thisPitch, 10);
delay(1); // delay in between reads for stability
}

And i've tried using this code to test the sensor:

For this code it said on the serial monitor that the force was 114g when no force was applied and it stayed the same when I applied force.

/******************************************************************************
Force_Sensitive_Resistor_Example.ino
Example sketch for SparkFun's force sensitive resistors
(Force Sensitive Resistor 0.5" - SEN-09375 - SparkFun Electronics)
Jim Lindblom @ SparkFun Electronics
April 28, 2016

Create a voltage divider circuit combining an FSR with a 3.3k resistor.

  • The resistor should connect from A0 to GND.
  • The FSR should connect from A0 to 3.3V
    As the resistance of the FSR decreases (meaning an increase in pressure), the
    voltage at A0 should increase.

Development environment specifics:
Arduino 1.6.7
******************************************************************************/
const int FSR_PIN = A0; // Pin connected to FSR/resistor divider

// Measure the voltage at 5V and resistance of your 3.3k resistor, and enter
// their value's below:
const float VCC = 4.98; // Measured voltage of Ardunio 5V line
const float R_DIV = 3230.0; // Measured resistance of 3.3k resistor

void setup()
{
Serial.begin(9600);
pinMode(FSR_PIN, INPUT);
}

void loop()
{
int fsrADC = analogRead(FSR_PIN);
// If the FSR has no pressure, the resistance will be
// near infinite. So the voltage should be near 0.
if (fsrADC != 0) // If the analog reading is non-zero
{
// Use ADC reading to calculate voltage:
float fsrV = fsrADC * VCC / 1023.0;
// Use voltage and static resistor value to
// calculate FSR resistance:
float fsrR = R_DIV * (VCC / fsrV - 1.0);
Serial.println("Resistance: " + String(fsrR) + " ohms");
// Guesstimate force based on slopes in figure 3 of
// FSR datasheet:
float force;
float fsrG = 1.0 / fsrR; // Calculate conductance
// Break parabolic curve down into two linear slopes:
if (fsrR <= 600)
force = (fsrG - 0.00075) / 0.00000032639;
else
force = fsrG / 0.000000642857;
Serial.println("Force: " + String(force) + " g");
Serial.println();

delay(500);
}
else
{
// No pressure detected
}
}

(deleted)

Excuse me? Can you not see my code? Does it not make sense to you?

(deleted)

(deleted)

Ya see the problem is I don't know how to do that so that's kind of why I am asking

What you are required to do first is to display the code properly in your posts. Select the code in your original post then click on the "code" icon (leftmost one looking like this : "</>"). :wink:

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.

Thanks.. Tom :slight_smile: