Temperature and Humidity measure by HSM20G, and display the information of Temp / RH in TextLCD (16 x 2). The circuit between mbed and HSM20G is recommended circuit. ( http://sites.google.com/site/measuringstuff/more-sensor-examples#TOC-HSM-20G-Humidity-and-Temperature-Mi)
Diff: main.cpp
- Revision:
- 0:a2b87ea0684b
diff -r 000000000000 -r a2b87ea0684b main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 28 15:24:36 2010 +0000 @@ -0,0 +1,47 @@ +#include "mbed.h" +#include "TextLCD.h" + +int nsum=10; + +AnalogIn humidity(p20); +AnalogIn temp(p19); + +float sensorValue2 = 0.0; +float sensorValue3 = 0.0; + +TextLCD lcd(p24,p25,p26,p27,p28,p29); //rs,e,d0-d3 + + +int main() { + while (1){ + for (int i=0;i<nsum;i++) + { + // lcd.cls(); + sensorValue2 += humidity.read(); + // lcd.locate(0,0); + // lcd.printf("p20=%5.3f",sensorValue2); + sensorValue3 += temp.read(); + // lcd.locate(0,1); + // lcd.printf("p19=%5.3f",sensorValue3); + // wait(2.0); + } + float sensorValue2Avg= sensorValue2/(float)nsum; + float RH= 30.855*sensorValue2Avg*3.3-11.504; + + float sensorValue3Avg= sensorValue3/(float)nsum; + float Vt=(float) sensorValue3Avg*3.3; + float R=(5.0-Vt)*10.0/Vt; + float TinC=0.0037*R*R - 0.9876*R + 65.573; + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("RH =%3.1f[per]",RH); + lcd.locate(0,1); + lcd.printf("Temp=%3.1f[deg]",TinC); + + wait(2.0); + + sensorValue2 = 0.0; + sensorValue3 = 0.0; + } +}