# Easy Tutorial: Flex Sensors With Arduino

1,952

2

Flex sensors are cool!

I use them all the time in my Robotics projects, and I thought of making a simple little tutorials to get you guys familiarized with these bendy little strips.

Let's talk about what a flex sensor is and how it works, how to connect one to Arduino, how to write code for it, and finally, how to test and successfully implement it in your project.

Now, I know some of you are not avid readers, and some would like to see it in action, in that case, watch the video of the full tutorial for the flex sensor in action inside the Ironman Repulsor that I made.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: What's a Flex Sensor and How Does It Work

Flex sensors look complicated, but it is actually just a conductive rubbery strip between 2 metal plated. Yup, that's it!

The way it works is, when the sensor is not bent (neutral), the rubbery strip is solid and thick, so it is conductive very little current between the two plates, as shown in the sketch, but when you bend it, the strip spreads out and allows more current through, and this current is detected and hence the amount of flex is fed back to the system.

Simple, eh? Let's connect it.

## Step 2: Connecting to Arduino

There are 2 pins on the flex sensor, one of them is connecting to 3.3V or 5V on the arduino, for power, and the other is connected to ground. But there's more - the ground connection is split and one wire goes to your arduino input pin, in my Arduino uno here, it is A1.
The important part is, there is a resistor in between the A1 pin and the ground. The resistor value will determine how sensitive your flex sensor is. A 1K resistor is a good starting point, but you can play with the values to achieve the sensitivity you need.

Done.

Let's see the sketch, and test our flex in the Ironman Repulsor.

## Step 3: The Code

The following code is from Sparkfun, but can be modified:

/******************************************************************************
Flex_Sensor_Example.ino Example sketch for SparkFun's flex sensors (https://www.sparkfun.com/products/10264) Jim Lindblom @ SparkFun Electronics April 28, 2016

Create a voltage divider circuit combining a flex sensor with a 47k resistor. - The resistor should connect from A1 to GND. - The flex sensor should connect from A1 to 3.3V As the resistance of the flex sensor increases (meaning it's being bent), the voltage at A1 should decrease.

Development environment specifics: Arduino 1.6.7 ******************************************************************************

/ const int FLEX_PIN = A1;

// Pin connected to voltage divider output

// Measure the voltage at 5V and the actual resistance of your

// 47k resistor, and enter them below: const float VCC = 4.98;

// Measured voltage of Ardunio 5V line const float R_DIV = 47500.0;

// Measured resistance of 3.3k resistor

// Upload the code, then try to adjust these values to more

// accurately calculate bend degree. const float STRAIGHT_RESISTANCE = 37300.0;

// resistance when straight const float BEND_RESISTANCE = 90000.0;

// resistance at 90 deg

void setup()

{ Serial.begin(9600);

pinMode(FLEX_PIN, INPUT); }

void loop()

{ // Read the ADC, and calculate voltage and resistance from it

float flexV = flexADC * VCC / 1023.0;

float flexR = R_DIV * (VCC / flexV - 1.0);

Serial.println("Resistance: " + String(flexR) + " ohms");

// Use the calculated resistance to estimate the sensor's

// bend angle:

float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE, 0, 90.0); Serial.println("Bend: " + String(angle) + " degrees");

Serial.println();

delay(500); }

## Step 4: Test

Upon testing, the flex sensor produced awesome results.
You can see it here

Hope you guys enjoyed this tutorial. Head over to Fungineers. There's a lot of Arduino and other projects you will enjoy :)

## Recommendations

• ### Internet of Things Class

22,831 Enrolled