Hello. I'm doing a project using flex sensors and i came upon a problem. The sensor doesn't read accurate values. I i used the code available in Spark Fun and it was working pretty fine, but now it isn't. This is the code i'm using. I tried changing the reference values for both the straight resistance and bend resistance but it doesn't work.
const int FLEX_PIN = A0; // Pin connected to voltage divider output
// Measure the voltage at 5V and the actual resistance of your
// 47k resistor, and enter them below:
const float VCC = 4.98; // Measured voltage of Ardunio 5V line
const float R_DIV = 47500.0; // Measured resistance of 3.3k resistor
// Upload the code, then try to adjust these values to more
// accurately calculate bend degree.
const float STRAIGHT_RESISTANCE = 37300.0; // resistance when straight
const float BEND_RESISTANCE = 90000.0; // resistance at 90 deg
void setup()
{
Serial.begin(9600);
pinMode(FLEX_PIN, INPUT);
}
void loop()
{
// Read the ADC, and calculate voltage and resistance from it
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");
// Use the calculated resistance to estimate the sensor's
// bend angle:
float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE,
0, 90.0);
Serial.println("Bend: " + String(angle) + " degrees");
Serial.println();
delay(500);
}
This is what i get:
Resistance: INF ohms
Bend: -93.00 degrees
Resistance: INF ohms
Bend: -93.00 degrees
Resistance: INF ohms
Bend: -93.00 degrees
Resistance: INF ohms
Bend: -93.00 degrees
Resistance: INF ohms
Bend: -93.00 degrees
Resistance: INF ohms
Bend: -93.00 degrees
Resistance: INF ohms
Bend: -93.00 degrees
Hope someone can help me asap, it's kinda reeaally urgent. Thanks in advance.