5

我将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 摄氏度。该传感器不靠近任何其他电子设备,因此我无法预见这是问题所在。

我读取传感器的代码不正确吗?我的传感器可能有故障吗?

4

3 回答 3

7

lilypad 不是 3.3V arduino,所以这意味着它应该(3.3/1024.0)是 0.726V 或 22.6 C?

于 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 回答