Go Down

Topic: HSM-20G analog temperature/humidity sensor (Read 10170 times) previous topic - next topic



I recently bought one of these: http://www.seeedstudio.com/depot/humidity-temperature-sensor-module-p-75.html?cPath=6 expecting that I would be able to work it out from the data sheet once I had it in my hands :-)

Looks like I'm wrong - I'm simply trying display the output in degrees C and %RH but I can't find the relevant info on how to convert the numbers.

Has anyone else had success with this sensor?



Feb 22, 2010, 11:56 pm Last Edit: Feb 23, 2010, 12:15 am by dsg0812 Reason: 1
Hi, please read the datasheet:

Tha datasheet has good graphs and values and how to wire it up.
with 5v Ref voltage, the humidity% :

%RH   OutputV
10       0.74
20       0.95
30       1.31  
40       1.68
50       2.02
60       2.37
70       2.69
80       2.99
90       3.19

Now for the conversion on Arduino analog pin in:
0V = 0 and 5V =1023, you do the math  8-)

To test temperature:
place crushed icecube and a bit of water in plastic-bag (or condom ;) ) and place over sensor, The sensor should give the analog value for 0C. use another human-readable thermometer to take the temperature in the room, the sensor is giving the analog value for this temperature. Repeat for stable higher temp, perhaps boiling water at nearly 100C, and sensor touching upper-outside of the pan/pot...



Feb 23, 2010, 12:45 am Last Edit: Feb 23, 2010, 12:55 am by dsg0812 Reason: 1
To get a "workable" formula for the Arduino to calculate temperature or RH%:
open Excel and input the values for Voltage or Arduino analog-in as X-axis and oC or %RH as Y-axis.
Make Scatter plot of the data (use the dots, not whole line)
Right click on one of the resulting points and choose trendline
Right click on the trendline and choose format trendline
select show formula, and choose the right type of trendline (straight line or poy (2 to 5 degree) or exp)

The formula for either temp or humidity should be visible now in the plot, it can be used with arduino to calculate right values.

The formula for %RH seems to be:
y = 4,8008*x^5 - 47,772*x^4 + 184,64*x^3 - 343,78*x^2 + 334,28*x - 110,6
where number after ^ is an exponent.



Hi ArduinoM,

Thanks for posting - I just learned a whole lot about excel and arduino :-).

Got RH working well with the code below based on a linear trendline (to make the maths easy) and the data provided in the data sheet.  Now for some reason I don't understand the temperture outputs on the data sheet are given in ohms and the output from arduino is showing 1023 which is presumably 60C or higher...?  One thing is for sure - it's cold and wet here today.... any ideas?

Code: [Select]
int tempsense = 0;
int rhsense = 0;
int temp = 0;
int rh = 0;

void setup() {

void loop() {

tempsense = (analogRead(1));
rhsense = (analogRead(2));
temp = (tempsense/50);
rh = ((30.855*(rhsense/204.6))-11.504);

Serial.print("Temperature: ");
Serial.println(" C ");

Serial.print("Humidity: ");
Serial.println("% ");


Ahhh-ha  I got the temp value to respond by engaging the pullup resitors on that pin - I just need to figure the formula out now as dividing the analogread value by 50 is clearly wrong !!!


Good that you are getting some data ;)
What voltage are you getting from the temp sensor?

Now the datasheet gives the ohm of the temperature
so now we need to do some calculations.
You really need to work from a value given from the table, and by far the most accurate value to reach is the 0C, if your room is excactly 25C then fine use 25C

Temperature([ch8451])      Resistance(k[ch937])
0                      163,81
10                      97,1
20                      59,42
25                      47
30                      37,43
40                      24,19
50                      16,01
60                      10,83

If you use the 0C, place sensor in plastic bag, crush icecube and place in another plastic bag and add a tiny amount of water to wet the crushed ice. Tie ice plastic bag tightly and wipe any moisture/water from the outside. Place icebag on top of baged sensor, The ice holds excactly 0C while melting!
Now read the voltage value from the Arduino (convert the 0 to 1023 value to voltage).
The formula for Amps = V/R (voltage divided by resistance)
The Arduino outputs 5V so if you read 4V then the voltage drop is 1V (5V - read value).
Amps = 1V/163810 Ohm
The amps should remain constant, so now that you have the konstant of I (amps) then you can find the voltage drop for the other temperatures by multiplying I*R = V (where I is your constant and R is the resistance of the table above).

The resistance drops when warmed up so it will eat less voltage.

I recomend to make another excel plot from the table above but with calculated voltage instead of Resistance:
X-axis: Voltage (or 0-1023 digital values)
Y-axis: Temperature

Make regression line and note the formula.

Be careful with water and electricity ;)



Oh by the way...
If you know the excact temperature of your room:
(from Excel and the table above)
y = -0,0007x^3 + 0,1114x^2 - 6,5523x + 152

X= the temperature of your room
Y= Resistive value R in kOhm (multiply by 1000 to get Ohm)

Read voltage drop (5V - voltage analog in) and calculate I.

(this formula only correlates by 99.98% =R value in regression line)


Fab again - many thanks.

I think the temp part of the sensor is duff as the value goes from 908 down to 892 when droping from 22C to 0C which is less than 1 degree resolution!!  I guess I'm stuck with just RH with this sensor.... but learnt loads so thanks for your time and knowledge :-)


There might be a solution:
change the ref voltage!
the humidity does not go over 3.3V
so ref voltage should be 3.3V  (jumper from 3.3V to Ref)

Add a resistor between temp output and analog in so that the voltage does not go over 3.3 V at 80 or 100C  (CAREFUL not to fry the Arduino)

this should increase the resolution
3.3V is now 1023

Humidity resolution will be almost 70% better

I can not find any good data on this device so can not find out max resolution of the temp sensor.

in the datasheet temp/resistance plot there are 37 datapoints for temp range from -55 to 125C ! so I would not get too excited ;)

It might be good to compliment your sensor with LM35



I have a writeup here:


Seems to work fairly well.


Hi Itsthemedication,

Thanks for sharing your work - very much appreciated.  I have now had a go and finally got the sensor working :-)  On my arduino 328 it outputs sensible figures but when I load up onto a 168 the figures are quite a bit out - any idea why this should be?

328             168
52.2 %RH    83.3 %RH
25.4 deg C  36.8 deg C

52.2 %RH    83.3 %RH
25.4 deg C   36.8 deg C

52.4 %RH    83.3 %RH
25.4 deg C   36.8 deg C



Go Up