안드로이드 ADK를 통해 서미스터에서 섭씨 독서가 잘못되었습니다

StackOverflow https://stackoverflow.com//questions/22006158

  •  21-12-2019
  •  | 
  •  

문제

Mario Boehmer의 책에서 프로젝트 8, Arduino가있는 Android ADK를 시작했습니다. 다음 값으로 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/0bwon70droimfz0frz2vssvhk00/edit.? USP= 공유

도움이 되었습니까?

해결책

그것은 어리석은 ... 나는 10K 저항 대신 1k 저항을 사용하고 있었다. 하드웨어를 교체했는데 지금 올바르게 작동합니다. 당신의 도움을 주셔서 감사합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top