Hello everybody !
I have a big but (I think) easy problem to solve !
I'm trying very hard to use a Flex Sensor (the "FS7954", Click here to see the datasheet) but I can't figure out where the problem is and I don't even know if it's my circuit or my code that is wrong (or both maybe).
This is my circuit that I've done on Fritzing (I'm using a 10 000 Ohms Resistor) :
And this is 2 photos of my circuit in real life :
It's the same than my Frizting circuit, so the white wire goes to the A0 pin, the Resistor is a 10 kOhms Resistor and I've connected the GND to the "- line" and the 5V to the "+ line" (I'm sorry I don't know the correct terms).
This is the code that I have on my computer (which almost completely comes from SparkFun) :
const int FLEX_PIN = A0;
const float VCC = 5;
const float R_DIV = 10000.0;
const float STRAIGHT_RESISTANCE = 25000;
const float BEND_RESISTANCE = 125000;
void setup()
{
 Serial.begin(9600);
Â
 pinMode(FLEX_PIN, INPUT);
Â
}
void loop()
{
 int flexADC = analogRead(FLEX_PIN);
 float flexV = flexADC * VCC / 1023.0;
 float flexR = R_DIV * (VCC / flexV - 1.0);
 Serial.println("Resistance: " + String(flexR) + " ohms");
 float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE, 0, 90.0);        Â
 Serial.println("Bend: " + String(angle) + " degrees");
 Serial.println();
 delay(1000);
}
I have to admit that I don't fully understand the following lines of the code :
float flexV = flexADC * VCC / 1023.0;
float flexR = R_DIV * (VCC / flexV - 1.0);
Here is what the monitor displays when I don't touch my Flex Sensor (so when it is straight) and as you can see I don't have "0 degrees" :
And here is what the monitor displays when I bend the Flex Sensor a lot (between 45 and 90 degrees in my opinion) :
As you can see, it makes no sense !
In my code, I put :
const float STRAIGHT_RESISTANCE = 25000;
const float BEND_RESISTANCE = 125000;
because on the DataSheet it says that :
By the way, I used the map function because it says on the DataSheet that the Flex Sensor is "linear" so in my opinion a map function is enough (I think that I don't have to find an actual function like an polynomial function that goes through a majority of the points).
So if someone understand what is wrong with my code and/or my circuit, I would love to hear some explanations !
Thanks !