Flex sensor is a flexible resistor, it has two pins. Whenever you bend it, its resistance changes. Its resistance is minimum when it is relaxed or straight. And resistance is found maximum when bended.
It follows resistivity
ρ = RA/l
where ρ = resistivity of a material
R = Resistance
A = Area of the material
l = Length of the material
Connect the flex sensor to a multimeter, and set the multimeter on resistance.
Note down its resistance when normal i.e. Straight ( bend angle = 0°)
Note down its resistance when fully bend ( bend angle = 180°)
Now, its time to connect it with arduino board.
Connecting Flex Sensor With ArduinoAs the flex sensor is a variable resistor, we cannot connect it directly to arduino. We need a voltage divider circuit. The first resistor will be fixed one. The value of the resistor must be equal to the max resistance value of flex sensor. The fixed value resistor and flex sensor must be connected in series. The fixed value resistor must be connected to 5V
whereas the flex sensor must be connected to GND
. Their junction must be connected to pin A0
of the board.
Servo motor has three pins Power, Ground and Signal
power and ground needs to be connected to 5V
and GND
pins of board respectively. Signal
can be connected to any of the digital pin.
Record the analog input value by bending the sensor from minimum to maximum.
The servo motor need angle in degrees from 0°
to 180°
, but the sensor data can be any value from 0
to 1024
.
Use to the below code to convert the flex sensor value to proportional servo motor angle.
int const min_flex_val= 159 // analog input value for straight sensor
int const max_flex_val= 511 // analog input value for totally bended sensor
float flex_value = analogRead(A0);
float y= ((flex_value - min_flex_val)/(max_flex_val-min_flex_val));
int angle=(y*180); //angle value will be in the range 0 to 180
By doing above your motor should rotate proportionally to the bending of the sensor.
This can be used to control the hand of a robot, or mimic human hand gestures.
Comments