0% found this document useful (0 votes)
27 views6 pages

3.interfacing of A Flex Sensor

Uploaded by

crce.9502.ecs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

3.interfacing of A Flex Sensor

Uploaded by

crce.9502.ecs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Fr.

CONCEICAO RODRIGUES COLLEGE OF ENGINEERING


(FrCRCE)
Department of Electronics and Computer Science (ECS)

3.Interfacing of a flex sensor

Timeline (3) Depth of Completeness Total Signature


Understanding (4) (3)

Marking scheme (Rubrics)

Course, Subject & Experiment Details

Academic year 2024 – 2025 Estimated Time 02 Hours

Course B.E. (ECS) Subject Name Internet of Things

Semester VII Chapter Title Interfacing to Flex sensor

Experiment Type Coding Subject Code ECL 702

Aim & Objective of Experiment

To interface a flex sensor to the Arduino Uno and measure the bend angle

Theory:

A flex sensor uses carbon on a strip of plastic to act like a variable resistor. The resistance
changes by flexing the component.
The sensor bends in one direction, the more it bends, the higher the resistance gets.
Flex sensor t 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
As 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.

Output:
Code:
int flexsensor = A0;
int ledPin = 3; // LED connected to pin 3

// Define the sensor values corresponding to the specific angles


int straightValue = 624; // Sensor value at 0 degrees
int value45 = 518; // Sensor value at 45 degrees
int value90 = 411; // Sensor value at 90 degrees
int value135 = 313; // Sensor value at 135 degrees
int bendValue = 229; // Sensor value at 180 degrees

void setup()
{
Serial.begin(9600);
pinMode(flexsensor, INPUT);
}

void loop()
{
int sensorValue = analogRead(flexsensor);
int bendDegrees;

// Determine the bend degrees using interpolation


if (sensorValue >= value45) {
bendDegrees = map(sensorValue, straightValue, value45, 0, 45);
}
else if (sensorValue >= value90) {
bendDegrees = map(sensorValue, value45, value90, 45, 90);
}
else if (sensorValue >= value135) {
bendDegrees = map(sensorValue, value90, value135, 90, 135);
}
else {
bendDegrees = map(sensorValue, value135, bendValue, 135, 180);
}

bendDegrees = constrain(bendDegrees, 0, 180); // Ensure the value is between 0 and 180


degrees

Serial.print("Sensor Value: ");


Serial.print(sensorValue);

Serial.print(" Bend: ");


Serial.print(bendDegrees);
Serial.println(" degrees");

// Map the bend degrees to a PWM value (0 to 255)


int ledBrightness = map(bendDegrees, 0, 180, 0, 255);
analogWrite(ledPin, ledBrightness); // Set the LED brightness based on bend degrees

delay(20);
}
Screenshots:
Post-Lab questions:

1. Write an Arduino code to convert the flex sensor value to proportional servo motor
angle.
2. List out the specifications of any flex sensor.

You might also like