Getting resistance values from a flex sensor

const int flexPin = A0;
const float VCC = 5;			// voltage at Ardunio 5V line
const float R_DIV = 30000.0;	// resistor used to create a voltage divider
const float flatResistance = 30000.0;	// resistance when flat
const float bendResistance = 80000.0;	// resistance at 180 deg

void setup() {
	pinMode(flexPin, INPUT);

void loop() {
	// Read the ADC, and calculate voltage and resistance from it
	int ADCflex = analogRead(flexPin);
	float Vflex = ADCflex * VCC / 1023.0;
	float Rflex = (R_DIV * (VCC / Vflex - 1.0))/1000;
	Serial.println("Resistance: " + String(Rflex) + " kiloohms");

In my code I want flex sensor to say its value is about 30 kiloohms when it is at 0 degrees and when it is at 180 degrees its value to about 80 kiloohms. Currently I am getting 9.99 kohms at 0 degrees and .17 kohms at 180 degrees. I attached how I set up the circuit.

I'm really curious to know why you want to "force" the sensor to say it's at a certain resistance at a certain angle. I'd have thought you would move it to an angle, take a reading, and then know that whenever it's giving that reading, it's at that angle. Then do the same for other angles.

Its resistance is surely "what it is" so to speak?

Thank you for your response. The professor said that the resistor at 0 degrees should be 30 kohms and at 180 degrees it should be at 80 kohms. I'm not picking these values randomly. That's why im looking at my values and they are way off.

I'll bet that you misunderstood.

Measure the resistance, and that settles the argument.

Prof might have been giving a random example just to explain how it changed, or they might have been giving numbers from a particular sensor they had used. Whatever it resistance is, is what its resistance is, I'd say.

If you want specific readings at specific angles of bend then you need to use the map function to turn what values you have into the range of what values you want. Well if not you your professor.


I think your resistance calculation is not what I would expect. I would have expected Rflex = Vflex * R1 / (5-Vflex)

Could you post some ADCflex numbers?

Also can I assume the resistor in your graphic is just to show the connections? Because the resistor shown (brown, black, Red) is 1k.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.