Flex Sensor Arduino: Bend Sensor Wiring, Angle and Robot Hand
Flex sensor Arduino guide: resistance that rises as it bends, 47 kΩ voltage divider, resistance vs angle table, calibration, glove robot hand, ESP32 code, care.
A flex sensor with Arduino is the simplest way to measure how far a finger, an elbow or a surface bends. This thin, flexible strip has a certain resistance when straight, and the resistance rises as it bends. The Arduino's analog input can't measure resistance directly, but a voltage divider built with a single fixed resistor turns that change into a voltage between 0 and 5 V. With five sensors on the fingers of a glove you can drive a robot hand, a game character or a device that recognises sign language.
In this article you'll learn what's inside a flex sensor, the difference between the 2.2 and 4.5 inch models, how to choose the right divider resistor and how to calculate resistance and angle from the measured voltage. You'll calibrate using a sample resistance vs angle table, then control a five-servo robot hand with a flex sensor glove. Finally you'll build the same circuit on an ESP32 and see what to watch out for so the sensor keeps working for years without cracking or breaking.
What is a flex sensor and how does it work?
A flex sensor is a layer of conductive ink printed on a flexible plastic strip. The ink contains carbon particles that touch each other. When the strip is straight, the particles are in close contact and the resistance is low; as the strip bends, the ink layer stretches, the particles move apart and the resistance rises. That's why the sensor gives reliable results only when bent in one direction, with the printed side on the outside; bending it the other way produces very little change and can crack the ink. The sensor behaves like a variable resistor, not a potentiometer: it has two legs and no polarity. The change isn't linear and can vary by a few percent even at the same angle, so every sensor needs to be calibrated with its own values.
| Feature | 2.2 inch flex sensor | 4.5 inch flex sensor |
|---|---|---|
| Active length | About 56 mm | About 112 mm |
| Flat resistance | 25 kΩ (±30%) | 10 kΩ (±30%) |
| Bend resistance | 45–125 kΩ depending on bend radius | 60–110 kΩ depending on bend radius |
| Power | 0.5 W continuous, 1 W peak | 0.5 W continuous, 1 W peak |
| Operating temperature | −35 °C to +80 °C | −35 °C to +80 °C |
| Life | More than 1 million bends | More than 1 million bends |
| Best for | Fingers, small joints | Elbows, knees, long surfaces |
Reading it with a voltage divider and choosing the right resistor
We connect the sensor between 5V and the analog pin, and the fixed resistor between the analog pin and GND. The pin voltage is then Vout = Vcc × Rfixed / (Rflex + Rfixed); as the sensor bends, Rflex rises and the voltage drops. To get the resistance back from the measured voltage, we invert the formula: Rflex = Rfixed × (Vcc / Vout − 1). Choosing a fixed resistor close to the geometric mean of the sensor's lowest and highest resistance gives the widest voltage swing: for the 2.2 inch sensor √(25 kΩ × 100 kΩ) = 50 kΩ, so 47 kΩ is a good choice, and for the 4.5 inch one √(10 kΩ × 110 kΩ) ≈ 33 kΩ, so 33 kΩ. For the detailed maths see the voltage divider article or the voltage divider calculator.
| Connection | Arduino Uno | ESP32 | Note |
|---|---|---|---|
| Flex sensor leg 1 | 5V | 3V3 | No polarity |
| Flex sensor leg 2 | A0 | GPIO 34 | Middle point of the divider |
| 47 kΩ fixed resistor | Between A0 and GND | Between GPIO 34 and GND | 33 kΩ for the 4.5 inch sensor |
| Optional 100 nF capacitor | Between A0 and GND | Between GPIO 34 and GND | Reduces noise |
| Second sensor (ESP32) | A1 | GPIO 35 | ADC1 pins only |
Sample resistance vs angle table
The table below shows typical values for a 2.2 inch sensor with 5 V and a 47 kΩ divider. The resistance column is a sample measurement; your sensor may differ by ±30%, but the trend is the same. Voltage and ADC values are calculated from the formula. Notice that the resistance rises slowly over the first 30 degrees and faster after that, so the angle-resistance relationship isn't linear. The ESP32 column is calculated for a 3.3 V supply and a 12-bit ADC with the same divider.
| Angle | Resistance (sample) | Voltage (5 V) | Uno ADC (0–1023) | ESP32 ADC (0–4095) |
|---|---|---|---|---|
| 0° (straight) | 25 kΩ | 3.26 V | 668 | 2673 |
| 15° | 32 kΩ | 2.97 V | 609 | 2436 |
| 30° | 40 kΩ | 2.70 V | 553 | 2212 |
| 45° | 48 kΩ | 2.47 V | 506 | 2026 |
| 60° | 57 kΩ | 2.26 V | 462 | 1851 |
| 90° | 75 kΩ | 1.93 V | 394 | 1577 |
| 120° | 100 kΩ | 1.60 V | 327 | 1309 |
Step by step: reading a flex sensor with an Arduino
- Connect one leg of the sensor to 5V and the other to A0; put a 47 kΩ resistor between A0 and GND.
- Measure the actual voltage on the 5V pin and the actual value of the 47 kΩ resistor with a multimeter, and enter them in the VCC and R_DIV constants.
- Upload the code, open the Serial Monitor at 115200 baud and enter the resistance shown with the sensor straight into R_FLAT.
- Bend the sensor to exactly 90 degrees using a set square or protractor, enter the reading into R_BEND and upload again.
- Hold the sensor at different angles and check how close the calculated angle is to the real one.
1// Flex sensör + Arduino Uno: direnç ve açı hesabı (5V -> flex -> A0 -> 47k -> GND)
2// Flex sensor + Arduino Uno: resistance and angle (5V -> flex -> A0 -> 47k -> GND)
3const int FLEX_PIN = A0;
4const float VCC = 5.0; // multimetreyle ölçtüğün 5V değeri / your measured 5V value
5const float R_DIV = 47000.0; // bölücü direnci, ölçülen değeri yaz / divider resistor, enter measured value
6
7// Kalibrasyon: kendi sensörünle ölç / calibration: measure with your own sensor
8const float R_FLAT = 25000.0; // düzken direnç / resistance when straight
9const float R_BEND = 75000.0; // 90 derecede direnç / resistance at 90 degrees
10
11void setup() {
12 Serial.begin(115200);
13}
14
15void loop() {
16 long sum = 0;
17 for (int i = 0; i < 16; i++) sum += analogRead(FLEX_PIN); // 16 ölçüm ortalaması / average of 16 readings
18 float adc = sum / 16.0;
19 if (adc < 1) adc = 1; // sıfıra bölmeyi önle / avoid division by zero
20
21 float v = adc * VCC / 1023.0;
22 float rFlex = R_DIV * (VCC / v - 1.0); // gerilim bölücü formülü / voltage divider formula
23 float angle = (rFlex - R_FLAT) * 90.0 / (R_BEND - R_FLAT); // iki noktalı doğrusal ölçek / two-point linear scale
24 angle = constrain(angle, 0, 180);
25
26 Serial.print(F("ADC: ")); Serial.print(adc, 0);
27 Serial.print(F(" V: ")); Serial.print(v, 3);
28 Serial.print(F(" R: ")); Serial.print(rFlex / 1000.0, 1);
29 Serial.print(F(" kOhm Aci / angle: ")); Serial.println(angle, 0);
30 delay(100);
31}In every loop the code takes 16 readings and averages them, which noticeably reduces ADC noise. The average ADC value is first converted to a voltage, then to a resistance with the divider formula. The angle is calculated with a two-point linear scale between the straight and the 90-degree resistance: if the resistance equals R_FLAT you get 0, if it equals R_BEND you get 90 degrees. It's important that the constants are real values measured with a multimeter; 5 V from USB usually varies between 4.7 and 5.1 V, and that difference shifts the resistance calculation by a few percent. You'll find how the ADC works in detail in the ADC article.
Angle calibration: two points or many?
Two-point calibration is quick and ideal for projects where an approximate value is enough, such as a glove. But because the resistance doesn't rise linearly with angle, as the table shows, you'll see a few degrees of error between 30 and 60 degrees. For more accuracy, measure the sensor at 0, 30, 60, 90 and 120 degrees, store the values in an array and calculate intermediate values with linear interpolation between the two nearest points; this is called piecewise linear calibration. Flex sensors also have two more effects. The first is hysteresis: you read a slightly different resistance at the same angle when bending and when straightening. The second is creep: when the sensor is held bent, its resistance drifts slowly for a few seconds. So a flex sensor isn't a precision protractor; it's a sensor that captures the direction and approximate size of a movement well. If you need an exact angle, an accelerometer or a potentiometer is a better fit.
Glove-controlled robot hand and servo control

