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)
main.cpp@0:a2b87ea0684b, 2010-09-28 (annotated)
- Committer:
- y_notsu
- Date:
- Tue Sep 28 15:24:36 2010 +0000
- Revision:
- 0:a2b87ea0684b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
y_notsu | 0:a2b87ea0684b | 1 | #include "mbed.h" |
y_notsu | 0:a2b87ea0684b | 2 | #include "TextLCD.h" |
y_notsu | 0:a2b87ea0684b | 3 | |
y_notsu | 0:a2b87ea0684b | 4 | int nsum=10; |
y_notsu | 0:a2b87ea0684b | 5 | |
y_notsu | 0:a2b87ea0684b | 6 | AnalogIn humidity(p20); |
y_notsu | 0:a2b87ea0684b | 7 | AnalogIn temp(p19); |
y_notsu | 0:a2b87ea0684b | 8 | |
y_notsu | 0:a2b87ea0684b | 9 | float sensorValue2 = 0.0; |
y_notsu | 0:a2b87ea0684b | 10 | float sensorValue3 = 0.0; |
y_notsu | 0:a2b87ea0684b | 11 | |
y_notsu | 0:a2b87ea0684b | 12 | TextLCD lcd(p24,p25,p26,p27,p28,p29); //rs,e,d0-d3 |
y_notsu | 0:a2b87ea0684b | 13 | |
y_notsu | 0:a2b87ea0684b | 14 | |
y_notsu | 0:a2b87ea0684b | 15 | int main() { |
y_notsu | 0:a2b87ea0684b | 16 | while (1){ |
y_notsu | 0:a2b87ea0684b | 17 | for (int i=0;i<nsum;i++) |
y_notsu | 0:a2b87ea0684b | 18 | { |
y_notsu | 0:a2b87ea0684b | 19 | // lcd.cls(); |
y_notsu | 0:a2b87ea0684b | 20 | sensorValue2 += humidity.read(); |
y_notsu | 0:a2b87ea0684b | 21 | // lcd.locate(0,0); |
y_notsu | 0:a2b87ea0684b | 22 | // lcd.printf("p20=%5.3f",sensorValue2); |
y_notsu | 0:a2b87ea0684b | 23 | sensorValue3 += temp.read(); |
y_notsu | 0:a2b87ea0684b | 24 | // lcd.locate(0,1); |
y_notsu | 0:a2b87ea0684b | 25 | // lcd.printf("p19=%5.3f",sensorValue3); |
y_notsu | 0:a2b87ea0684b | 26 | // wait(2.0); |
y_notsu | 0:a2b87ea0684b | 27 | } |
y_notsu | 0:a2b87ea0684b | 28 | float sensorValue2Avg= sensorValue2/(float)nsum; |
y_notsu | 0:a2b87ea0684b | 29 | float RH= 30.855*sensorValue2Avg*3.3-11.504; |
y_notsu | 0:a2b87ea0684b | 30 | |
y_notsu | 0:a2b87ea0684b | 31 | float sensorValue3Avg= sensorValue3/(float)nsum; |
y_notsu | 0:a2b87ea0684b | 32 | float Vt=(float) sensorValue3Avg*3.3; |
y_notsu | 0:a2b87ea0684b | 33 | float R=(5.0-Vt)*10.0/Vt; |
y_notsu | 0:a2b87ea0684b | 34 | float TinC=0.0037*R*R - 0.9876*R + 65.573; |
y_notsu | 0:a2b87ea0684b | 35 | |
y_notsu | 0:a2b87ea0684b | 36 | lcd.cls(); |
y_notsu | 0:a2b87ea0684b | 37 | lcd.locate(0,0); |
y_notsu | 0:a2b87ea0684b | 38 | lcd.printf("RH =%3.1f[per]",RH); |
y_notsu | 0:a2b87ea0684b | 39 | lcd.locate(0,1); |
y_notsu | 0:a2b87ea0684b | 40 | lcd.printf("Temp=%3.1f[deg]",TinC); |
y_notsu | 0:a2b87ea0684b | 41 | |
y_notsu | 0:a2b87ea0684b | 42 | wait(2.0); |
y_notsu | 0:a2b87ea0684b | 43 | |
y_notsu | 0:a2b87ea0684b | 44 | sensorValue2 = 0.0; |
y_notsu | 0:a2b87ea0684b | 45 | sensorValue3 = 0.0; |
y_notsu | 0:a2b87ea0684b | 46 | } |
y_notsu | 0:a2b87ea0684b | 47 | } |