The Sensing Principle: How a Flexi Sensor Actually Works

A flexi sensor (often referred to as a bend sensor) is fundamentally a flexible variable resistor. The core technology relies on a conductive polymer or carbon-based ink layer sandwiched between two thin, flexible polymer substrates. When the sensor is completely flat, the conductive particles are tightly packed, yielding a baseline resistance typically between 10kΩ and 25kΩ (depending on the specific model, such as the Spectra Symbol FS-1000A or Flexpoint 2.2-inch sensor). As you bend the sensor, the outer substrate stretches, causing micro-fractures and increasing the physical distance between the conductive particles in the ink matrix. This deformation restricts electron flow, causing the electrical resistance to climb.

When bent to a 90-degree angle, that resistance increases roughly linearly to between 35kΩ and 60kΩ. Because microcontrollers like the ESP32 or Arduino cannot measure resistance directly, we must convert this physical deformation into a measurable voltage. We achieve this by placing the flexi sensor in a voltage divider circuit with a fixed resistor. This translates the changing resistance into an analog voltage signal (typically 0V to 3.3V), which the microcontroller's Analog-to-Digital Converter (ADC) then samples and converts into a discrete digital number for your code to process.

Hardware Interfacing: Wiring and Pinout Table

Unlike digital sensors (like I2C accelerometers) that output a clean serial data stream, the flexi sensor outputs a purely analog resistance. To interface it with a 3.3V logic microcontroller like the ESP32, you must build a voltage divider. The flexi sensor acts as R1 (connected to 3.3V), and a fixed 10kΩ resistor acts as R2 (connected to GND). The ADC reads the voltage at the junction between them.

Table 1: Flexi Sensor to ESP32 Wiring Specification
Sensor / Component Function ESP32 Pin Notes & Supply Range
Flexi Sensor Pin 1 VCC / Supply 3V3 Supply range: 2.5V to 5.0V. 3.3V preferred for ESP32.
Flexi Sensor Pin 2 Signal Output GPIO 34 Junction of sensor and fixed resistor. Must use ADC1 pin.
10kΩ Fixed Resistor Pull-down / R2 GND 10kΩ is standard; use 22kΩ if your specific sensor reads >40kΩ flat.
0.1µF Ceramic Capacitor Low-pass Filter GND (parallel) Connect between GPIO 34 and GND to eliminate high-frequency EMI noise.
Bench Tip: ESP32 ADC Pin Selection
Never use GPIO 25, 26, or 27 for precision analog reads on the ESP32. These pins are routed to ADC2, which is shared with the WiFi radio and will drop readings when WiFi is active. Always use ADC1 pins (GPIO 32, 33, 34, 35, 36, 39). GPIO 34 is an excellent choice as it is input-only and lacks internal pull-up/pull-down resistors that can skew high-impedance voltage divider readings.

Signal Math: Converting Raw ADC Readings to Bend Angles

The most common mistake makers make with flex sensors is conflating the raw ADC integer with the actual physical bend angle. The ESP32 features a 12-bit ADC, meaning it outputs a raw integer from 0 to 4095. However, the ESP32's ADC is notoriously non-linear at the extremes (saturating near 0 and 3.1V). To bypass this, modern ESP32 Arduino cores include the analogReadMilliVolts() function, which uses the chip's internal eFuse calibration data to return a linear millivolt reading. We will use millivolts for our math.

Step 1: Calculate the Sensor Resistance
Using the voltage divider formula, we can rearrange the equation to solve for the flexi sensor's current resistance ($R_{flex}$) based on the measured voltage ($V_{mV}$):

R_flex = (R_fixed * V_mV) / (3300 - V_mV)

If your fixed resistor is 10,000 ohms and the ESP32 reads 1850 mV, the math is: (10000 * 1850) / (3300 - 1850) = 12,758 ohms.

Step 2: Map Resistance to Bend Angle
Flex sensors do not have a universal, factory-calibrated resistance-to-angle curve. You must perform a 2-point linear interpolation. Measure the resistance when the sensor is perfectly flat ($R_{flat}$, 0 degrees) and when bent to a known reference angle, usually 90 degrees ($R_{90}$). The angle ($\theta$) for any given resistance ($R_{flex}$) is calculated as:

Angle = 90.0 * ((R_flex - R_flat) / (R_90 - R_flat))

Here is the complete C++ function to implement this math on the ESP32:

const int SENSOR_PIN = 34;
const float R_FIXED = 10000.0;
const float R_FLAT = 12500.0;  // Calibrate this for your specific sensor
const float R_90 = 35000.0;    // Calibrate this for your specific sensor

