【问题标题】:How to Get Ambient Temp from Arduino Lilypad Temperature Sensor如何从 Arduino Lilypad 温度传感器获取环境温度
【发布时间】:2009-11-03 01:30:14
【问题描述】:

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

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

【问题讨论】:

    标签: arduino microcontroller


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      试试这个。我有完全相同的问题。在这里阅读更多: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);
        

        电压表上的传感器电压读数是多少?当您改变传感器的温度时,读数会改变吗? (握住它应该足以改变读数。)

        【讨论】:

        • 你可以安全地在 c 中转换 int -> float (有一些精度损失)。不过,最初的答案会很有用。
        猜你喜欢
        • 1970-01-01
        • 2014-03-31
        • 1970-01-01
        • 2022-06-14
        • 1970-01-01
        • 1970-01-01
        • 2023-01-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多