# Door Angle Using A Flex Sensor

**URL:** <https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746>\
**Category:** General Guidance\
**Created:** [May 14, 2023, 8:19am UTC](https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746 "2023-05-14T08:19:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rootofpi1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rootofpi1/32/962962_2.png) [@rootofpi1](https://forum.arduino.cc/u/rootofpi1)\
**Post date:** [May 14, 2023, 8:19am UTC](https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746/1 "2023-05-14T08:19:38Z")

</div>

I am not sure where to start. I have planned to create a door angle measurement system by placing a flex sensor on the door hinge and using an ESP32 microcontroller to collect data. However, I am new to this and I am confused about where to begin and what I need to take into consideration. Could you please provide me with some guidance on how to get started?

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [May 14, 2023, 8:25am UTC](https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746/2 "2023-05-14T08:25:09Z")

</div>

> [@rootofpi1](#):
>
> flex sensor

Does the flex sensor come with a data sheet (link?) and Arduino sample code?

---

<div class="post-metadata">

**Author:** ![rootofpi1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rootofpi1/32/962962_2.png) [@rootofpi1](https://forum.arduino.cc/u/rootofpi1)\
**Post date:** [May 14, 2023, 8:50am UTC](https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746/3 "2023-05-14T08:50:22Z")

</div>

Hello Yes .

> **[flex22.pdf](https://www.sparkfun.com/datasheets/Sensors/Flex/flex22.pdf)**

and this is the code i am using i got it from online

```arduino
// Define the analog input pin for the flex sensor
const int FLEX_PIN = 34;

// Define the calibration values (you will need to measure these)
const float CALIB_0_DEG = 0.0; // voltage reading at 0 degrees
const float CALIB_90_DEG = 3.3; // voltage reading at 90 degrees

// Define the reference angle (you will need to measure this)
const float REF_ANGLE = 0.0; // angle when the door is closed

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

void loop() {
  // Read the voltage output from the flex sensor
  float voltage = analogRead(FLEX_PIN) * 3.3 / 4095.0;

  // Calculate the voltage difference relative to the reference angle
  float voltage_diff = voltage - CALIB_0_DEG;

  // Convert the voltage difference to an angle measurement
  float angle = (voltage_diff * 90.0) / (CALIB_90_DEG - CALIB_0_DEG);

  // Subtract the reference angle to get the angle relative to the reference position
  angle -= REF_ANGLE;

  // Print the angle to the serial monitor
  Serial.print("Angle: ");
  Serial.print(angle);
  Serial.println(" degrees");

  // Wait a short time before taking another reading
  delay(100);
}

```

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [May 14, 2023, 9:04am UTC](https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746/4 "2023-05-14T09:04:02Z")

</div>

> [@rootofpi1](#):
>
> Hello Yes .

Fine 🙂

Next you have to find a door and mounting place for the sensor field test. Also build or get an amplifier as outlined in the data sheet, for mount **directly** at the sensor. Then you are ready to run the test program.

---

<div class="post-metadata">

**Author:** ![cloudDev](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@cloudDev](https://forum.arduino.cc/u/cloudDev)\
**Post date:** [May 14, 2023, 9:29am UTC](https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746/5 "2023-05-14T09:29:24Z")

</div>

> [@warning DO NOT CREATE TOPICS IN THIS CATEGORY warning](https://forum.arduino.cc/t/do-not-create-topics-in-this-category/1111650/1):
>
> More information:

# [warning DO NOT CREATE TOPICS IN THIS CATEGORY warning](https://forum.arduino.cc/t/do-not-create-topics-in-this-category/1111650)

Please move your topic!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 10, 2023, 9:30am UTC](https://forum.arduino.cc/t/door-angle-using-a-flex-sensor/1126746/6 "2023-11-10T09:30:24Z")

</div>

Closed on November 10, 2023, 9:30am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
