Flex Sensor

Introduction


The bending sensor is a 7.3 cm long strip whose resistance varies when bent. It can bend from 0 degrees to 180 degrees.

Flex sensors are available in two sizes: 2.2 inches (5.5 cm) long and 4.5 inches (11.4 cm) long.

It can be useful in many areas:

It can measure mechanical movement, air flow, water flow and even vibrations.
It can be used as a motion sensor or as a highly resistant and reliable switch.

How does the sensor work?

One side of the sensor is printed with a polymer ink containing conductive particles. When the sensor is straight, the particles give the ink a resistance of around 30k Ohms.

When the sensor is bent away from the ink, the conductive particles move further away, increasing this resistance (to around 50k-70k Ohms when the sensor is bent at 90 degrees, and up to 125k Ohms at 180 degrees).

Sensor pins

Here are the pins of the bending sensor:

  • GND: Connect to the ground of the Arduino board.
  • Vcc : To be connected to the arduino board with a 10k ohms resistor.

Display value on serial monitor

We’ll now look at how to display sensor deflection on the serial monitor.

const int flexPin = A2; //Declares flex sensor pin
int value; //Variable to save the value read by the sensor

void setup(){
  Serial.begin(9600);//Initialize serial monitor
}

void loop(){  
  value = analogRead(flexPin); //Read and save the value read by the flex sensor
  value = map(value, 700, 900, 0, 180);//Convert the values to match those of the led 
  Serial.print("The sensor is twisted a:"); // Display the value on the serial monitor
  Serial.print(value);
  Serial.println(" degres");
  delay(100); //Wait between two measurements  
}

Blink the led with the flex sensor

Here’s a circuit to vary the intensity of the LED according to the bending of the sensor. When the sensor is at 0°, the LED is off, but the closer the bending sensor is to 180°, the brighter the LED.

const int ledPin = 9; //Declare led pin
const int flexPin = A2; //Declare flex sensor pin
int value; //Variable to save the value read by the sensor

void setup(){
  pinMode(ledPin, OUTPUT); //Define led as output
}

void loop(){  
  value = analogRead(flexPin); //Read and save the value read by the flex sensor
  value = map(value, 700, 900, 0, 255);//Convert the values to match those of the led 
  analogWrite(ledPin, value); //Assign value to led
  delay(100); //Wait between two measurements  
}

Controlling a servomotor with the sensor

The last circuit we’re proposing allows you to adapt the rotation of a servomotor with a bending sensor. In fact, it’s quite possible that these two components will be used together in your project to, for example, maintain the balance of a robot by adapting the position of the servomotor if the sensor is more or less twisted.

Here, the servomotor is at position 0° when the sensor is not bent, and 180° when the sensor is completely bent.

#include <Servo.h> // the servo motor library
Servo servomotor; // the servomotor
const int sensor_flex=A0;// flex sensor pin
int sensor_value = 0; // variable to retrieve sensor value

void setup(){
  pinMode(sensor_flex, INPUT); //Declare sensor as input
  servomotor.attach(12, 500, 2500);// attach the servomotor to pin 12 of the arduino
}

void loop(){
  sensor_value = analogRead(sensor_flex);// Read and store sensor value
  sensor_value = map(sensor_value, 700,900, 0, 180); // We modify this value to be between 0° and 180°.
  servomotor.write(sensor_value); // assign this value to the servomotor
  delay(10); // 10 millisecond pause between each value reading
}