2009-11-03 9 views
5

Estoy conectando un LilyPad Temperature sensor a un LilyPad Arduino 328 Main Board con el objetivo de leer lecturas de temperatura ambiente bastante precisas. El sensor está recibiendo energía y dando respuestas que puedo leer en serie.Cómo obtener la temperatura ambiente de Arduino Lilypad Sensor de temperatura

El problema al que me enfrento es que la lectura desde el sensor me está resultando muy inusual, aunque con números consistentes. Estoy leyendo la entrada del sensor analógico y conversión en voltios como este ...

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

Esto produce una lectura constante de aproximadamente 1,1 voltios, que la documentación del sensor indica que sería una temperatura ambiente de aproximadamente 60 grados centígrados cuando la la verdadera temperatura ambiente es de aproximadamente 23 grados. El sensor no está cerca de ningún otro dispositivo electrónico, por lo que no puedo prever que ese sea el problema.

¿Mi código de lectura del sensor es incorrecto? ¿Podría mi sensor estar defectuoso?

Respuesta

7

¿No es el lilypad un arduino de 3.3V, por lo que significa que debería ser (3.3/1024.0), que sería 0.726V o 22.6 C?

0

Según este documentation, analogRead devuelve un número entero. ¿Ha intentado arrojarlo a un flotador de este modo:

therm = (float)analogRead(2); 

¿Qué leer el voltaje del sensor en un voltímetro? ¿La lectura cambia cuando cambia la temperatura del sensor? (Sostener su mano sobre él debería ser suficiente para cambiar la lectura.)

+1

se puede lanzar con seguridad int -> flotante en C (con alguna pérdida de precisión). La respuesta original sería útil, sin embargo. – FryGuy

3

Pruebe esto. Tenía exactamente la misma problem.read más aquí: 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 
} 
Cuestiones relacionadas