ตอนบ่ายผมได้ทำโปรแกรมวัดค่าอุณหภูมิโดยการอ่านค่าความต้านทานจากเช็นเชอร์โดนมีตารางเทียค่าจากดาต้าชีทสามารถโหลดได้ที่นี้ครับ
www.farnell.com/datasheets/102485.pdf
สวนผมของโปรแกรมครับจะได้แบบนี้ครับ
ส่วนของโปรแกรมครับจะเป็นแบบนี้ครับ
const int analogInPin = A0;
int sensorValue = 0;
float RValue = 0;
float Rsensor = 0;
const long temperature [72][2] =
{
{-55,10723236},{-50,7366689},{-44,5132757},{-40,3624165},{-35,2591304},
{-30,1874913},{-25,1371886},{-20,1014545},{-15,757881},{-10,571590},
{-5,435026},{0,333964},{5,258497},{10,201659},{15,158499},{20,125468},
{25,100000},{30,80223},{35,64759},{40,52589},{45,42951},{50,35272},
{55,29119},{60,24161},{65,20144},{70,16874},{75,14198},{80,11998},
{85,10181},{90,8674},{95,7419},{100,6369},{105,5487},{110,4744},
{115,4115},{120,3581},{125,3126},{130,2737},{135,2404},{140,2117},
{145,1869},{150,1655},{155,1469},{160,1307},{165,1166},{170,1043},
{175,934},{180,839},{185,755},{190,681},{195,615},{200,557},{205,505},
{210,459},{215,418},{220,382},{225,349},{230,319},{235,292},{240,269},
{245,247},{250,227},{255,210},{260,194},{265,179},{270,166},{275,154},
{280,143},{285,133},{290,124},{295,115},{300,107}};
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(analogInPin);
Serial.print("sensor = " );
Serial.print(sensorValue);
//RValue = ((50/(5-((sensorValue*5)/1024)))-10);
RValue = (sensorValue*5.0000)/1024.0000;
Serial.print(" \t R = " );
Serial.print(RValue);
Rsensor = ((50/(5 - RValue))-10)*1000;
Serial.print(" Rsensor = " );
Serial.println(Rsensor);
for(int i =0 ; i<72 ; i++)
{
if(Rsensor>temperature[i][1])
{
Serial.print(temperature[i][1]); //R_MAX
Serial.print(',');
Serial.print(temperature[i][0]); //T_MAX
Serial.print(',');
Serial.print(temperature[i-1][1]); //R_MIN
Serial.print(',');
Serial.println(temperature[i-1][0]); //T_MIN
break;
}
}
delay(1000);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น