float getBendAngle() {
  int mV = analogReadMilliVolts(SENSOR_PIN);
  
  // Prevent division by zero if ADC saturates at 3300mV
  if (mV >= 3290) mV = 3290; 
  
  float r_flex = (R_FIXED * mV) / (3300.0 - mV);
  
  // Linear interpolation to degrees
  float angle = 90.0 * ((r_flex - R_FLAT) / (R_90 - R_FLAT));
  
  // Clamp angle to physical limits
  if (angle < 0.0) return 0.0;
  if (angle > 90.0) return 90.0;
  
  return angle;
}

Calibration and Interference: Getting Reliable Data

If you wire up a flexi sensor and immediately read the serial monitor, you will likely see the values jittering by 3 to 5 degrees even when the sensor is sitting perfectly still on your desk. This is caused by three primary interference sources inherent to carbon-ink flex sensors and high-impedance analog circuits.

1. Electromagnetic Interference (EMI): The voltage divider creates a high-impedance node at the ADC pin. High-impedance lines act as antennas, picking up 50/60Hz hum from mains wiring and RF noise from the ESP32's WiFi antenna. Fix: Solder a 0.1µF ceramic capacitor directly between the ADC pin and GND. This creates a hardware low-pass filter that smooths out high-frequency noise before it hits the ADC.

2. Mechanical Creep and Hysteresis: Flex sensors suffer from mechanical memory. If you bend the sensor to 90 degrees and hold it there for 60 seconds, the polymer substrate relaxes. When you release it, the resistance will not immediately snap back to your calibrated $R_{flat}$ value; it will slowly creep back over several seconds. Fix: Do not use flex sensors for applications requiring rapid, repetitive, high-precision snap-back measurements (like high-speed vibration analysis). For wearable gloves, implement a software moving-average filter in your code to smooth the hysteresis curve.

3. Temperature Drift: The conductive polymer's resistance changes with ambient temperature. A sensor calibrated at 20°C (68°F) will read slightly stiffer at 10°C and slightly more relaxed at 35°C. For indoor hobby projects, this drift is negligible (usually <2% error). For outdoor robotics or wearable tech in varying climates, you must add a thermistor to your build and apply a temperature-compensation multiplier in your software.

FAQ: Common Flexi Sensor Questions

Can I connect a flexi sensor directly to a digital GPIO pin?

No. A flexi sensor is a passive, analog resistive component. It does not output a digital HIGH/LOW signal, nor does it use protocols like I2C or SPI. If you connect it directly to a digital GPIO, the pin will either float (causing random 0s and 1s) or just read the state of the internal pull-up/pull-down resistor. You must use an analog-to-digital converter (ADC) pin combined with a fixed resistor to create a voltage divider, as outlined in the wiring table above.

Why is my flexi sensor ADC reading jumping around randomly?

Random jitter is almost always caused by high-impedance noise pickup or a poor physical connection. Because the sensor outputs a voltage based on a high-resistance divider (often 20kΩ+ total resistance), the ESP32's ADC sampling capacitor struggles to charge fully during the brief sampling window, leading to fluctuating reads. Adding a 0.1µF capacitor between the signal pin and GND provides a local charge reservoir, eliminating 90% of this jitter. Additionally, ensure you are using soldered connections or high-quality breadboard jumper wires; the thin, fragile traces on flex sensors are prone to micro-disconnects if clipped loosely with alligator clips.

How long do flexi sensors last before they break?

Lifespan is measured in bend cycles, not time. A high-quality 2.2-inch sensor (like those from Flexpoint or Spectra Symbol) rated for 1 million cycles will last indefinitely in low-frequency applications like a DIY smart glove or a slow-moving robotic joint. However, the failure point is almost never the conductive ink itself; it is the rigid crimp connection where the flexible polymer meets the metal connector pins. If you repeatedly bend the sensor flush against the base of the connector pins, the traces will snap. Always leave at least 5mm of flat, unbent substrate near the connector base, and use strain relief (like heat shrink or Kapton tape) over the crimp.

Can I use a flexi sensor to measure bidirectional bending?

Standard flexi sensors are unidirectional. They are designed to bend in one specific direction (usually with the printed logo facing outward). If you bend them backward, the resistance change is highly non-linear, and you risk delaminating the substrate or cracking the carbon ink layer. If your project requires bidirectional measurement (e.g., measuring both flexion and extension of a robotic knee), you must mount two identical flexi sensors back-to-back with a thin layer of foam between them, reading both ADC channels and calculating the delta between them.