The favourite flex sensor project is a robot hand that copies the movements of a glove. A sensor is placed on top of each finger of the glove; in the robot hand, each finger is tied to a servo with a fishing line. As the servo turns, it winds the line and the finger bends; when it turns back, a rubber band or spring opens the finger. Five of the Arduino Uno's six analog inputs go to the sensors, and five digital pins (D3, D5, D6, D9, D10) go to the servos. The Servo library supports up to 12 servos on the Uno and can use any digital pin. You'll find how servos work in the servo motor article and mechanical design ideas in the Arduino robot arm guide.
| Finger | Flex sensor pin | Servo signal pin |
|---|---|---|
| Thumb | A0 | D3 |
| Index finger | A1 | D5 |
| Middle finger | A2 | D6 |
| Ring finger | A3 | D9 |
| Little finger | A4 | D10 |
1// Flex sensörlü eldiven + 5 servolu robot el (Arduino Uno), açılışta otomatik kalibrasyon
2// Flex sensor glove + 5-servo robot hand (Arduino Uno), automatic calibration at start-up
3#include <Servo.h>
4
5const int FINGERS = 5;
6const int FLEX_PINS[FINGERS] = {A0, A1, A2, A3, A4}; // başparmak..serçe / thumb..little finger
7const int SERVO_PINS[FINGERS] = {3, 5, 6, 9, 10};
8const int LED_PIN = 13;
9
10Servo servos[FINGERS];
11int openVal[FINGERS], fistVal[FINGERS]; // açık el ve yumruk ADC değerleri / open hand and fist ADC values
12float smooth[FINGERS];
13
14int readFlex(int pin) {
15 analogRead(pin); // ilk okumayı at: kanal değişimi / discard first read after channel switch
16 long s = 0;
17 for (int i = 0; i < 8; i++) s += analogRead(pin);
18 return s / 8;
19}
20
21void captureAll(int *dest) { // 1 sn boyunca ortalama al / average over 1 s
22 long acc[FINGERS] = {0, 0, 0, 0, 0};
23 for (int n = 0; n < 20; n++) {
24 for (int f = 0; f < FINGERS; f++) acc[f] += readFlex(FLEX_PINS[f]);
25 delay(50);
26 }
27 for (int f = 0; f < FINGERS; f++) dest[f] = acc[f] / 20;
28}
29
30void blinkWait(int times) {
31 for (int i = 0; i < times; i++) {
32 digitalWrite(LED_PIN, HIGH); delay(250);
33 digitalWrite(LED_PIN, LOW); delay(250);
34 }
35}
36
37void setup() {
38 Serial.begin(115200);
39 pinMode(LED_PIN, OUTPUT);
40
41 Serial.println(F("Elini AC ve bekle / OPEN your hand and wait"));
42 blinkWait(6);
43 captureAll(openVal);
44 Serial.println(F("Simdi YUMRUK yap / now make a FIST"));
45 blinkWait(6);
46 captureAll(fistVal);
47
48 for (int f = 0; f < FINGERS; f++) {
49 if (abs(openVal[f] - fistVal[f]) < 20) fistVal[f] = openVal[f] - 150; // fark çok küçükse güvenli varsayılan / safe default if range is too small
50 smooth[f] = openVal[f];
51 servos[f].attach(SERVO_PINS[f]);
52 }
53 digitalWrite(LED_PIN, HIGH); // kalibrasyon bitti / calibration done
54}
55
56void loop() {
57 for (int f = 0; f < FINGERS; f++) {
58 int raw = readFlex(FLEX_PINS[f]);
59 smooth[f] = smooth[f] * 0.8 + raw * 0.2; // üstel yumuşatma, titremeyi azaltır / exponential smoothing, reduces jitter
60 int angle = map((int)smooth[f], openVal[f], fistVal[f], 0, 180);
61 servos[f].write(constrain(angle, 0, 180));
62 Serial.print(angle); Serial.print(f < FINGERS - 1 ? '\t' : '\n');
63 }
64 delay(20);
65}At start-up the code runs a two-stage automatic calibration. The LED blinks for three seconds; keep your hand open while the code records the average value of each finger for one second. Then the LED blinks again and this time you make a fist. The recorded open-hand value is mapped to 0 degrees on the servo and the fist value to 180 degrees; since map also works with a reversed range, it doesn't matter that the ADC value drops as the sensor bends. Exponential smoothing is applied to each finger so the servo doesn't react to small noise. Open the Serial Plotter and you'll see the angles of all five fingers as lines at the same time. If the difference between open hand and fist is very small for a finger, the sensor is either mounted backwards or a leg is broken; in that case the code uses a safe default range. If you want more servos, a PCA9685 servo driver makes the job easier.
Flex sensor with an ESP32
On the ESP32 the wiring is the same, except the supply is 3.3 V; since the divider ratio doesn't change, the voltages shrink by a factor of 3.3/5. Connect the sensors to ADC1 pins (GPIO 32–39); ADC2 pins don't work while Wi-Fi is on. The ESP32's ADC is not linear, especially near the ends, so instead of analogRead we use analogReadMilliVolts, which applies the factory calibration. For the servos you need the ESP32Servo library, which you can install from the Library Manager. The code was compiled with the 2.0.x core, and current ESP32Servo versions offer the same interface on the 3.x core.
1// ESP32 + 2 flex sensör + 2 servo: milivolt okuma, direnç, açı (3V3 -> flex -> GPIO -> 47k -> GND)
2// ESP32 + 2 flex sensors + 2 servos: millivolt reading, resistance, angle (3V3 -> flex -> GPIO -> 47k -> GND)
3#include <ESP32Servo.h>
4
5const int FLEX_PINS[2] = {34, 35}; // yalnız ADC1 pinleri, Wi-Fi ile de çalışır / ADC1 pins only, work with Wi-Fi too
6const int SERVO_PINS[2] = {18, 19};
7const float VCC_MV = 3300.0; // 3V3 hattını ölç ve yaz / measure your 3V3 rail and enter it
8const float R_DIV = 47000.0;
9const float R_FLAT[2] = {25000.0, 25000.0}; // her sensör için ayrı kalibrasyon / separate calibration per sensor
10const float R_BEND[2] = {75000.0, 75000.0};
11
12Servo servos[2];
13
14float readResistance(int pin) {
15 uint32_t mv = 0;
16 for (int i = 0; i < 16; i++) mv += analogReadMilliVolts(pin); // fabrika kalibrasyonlu mV / factory-calibrated mV
17 float v = mv / 16.0;
18 if (v < 10) v = 10;
19 return R_DIV * (VCC_MV / v - 1.0);
20}
21
22void setup() {
23 Serial.begin(115200);
24 for (int i = 0; i < 2; i++) {
25 analogSetPinAttenuation(FLEX_PINS[i], ADC_11db); // 0-3,1 V aralığı / 0-3.1 V range
26 servos[i].setPeriodHertz(50);
27 servos[i].attach(SERVO_PINS[i], 500, 2400); // SG90 için darbe aralığı / pulse range for SG90
28 }
29}
30
31void loop() {
32 for (int i = 0; i < 2; i++) {
33 float r = readResistance(FLEX_PINS[i]);
34 float angle = (r - R_FLAT[i]) * 90.0 / (R_BEND[i] - R_FLAT[i]);
35 angle = constrain(angle, 0, 180);
36 servos[i].write((int)angle);
37 Serial.printf("Flex%d: %.1f kOhm %3.0f derece/deg ", i + 1, r / 1000.0, angle);
38 }
39 Serial.println();
40 delay(30);
41}Each sensor has its own R_FLAT and R_BEND values, because two sensors can show different resistances even at the same angle. Making this setup wireless is easy: the ESP32 in the glove can read the angles and send them dozens of times per second over ESP-NOW to a second ESP32 in the robot hand. That way you control the robot hand from a few metres away without a tangle of wires. A small Li-ion cell and a charger module are enough for the board in the glove.
Making your flex sensor last longer
- Bend it only with the printed side on the outside; bending the other way cracks the ink.
- Never bend the end with the legs; fix that part with a stiff strip, hot glue or heat shrink tubing.
- Avoid sharp folds; bend the sensor in a gentle curve, the way it wraps around a finger.
- On a glove, fix the sensor only at the leg end and let the other end slide freely in a fabric channel so the sensor isn't stretched.
- Solder quickly, use a female pin header or crimp connector if possible, and route the wires along the glove with cable ties rather than hanging them from the legs.
- Protect the sensor from sweat, water and sharp objects; a thin protective sleeve protects both the ink and the legs.
Flex sensor project ideas
- Idea: A glove-controlled four-axis robot arm; each finger drives one joint.
- Idea: A glove that recognises a simple sign language alphabet; turn the combination of finger angles into a letter and show it on an OLED display.
- Idea: A digital instrument played with your fingers; the bend of each finger changes the sound of a different note.
- Idea: A posture reminder; a 4.5 inch sensor on the back vibrates when you slouch.
- Idea: A door or lid opening meter; a sensor next to the hinge measures how far it opens.
- Idea: A glove game controller; turn finger bends into keyboard keys.
Common problems and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Reading always 0 or always 1023 | Fixed resistor missing or a leg broken | Check the divider, measure the sensor's resistance with a multimeter |
| Value barely changes when bent | Sensor bent the wrong way or unsuitable resistor | Put the printed side outwards, use 47 kΩ for 2.2 inch and 33 kΩ for 4.5 inch |
| Angle jitters | ADC noise, long wires | Average, add a 100 nF capacitor, apply exponential smoothing |
| Sensor suddenly shows infinite resistance | The conductive track at the end has broken | Replace the sensor, support the end and don't bend it there |
| Servos jitter, Arduino resets | Servos powered from the Arduino's 5V pin | Use a separate 5 V 2–3 A supply and join the grounds |
| One finger's value reacts to another finger's movement | Previous channel affecting the ADC after a switch | Discard the first reading on each channel or use a smaller divider resistor |
| Readings go wrong on the ESP32 when Wi-Fi starts | Sensor connected to an ADC2 pin | Use ADC1 pins between GPIO 32 and 39 |
With a connection as simple as a single resistor, a flex sensor turns movement into a measurable number; with the right divider, a good calibration and a little care at the end, you can use it reliably in many projects from gloves to robot hands. If you want to try analog reading and servo control step by step with a circuit diagram and ready code, take a look at the potentiometer and servo projects in the BlueGrays app.
Frequently asked questions
How does a flex sensor work?
A flex sensor is made of conductive ink with carbon particles printed on a flexible strip. As the strip bends, the particles move apart and the resistance rises; a 2.2 inch sensor reads about 25 kΩ when straight and 45–125 kΩ when bent. The Arduino measures this change through a voltage divider on an analog input.
What resistor should I use with a flex sensor?
For the widest measuring range, choose a fixed resistor close to the geometric mean of the sensor's lowest and highest resistance. 47 kΩ works well for the 2.2 inch sensor and 33 kΩ for the 4.5 inch sensor. A very small value such as 10 kΩ narrows the voltage range.
How do you measure an angle with a flex sensor?
First, the sensor's resistance is calculated from the measured voltage with the voltage divider formula. Then it is converted to an angle with a linear scale using the resistances measured with the sensor straight and at 90 degrees. For better accuracy, take measurements at several angles and use piecewise linear calibration.
Can a flex sensor bend both ways?
A flex sensor gives a clear change in resistance only when bent with the printed side on the outside. Bending it the other way produces very little change and, if repeated, can crack the conductive ink. If you need to measure in both directions, you can use two sensors back to back.
Why do flex sensors break?
The most common cause is bending or pulling the end where the legs join the plastic; the conductive track there breaks and the sensor shows infinite resistance. Sharp folds, long soldering times and bending in the wrong direction also damage the sensor. Supporting the end with a stiff piece greatly extends its life.
Can I use a flex sensor with an ESP32?
Yes, the circuit is the same; the divider is simply powered from 3.3 V and the sensor goes to one of the ADC1 pins (GPIO 32–39). ADC2 pins can't be read while Wi-Fi is on, so avoid them. Because the ESP32's ADC isn't linear, reading calibrated millivolts with analogReadMilliVolts gives more accurate results.
Projects to build after reading this
See all projects
Measuring Light Intensity with an LDR
Want to see how bright your room is as a number? The LDR, a small part that reacts to light, measures the light around it, and the Arduino writes the value to your computer screen every half second.

