2009-11-03 17 views
5

LilyPad Temperature sensor, LilyPad Arduino 328 Main Board'a oldukça doğru ortam sıcaklık okumalarını okumak amacıyla bağlıyorum. Sensör güç alıyor ve seri üzerinden okuyabileceğim yanıtlar veriyor.Arduino Lilypad Sıcaklık Sensörü Ortam Sıcaklığı Nasıl Alınır

Ben karşı karşıya am sorun sensörden okuma beni çok sıradışı veriyor olmasıdır - tutarlı sayılar rağmen. I

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); 
} 

Bu sensör belgeler, yaklaşık 60 santigrat derecelik bir ortam sıcaklığı olacaktır gösterir yaklaşık 1.1 Volt tutarlı bir okuma verir ... analog sensör girişi okuma ve bu gibi volta dönüştürmek olduğum zaman gerçek ortam sıcaklığı yaklaşık 23 derecedir. Sensör diğer elektronik cihazların yakınına yakın değil, bu yüzden problem olduğunu göremiyorum.

Sensörün kodunu okumak için kodum yanlış mı? Sensörüm arızalı olabilir mi?

cevap

7

Lilypad 3,3V'luk bir arduino değil, yani (3.3/1024.0), yani 0.726V veya 22.6 C?

0

bu documentation göre analogRead bir tamsayı döndürür. Bunu gibi bir şamandıra bunu döküm denediniz: Sensör voltajı bir voltmetre okumaya neyi

therm = (float)analogRead(2); 

? Sensörün sıcaklığını değiştirdiğinizde okuma değişir mi? (Üzerinde elinizi tutmak, okumayı değiştirmek için yeterli olmalıdır.)

+1

: Ben daha burada tam olarak aynı problem.read vardı. Orijinal cevap olsa yararlı olurdu. – FryGuy

3

Bunu deneyin. - (bazı hassas kaybıyla) c> şamandıra güvenle int yayınlayabilirsiniz 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 
} 
İlgili konular