0% found this document useful (0 votes)
3 views

rf code sensor

Uploaded by

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

rf code sensor

Uploaded by

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

Arduino code:

const int flexPin = A0; // Analog pin the flex sensor is connected to
const float fixedResistance = 47000.0; // Resistance of the fixed resistor in ohms

// Calibration values (replace these with your own)


const float straightResistance = 25000.0; // Resistance of the flex sensor when
straight
const float bentResistance = 100000.0; // Resistance of the flex sensor when fully
bent
const float straightAngle = 0; // Angle corresponding to straight position (in
degrees)
const float bentAngle = 90.0; // Angle corresponding to fully bent position (in
degrees)

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

void loop() {
int flexValue = analogRead(flexPin); // Read the analog value from the flex
sensor
float voltage = flexValue * 5.0 / 1023.0; // Convert analog value to voltage
float flexResistance = fixedResistance * (5.0 / voltage - 1.0); // Calculate
resistance of the flex sensor

// Map the resistance value to an angle using linear interpolation


float angle = map(flexResistance, straightResistance, bentResistance,
straightAngle, bentAngle);

Serial.println(angle); // Print the angle to the serial monitor


delay(1000); // Short delay between readings
}

You might also like