2016-03-28 125 views
1

無法測量arduino中溫度傳感器的溫度, 其給出錯誤的溫度=溫度= 499.51 * c。即時連接溫度傳感器到Arduino uno套件。我需要像35的溫度值無法用arduiono套件中的溫度傳感器測量溫度值

int val; 
int tempPin = 1; 

void setup() 
{ 
    Serial.begin(9600); 
} 
void loop() 
{ 
    val = analogRead(tempPin); 
    float mv = (val/1024.0) * 5000; 
    float cel = mv/10; 
    float farh = (cel * 9)/5 + 32; 

    Serial.print("TEMPRATURE = "); 
    Serial.print(cel); 
    Serial.print("*C"); 
    Serial.println(); 
    delay(1000); 

    /* uncomment this to get temperature in farenhite 
    Serial.print("TEMPRATURE = "); 
    Serial.print(farh); 
    Serial.print("*F"); 
    Serial.println(); 


    */ 
} 

回答

0

你不清楚你使用的是什麼溫度傳感器。從你的代碼看,你似乎使用模擬傳感器。如果是這樣,你應該

a) check the data sheet of the sensor and adjust your code accordingly 
OR 
b) calibrate your system by taking readings of known temperatures and adjusting your code accordingly. 

隨着你給的信息,它很難更具體。