Flex Sensor 2.2" - Small Retail
by MikeGrusin | August 09, 2011 | 3 comments
Skill Level:
Beginner
Thank you for purchasing a SparkFun Flex Sensor! This unique component can sense how much it is being bent. It opens up a wide range of projects, including:
...and other uses limited only by your imagination.
One side of the sensor is printed with a polymer ink that has conductive particles embedded in it. When the sensor is straight, the particles give the ink a resistance of about 30k Ohms. When the sensor is bent away from the ink, the conductive particles move further apart, increasing this resistance (to about 50k Ohms when the sensor is bent to 90º as in the diagram below). When the sensor straightens out again, the resistance returns to the original value. By measuring the resistance, you can determine how much the sensor is being bent.

NOTE: Although the active portion of the sensor (the area between the black squares) is quite sturdy, the pin-end of the sensor is susceptible to kinking and eventual failure. We recommend reinforcing or securing this area (for example, clamping or gluing down the sensor at the black square nearest the pins) to ensure that this area doesn't flex along with the rest of the sensor.
The simplest way to incorporate this sensor into your project is by using it in a voltage divider. This circuit requires one resistor. Many values from 10K to 100K will work, we'll use a 10K resistor here (SparkFun part number COM-08374, also supplied in our Inventor's Kits and locally at Radio Shack, etc.). Connect the flex sensor to your microcontroller using the following circuit:

The resistor and the flex sensor form a voltage divider, which divides VCC by a ratio determined by the two resistances. When the sensor is straight, the 10K resistor and the 30K flex sensor will cause the output voltage to be about 75% of VCC. When the sensor is bent, the voltage will increase to about 83% of VCC (see our voltage divider tutorial for the math) . If you're using 5V for VCC, you should see about 3.75V when the sensor is straight, and about 4.17V when the sensor is bent by 90º. These numbers will vary for individual sensors; for the most accurate results, test your specific sensor and use those numbers in your code.
Here's a basic Arduino sketch to show the output from your sensor:
// Flex sensor test program // Mike Grusin, SFE, 2011 // This program is free, use it however you wish! // HARDWARE: // Make the following connections between the Arduino and the flex sensor // Note that the flex sensor pins are interchangeable // Sensor pin - GND // Sensor pin - Analog In 0, with 10K resistor to +5V // INSTRUCTIONS: // Upload this sketch to your Arduino, then activate the Serial Monitor // (set the Serial Monitor to 9600 baud) void setup() { // initialize serial communications Serial.begin(9600); } void loop() { int sensor, degrees; // read the voltage from the voltage divider (sensor plus resistor) sensor = analogRead(0); // convert the voltage reading to inches // the first two numbers are the sensor values for straight (768) and bent (853) // the second two numbers are the degree readings we'll map that to (0 to 90 degrees) degrees = map(sensor, 768, 853, 0, 90); // note that the above numbers are ideal, your sensor's values will vary // to improve the accuracy, run the program, note your sensor's analog values // when it's straight and bent, and insert those values into the above function. // print out the result Serial.print("analog input: "); Serial.print(sensor,DEC); Serial.print(" degrees: "); Serial.println(degrees,DEC); // pause before taking the next reading delay(100); }
Enjoy your new sensor! If you have any questions (or want to show off your project), please don't hesitate to contact us at techsupport@sparkfun.com.
Comments 3 comments
Thanks for this tutorial. This will help me learn how it works.
Thanks for this tutorial, its really helped allot for me. I need one more help, did you work on flex sensor 4.5? if so can you post tutorial on that.
Es una buena recomendación.
Se le agradece.
Atentamente,
Wilber – El Salvador