Interfacing Flex Sensor with Arduino
A flex sensor is basically a variable resistor, whose resistance varies when bent. Because the resistance is
directly proportional to the amount of bending, it is often referred to as a Flexible Potentiometer.
Flex sensors are typically available in two sizes: 2.2′′ (5.588cm) long and 4.5′′ (11.43cm) long.
Reading a Flex Sensor
The simplest way to read the flex sensor is to combine it with a static resistor to form a voltage divider,
which produces a variable voltage that can be read by the analog-to-digital converter of a microcontroller.
flex voltage divider
It is important to note that the output voltage you measure is the voltage drop across the pull-down
resistor, not the voltage drop across the flex sensor.
Code
const int flexPin = A0; // Pin connected to voltage divider output
// Change these constants according to your project's design
const float VCC = 5; // voltage at Ardunio 5V line
const float R_DIV = 47000.0; // resistor used to create a voltage divider
const float flatResistance = 25000.0; // resistance when flat
const float bendResistance = 100000.0; // resistance at 90 deg
void setup() {
[Link](9600);
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);
[Link]("Resistance: " + String(Rflex) + " ohms");
// Use the calculated resistance to estimate the sensor's bend angle:
float angle = map(Rflex, flatResistance, bendResistance, 0, 90.0);
[Link]("Bend: " + String(angle) + " degrees");
[Link]();
delay(500);
}