Arduino Lilypad温度センサーから周囲温度を取得する方法
-
12-09-2019 - |
質問
を接続しています LilyPad 温度センサー に LilyPad Arduino 328 メインボード かなり正確な周囲温度の測定値を読み取ることが目的です。センサーは電力を受け取り、シリアル経由で読み取ることができる応答を返しています。
私が直面している問題は、センサーからの読み取り結果が非常に異常であるにもかかわらず、一貫した数値を示していることです。アナログセンサー入力を読み取り、このようにボルトに変換しています...
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 度になることが示されています。センサーは他の電子機器に近接していないため、それが問題になるとは予想できません。
センサーを読み取るためのコードが間違っていますか?私のセンサーが故障している可能性がありますか?
解決
それは0.726V、または22.6 Cされるであろう、それは
(3.3/1024.0)
れるべきであることを意味するので、は、lilypad 3.3VのArduinoのではないか。
他のヒント
これを試して。私もまったく同じ問題を抱えていました。詳しくはこちらをご覧ください: 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
}
この文書するによれば、analogReadは整数を返します。
:あなたはそうのようなフロートにキャストしようとしていますtherm = (float)analogRead(2);
どのようなセンサ電圧は、電圧計で読むのですか?あなたは、センサの温度を変更したときに読み取り変更していますか? (読書を変更するのに十分であるべきで、あなたの手を握って。)
所属していません StackOverflow