首页 文章

如何从Arduino Lilypad温度传感器获取环境温度

提问于
浏览
5

我正在将LilyPad Temperature sensor连接到LilyPad Arduino 328 Main Board,目的是读取相当准确的环境温度读数 . 传感器正在接收电源并给出我能够通过串行读取的响应 .

我遇到的问题是从传感器读取给我非常不寻常的 - 虽然数字一致 . 我正在读模拟传感器输入并转换成这样的伏特......

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

  • 0

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

  • 7

    试试这个 . 我有完全相同的问题 . 在这里阅读更多: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
    }
    
  • 3

    根据这个documentation,analogRead返回一个整数 . 您是否尝试将其投射到浮动状态,如下所示:

    therm = (float)analogRead(2);
    

    电压表上的传感器电压读数是多少?更改传感器温度时读数是否会改变? (握住它应该足以改变读数 . )

相关问题