【问题标题】:flex sensors with arduino带有 arduino 的柔性传感器
【发布时间】:2016-12-08 23:33:34
【问题描述】:

我有一个与 arduino 睡莲47k ohms 电阻相连的 flex 传感器

我的问题是我无法从 flex 传感器获得一致的值:有时,我得到非常奇怪的读数,即使 flex 传感器没有处于弯曲状态.

我尝试更改straight_resistancebend_resistance 的值,但似乎无法解决问题。

这是我的代码,期待帮助。

const int FLEX_PIN = A0; // Pin connected to voltage divider output

// Measure the voltage at 5V and the actual resistance of your
// 47k resistor, and enter them below:
const float VCC = 4.98; // Measured voltage of Ardunio 5V line (r1/r1+r2)5
const float R_DIV = 47500.0; // Measured resistance of 3.3k resistor

// Upload the code, then try to adjust these values to more
// accurately calculate bend degree.
const float STRAIGHT_RESISTANCE = 24248750.00; // resistance when     straight 
const float BEND_RESISTANCE = 48544996.00; // resistance at 90 deg

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

void loop() 
{
  // Read the ADC, and calculate voltage and resistance from it
  int flexADC = analogRead(FLEX_PIN);
  float flexV = flexADC * VCC / 1023.0;
  float flexR = R_DIV * (VCC / flexV - 1.0);
  Serial.println("Resistance: " + String(flexR) + " ohms");

  // Use the calculated resistance to estimate the sensor's
  // bend angle:
  float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE,
               0, 90.0);
  Serial.println("Bend: " + String(angle) + " degrees");
  Serial.println();

  delay(750);
}

【问题讨论】:

  • 您检查过您的弯曲传感器是否损坏了吗?您可以尝试使用欧姆表来检查它们。

标签: arduino arduino-uno


【解决方案1】:

您的代码中的以下值似乎不正确。这些是以 MOhms 为单位的值,而不是 kOhms。

const float STRAIGHT_RESISTANCE = 24248750.00; // resistance when     straight 
const float BEND_RESISTANCE = 48544996.00; // resistance at 90 deg

另一个问题是 map() 函数只适用于整数!您传入的浮点值会在 map() 函数使用它们之前转换为整数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多