5

LilyPad温度センサーLilyPadArduino328メインボードに接続して、かなり正確な周囲温度の読み取り値を読み取ることを目的としています。センサーに電力が供給され、シリアルで読み取ることができる応答が返されます。

私が直面している問題は、センサーからの読み取りが非常に珍しいことです-一貫した数値ですが。私はアナログセンサー入力を読んでいて、このようにボルトに変換しています...

loop(){
    float therm;   
    therm = analogRead(2); // Read from sensor through Analog 2
    therm *= (5.0/1024.0); // 5 volts / 1024 units of analog resolution
    delay(100);
}

これにより、約1.1ボルトの一貫した読み取り値が得られます。これは、実際の周囲温度が約23度の場合、センサーのドキュメントが摂氏約60度の周囲温度になることを示しています。センサーは他の電子機器の近くにないので、それが問題であるとは予測できません。

センサーを読み取るための私のコードは正しくありませんか?センサーが故障していませんか?

4

3 に答える 3

7

リリーパッドは3.3Varduinoではないので、0.726V、つまり22.6Cになるはず(3.3/1024.0)です。

于 2009-11-03T02:01:19.520 に答える
3

これを試して。私はまったく同じ問題を抱えていました。詳細はこちら:http ://www.ladyada.net/learn/sensors/tmp36.html

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures

#define BANDGAPREF 14   // special indicator that we want to measure the bandgap

/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  Serial.begin(9600);  //Start the serial connection with the computer
                       //to view the result open the serial monitor 
  delay(500);
}

void loop()                     // run over and over again
{
  // get voltage reading from the secret internal 1.05V reference
  int refReading = analogRead(BANDGAPREF);  
  Serial.println(refReading);

  // now calculate our power supply voltage from the known 1.05 volt reading
  float supplyvoltage = (1.05 * 1024) / refReading;
  Serial.print(supplyvoltage); Serial.println("V power supply");

  //getting the voltage reading from the temperature sensor
  int reading = analogRead(sensorPin);  

  // converting that reading to voltage
  float voltage = reading * supplyvoltage / 1024; 

  // print out the voltage
  Serial.print(voltage); Serial.println(" volts");

  // now print out the temperature
  float temperatureC = (voltage - 0.5) * 100 ;   //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((volatge - 500mV) times 100)
  Serial.print(temperatureC); Serial.println(" degress C");

  // now convert to Fahrenheight
  float temperatureF = (temperatureC * 9 / 5) + 32;
  Serial.print(temperatureF); Serial.println(" degress F");

  delay(1000);                                     //waiting a second
}
于 2009-12-30T23:35:20.057 に答える
0

このドキュメントによると、analogReadは整数を返します。次のようにフロートにキャストしてみましたか?

therm = (float)analogRead(2);

センサー電圧は電圧計で何を読み取りますか?センサーの温度を変えると読み値は変わりますか?(手をかざすだけで読みが変わります。)

于 2009-11-03T01:58:06.983 に答える