我正在连接一个 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 摄氏度的环境温度。该传感器距离任何其他电子设备都不近,因此我无法预见这是问题所在。

我的读取传感器的代码不正确吗?我的传感器有问题吗?

有帮助吗?

解决方案

是不是一个利利帕德3.3V的Arduino,所以这意味着应当(3.3/1024.0),这将是0.726V,或22.6 C 2

其他提示

尝试此。我有完全一样的problem.read更多在这里: 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);

什么上的电压表读出的传感器电压?请问读数的变化,当你改变传感器的温度? (保持你的手放在它应该是足以改变读数。)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top