【问题标题】:Invalid Celsius reading from Thermistor via Android ADK通过 Android ADK 从热敏电阻读取的摄氏温度无效
【发布时间】:2014-04-08 18:15:02
【问题描述】:

我正在参与 Mario Boehmer 的书“使用 Arduino 开始 Android ADK”中的项目 8。 我正在使用具有以下值的 10k 热敏电阻,但我的温度报告为 6531.0C,这显然是不正确的。

long r0 = 10000;
long beta = 4050;

// temperature in kelvin at at 25 celsius
double t0 = 298.15;
// value of second resistor
long additional_resistor = 10000;
// input voltage
float v_in = 5.0;

串行监视器的读数如下:

currentThermistorResistance: 128378.38
currentTemperatureInDegrees: -22.16
convertedValue: -221
voltageMeasured: 0.36

完整代码如下:

#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

#define COMMAND_TEMPERATURE 0x4
#define INPUT_PIN_0 0x0

// Size: 5mm
// Resistance: 10KΩ
// Temperature: -30°C to +125°C
// Tolerance: ±10%

//-----
//change those values according to your thermistor's datasheet
// original
// long r0 = 4700;
// long beta = 3980;

//new
long r0 = 10000;
long beta = 4050;
//-----

// temperature in kelvin at at 25 celsius
double t0 = 298.15;
// value of second resistor
long additional_resistor = 10000;
// input voltage
float v_in = 5.0;

double r_inf;
double currentThermistorResistance;

/*
AndroidAccessory(const char *manufacturer,
                 const char *model,
                 const char *description,
                 const char *version,
                 const char *uri,
                 const char *serial);
*/

AndroidAccessory acc("UW MHCID",
             "HCID TempSense",
             "A temperature sensing android application",
             "0.1",
             "https://github.com/pdugan20/hcid-temp-sense",
             "0000000012345678");

byte sntmsg[6];

void setup() {
  Serial.begin(19200);
  acc.powerOn();
  // changed from powerOn() to begin()
  // acc.begin();
  sntmsg[0] = COMMAND_TEMPERATURE;
  sntmsg[1] = INPUT_PIN_0;
  r_inf = r0 * (exp((-beta) / t0));
}

void loop() {
  if (acc.isConnected()) {
    int currentADCValue = analogRead(INPUT_PIN_0);

    float voltageMeasured = getCurrentVoltage(currentADCValue);
    double currentThermistorResistance = getCurrentThermistorResistance(voltageMeasured);
    double currentTemperatureInDegrees = getCurrentTemperatureInDegrees(currentThermistorResistance);

    // multiply the float value by 10 to retain one value behind the decimal point before converting
    // to an integer for better value transmission
    int convertedValue = currentTemperatureInDegrees * 10;

    sntmsg[2] = (byte) (convertedValue >> 24);  
    sntmsg[3] = (byte) (convertedValue >> 16);  
    sntmsg[4] = (byte) (convertedValue >> 8);  
    sntmsg[5] = (byte) convertedValue;
    acc.write(sntmsg, 6);
    delay(100);
  }
}

// "reverse ADC calculation"
float getCurrentVoltage(int currentADCValue) {
  return v_in * currentADCValue / 1024;
}

// rearranged voltage divider formula for thermistor resistance calculation
double getCurrentThermistorResistance(float voltageMeasured) {
  return ((v_in * additional_resistor) - (voltageMeasured * additional_resistor)) / voltageMeasured; 
}

//Steinhart-Hart B equation for temperature calculation
double getCurrentTemperatureInDegrees(double currentThermistorResistance) {
  return (beta / log(currentThermistorResistance / r_inf)) - 273.15; 
}

有人有什么想法吗? 我的完整代码在这里: https://github.com/pdugan20/hcid-temp-sense

有问题的热敏电阻是以下数据表中的 103: https://drive.google.com/file/d/0BwOn70drOiMfZ0FrZ2VsSVhKQ00/edit?usp=sharing

【问题讨论】:

  • 请更新问题以包含相关代码。该链接可能随时消失。
  • 能不能用串口监视器调试一下电压Measured、currentThermistorResistance、currentTemperatureInDegrees 和convertedValue 的值是多少,这样我们就可以知道问题出在哪里了。另外,您确定您已正确连接所有内容吗?见playground.arduino.cc/ComponentLib/Thermistor
  • @lesto 当然,我已经包含了上面这些变量的值。我相当肯定它连接正确。
  • 尝试用各种普通电阻代替热敏电阻,看看是否可以简单地改变读数。还要确保如果热敏电阻与电路中的固定电阻器一起工作,则该值是正确的,并且不会偏离 10 或 100 倍。查看色带时使用良好的光线,或使用仪表进行验证。用仪表测量热敏电阻并与其曲线进行比较也是一个好主意。
  • @ChrisStratton 你是对的,我插入了错误的电阻器。它现在工作正常。

标签: android arduino adk


【解决方案1】:

那是愚蠢的... 我使用的是 1k 电阻而不是 10k 电阻。 更换了硬件,现在可以正常工作了。 谢谢大家的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    相关资源
    最近更新 更多