Using a Servo Motor
The arm of a small servo motor turns to three positions in turn: all the way to the start, right to the middle and all the way to the end, waiting two seconds at each stop.

Servo Motor Operation with Potentiometer
As you turn the potentiometer knob, the servo motor's arm turns right along with it: one end of the knob means zero degrees, the other end means half a turn.

Servo Control with Joystick
Steer two motors with a joystick, just like turning a security camera. Push the stick left or right and the bottom servo motor slowly turns, push it up or down and the top servo tilts up and down…

ESP32 Servo Motor (Potentiometer Control)
In this project, we control an SG90 servo motor using a potentiometer. We adjust the servo angle by mapping the analog value read from the potentiometer to the 0–180-degree range. The ESP32Servo library generates servo signals on suitable output-capable GPIO pins of the ESP32; this project uses GPIO 18. This is a fundamental control method for robotic arms, camera gimbals, and automatic door mechanisms.

ESP32 LED Brightness Control with a Potentiometer (Analog → PWM)
In this project, we control the brightness of an LED analogically using a potentiometer. The ESP32's ADC pin reads the 0-3.3V voltage from the potentiometer, and this value is then converted into a PWM (Pulse Width Modulation) signal and sent to the LED. As a result, as you turn the potentiometer, the LED gradually brightens and dims. With Arduino Core 3.0+, analogWrite() can be used directly; on the ESP32-S2/S3, the ADC resolution is fixed at 12-bit.

Servo Circle Choreography - Animated Patterns with 32 Servos
A visual animation project driven by 32 servo motors arranged in a circle on an Arduino Mega. The servos are managed in a single array, connected to the Mega's pins 22–53, and perform four motion sequences: a chaotic jitter at random angles, a synchronized sweep, a wave travelling around the circle and a compass needle swinging left and right.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 750+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

