2009-11-03 11 views
5

Łączę LilyPad Temperature sensor z LilyPad Arduino 328 Main Board celem odczytu dość dokładnych odczytów temperatury otoczenia. Czujnik otrzymuje moc i daje odpowiedzi, które jestem w stanie odczytać przez port szeregowy.Jak uzyskać temperaturę otoczenia z czujnika temperatury Lafdu Arduino

Problemem, z którym się skonfrontowałem, jest to, że odczyt z czujnika daje mi bardzo nietypowe - choć spójne liczby. Czytam czujnikami analogowych i przechodzenia na V tak ...

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

Daje to powtarzalność pomiaru wynosi około 1,1 V, dokumentację czujnik wskazuje będzie temperatura otoczenia, około 60 stopni Celsjusza, gdy rzeczywista temperatura otoczenia wynosi około 23 stopni. Czujnik nie znajduje się blisko żadnej innej elektroniki, więc nie mogę przewidzieć, że jest to problem.

Czy mój kod do odczytu czujnika jest nieprawidłowy? Czy mój czujnik może być wadliwy?

Odpowiedz

7

Czy lilypad nie jest 3,3V arduino, więc oznacza to, że powinno to być (3.3/1024.0), co powinno wynosić 0,726V lub 22,6 C?

0

Zgodnie z tym documentation, analogRead zwraca liczbę całkowitą. Czy próbowałeś rzucić to w taki sposób:

therm = (float)analogRead(2); 

Co odczytuje napięcie czujnika na woltomierzu? Czy odczyt zmienia się po zmianie temperatury czujnika? (Trzymanie ręki na niej powinno wystarczyć, aby zmienić odczyt).

+1

można bezpiecznie oddanych int -> pływaka w C (z pewną utratą precyzja). Oryginalna odpowiedź byłaby jednak przydatna. – FryGuy

3

Spróbuj tego. Miałem dokładnie ten sam problem.read więcej tutaj: 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 
}