This is the Flexible Sensor/ Flex Sensor. This sensor works on resistance across the sensor when the sensor bend the resistance of the sensor increase the same characteristics on potentiometer / variable resistors. This sensor works on 5v it read 1023 at 9v it read on 0. As you can see the diagram below it has hook a 220 Ohms resistor from the ground this is a voltage divider that divides the 5v between the sensor and the resistor and hook up to your microcontrollers/SBC. The flex sensor is mostly used on Angle displacement measurement, robotics, gaming and virtual motion, medical devices, computer and peripherals, musical instruments & physical therapy.
Required Complements
- Arduino Microcontroller, NodeMCU, Teensy Board, TeensyDuino, ESP8266 12, 12E, ESP8266 NodeMCU, ESPDuino, ATMEGA328 16/12, ATMEGA32u4 16/8/ MHz, ESP8266, ATMEGA250 16 MHz, ATSAM3x8E, ATSAM21D, ATTINY85 16/8 MHz (Note: The Diagram below is using NANO. (please refer to the respective pin-outs)
- Flex Sensor
- 220 Ohms or 10k Resistor
- Jumper Wire / DuPont Wire
- Solderless Breadboard
For making your own flex sensor your need the following components below.
- Heat Shrink Tube (Any Color)
- Plastic Flexible Plate or Assitate
- Copper Tape / Copper Foil
- Static Bag / Static Plastic Bag Cutted into 6mm x 115mm
Wiring Diagram
Test code for flex sensor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
int flexsense = 14; // Set to analog pin A0 void setup(){ Serial.begin(9600); Serial.println("14CORE | Flex Sensor Test Code"); Serial.println("Starting...."); } void loop(){ int sensorRaw = analogRead(flexsense); Serial.println(sensorRaw); //Reading flex data between 512 / 614 //Working with map() we can convert that to a larger range like 0-100. int reading = map(sensorRaw, 512, 614, 0, 100); Serial.println(reading); delay(250); } |
Source Code with Servo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
#include <Servo.h> //Attach servo library Servo servo1, servo2, servo3, servo4, servo5; int s1 = 3, s2 = 5, s3 = 6, s4 = 9, s5 = 10; int fs1 = 14, fs2 = 15, fs3 = 16, fs4 = 17, fs5 = 18; int positioning (int sensorVal){ //you can change the sensorVal variable to distance from lowest possible sensorVal, 400. sensorVal = 700 - sensorVal; //sensorVal/300(range of sensorVal) = P / 180 (range of P) //300*P=180*sensorVal //P=3/5*sensorVal return 0.6 * sensorVal; } void setup() { Serial.begin(9600); //Start Serial Communication at 9600 boud rate Serial.println("14CORE | Prosthetic hand & arm with Flex sensor test"); Serial.println("Starting...."); Serial.println("----------------------------------------------"); delay(200); //Attach servo to respective pins servo1.attach(s1); servo2.attach(s2); servo3.attach(s3); servo4.attach(s4); servo5.attach(s5); // Set servos as output pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); pinMode(s4, OUTPUT); pinMode(s5, OUTPUT); // Set flex sensor as input pinMode(fs1, INPUT); pinMode(fs2, INPUT); pinMode(fs3, INPUT); pinMode(fs4, INPUT); pinMode(fs5, INPUT); // Set servo write at 0 servo1.write(0); servo2.write(0); servo3.write(0); servo4.write(0); servo5.write(0); delay(2000); servo1.write(0); servo2.write(0); servo3.write(0); servo4.write(0); servo5.write(0); } void loop() { //set analog input as variables int flex1 = analogRead(fs1); int flex2 = analogRead(fs2); int flex3 = analogRead(fs3); int flex4 = analogRead(fs4); int flex5 = analogRead(fs5); Serial.print("flex sensors values taken in"); /*Define the position variables as proportianal to the the sensor inputs, the 400 to 700 value range you can chage to set your own positioning*/ int pos1 = positioning(flex1); pos1 = constrain(pos1, 0, 180); int pos2 = positioning(flex2); pos2 = constrain(pos2, 0, 180); int pos3 = positioning(flex3); pos3 = constrain(pos3, 0, 180); int pos4 = positioning(flex4); pos4 = constrain(pos4, 0, 180); int pos5 = positioning(flex5); pos5 = constrain(pos5, 0, 180); Serial.print("Positioning..."); //Set servos to rotate by the amount specified in the "position" variables servo1.write(pos1); servo2.write(pos2); servo3.write(pos3); servo4.write(pos4); servo5.write(pos5); } |
Downloads
Download flex sensor datasheet | PDF
how could i control 2 servo motors using one flex sensor …plus i want each bend of flex sensor could changed the direction of both servo motors like if i bend flex up to 45 degree both servo will go fr the direction of right side same as if i bend my flex sensor in the direction of 90 servos will go for left direction otherwise same as linear direction plz give me reply thanks