【发布时间】:2016-12-08 23:33:34
【问题描述】:
我有一个与 arduino 睡莲 和 47k ohms 电阻相连的 flex 传感器。
我的问题是我无法从 flex 传感器获得一致的值:有时,我得到非常奇怪的读数,即使 flex 传感器没有处于弯曲状态.
我尝试更改straight_resistance 和bend_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