RH% with Honeywell

manie

Senior Member
I am using the Rev-Ed supplied RH sensor. See attached datasheet.
This my code for reading the sensor and calculating RH %.
Variable names with a "b" suffix = bytes, those with a "w" suffix = words.
Code:
ReadRh:

	Tempw1=0
	for Cntb1=1 to 3
		readadc 3, AdcInW				'read RH adc value
		tempw1=tempw1+AdcInW
	next cntb1

	AdcInW=tempw1/3
	tempw1 = AdcInW * 198/10 + 0 max 5100	'calc mV from 8bit read ( reading * 19.8=mV value)
	tempw2=tempw1 - 960 min 0			'subtract 0.96V = zero % offset value
	tempw1 = tempw2*10/307 + 0 max 100		'divide by 30.7mV per 1% RH
	Cntb1 = 0 + tempw1 max 100			'Rh=actual Rel.Hum.%
	cntb2=tempw1//10
	put 26,cntb1:put 27,cntb2
	
return
I am getting some funny values. Could it be the code or could the sensor be faulty ?

Thanks for looking.
EDIT:
Sorry, datasheet now attached.
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
The hard part is working out what all your 'magic numbers' do and why. I'd also forget about the averaging to start with ( simple though it is ) and storing the resuts, Start with a simple read sensor SERTXD out the results.

Best apprach is to write it out as an equation showing each step in converting from an analoge reading for each individual step, then it's a question of checking your equation is right then, secondly, is it implemented correctly as as a program.

As it stands, anyone trying to help will have to work out the equations, turn that into a program and hope to see where what you have may diverge from what they have if it does differ.

The best way to test any conversion program is to put it in a subroutine called then call it with various values ( what would be sensor values in the final product ) see what the results are, does it match.
 

MartinM57

Moderator
There's a nice graph in the datasheet for Vout vs. RH - so:
- a quick check with a multimeter on your ADC pin will confirm a sensible voltage is being obtained
- a sertxd/debug statement after the readadc will tell you if you are making sensible ADC readings
- otherwise it's time to delve into the maths
 

Dippy

Moderator
Do what Martin says.

Then remove all the faffy stuff after AdcInW=tempw1/3

Then check AdcInW.

Obv those variables are declared as Words.
And ReadADC is...
 

hippy

Ex-Staff (retired)
My equation ( assuming floating point allowed ) ...

Nadc = 0 to 255
Vpsu_mv = 5000 mV
Vmin_mV = 958 mV
Vmax_mV = 4070 mV

Vadc_mV = Nadc / 255 * Vpsu_mV

rh% = ( Vadc_mV - Vmin_mV ) *100 / ( Vmax_mV - Vmin_mV )

Also note that to do limiting you cannot use "MIN 0" as the PICAXE is positive integer only ...

n = ( Vadc_mV - Vmin_mV ) Min 0

has to be coded as -

n = ( Vadc_mV Min Vmin_mV ) - Vmin_mV
 
Last edited:

hippy

Ex-Staff (retired)
This works for me. You could probably improve the conversion operations ...

Code:
#Picaxe 20X2
#Terminal 9600
#No_Table
#No_Data

Symbol Nadc    = w0
Symbol Vadc_mV = w1
Symbol rh      = w2

Pause 2000

Nadc =  49 : Gosub Convert
Nadc = 167 : Gosub Convert
Nadc = 208 : Gosub Convert
End
 
Convert:
  Vadc_mV = Nadc * 19
  Vadc_mV = Nadc * 6 / 10 + Vadc_mV
  rh = Vadc_mV Min 958 - 958 * 10 / 311 Max 100
  SerTxd( #Vadc_mV, "mV = ", #rh, "%", CR, LF )
  Return
960mV = 0%
3273mV = 74%
4076mV = 100%
 
Last edited:

manie

Senior Member
Thanks to ALL for answering: What makes you feel REALLY BAD is asking help when you could solve the problem yourself. I have to be honest, I was able to solve it, as the calculation is correct (except for "Min 0" part....). Problem was this:

Project is Chook-House controler project.
The farmer cleaned (pressure washed) the chook-house.
He DID however remove the LM35DZ's and the RH sensors....
He plugged them back in....
He plugged them into wrong sockets....:eek:
RH sensor was thus wired "backwards", so produced funny voltages.:eek:

I plugged the sensors into their correct respective sockets, it worked fine.:)

HOWEVER, I've learnt a bit again on the applicable maths part. Thanks guys.

Really appreciated........;)
 

eclectic

Moderator
.
He DID however remove the LM35DZ's and the RH sensors....
He plugged them back in....
He plugged them into wrong sockets....:eek:
RH sensor was thus wired "backwards", so produced funny voltages.:eek:

I plugged the sensors into their correct respective sockets, it worked fine.:)

HOWEVER, I've learnt a bit again on the applicable maths part. Thanks guys.

Really appreciated........;)
None of my business, BUT, can you
make / buy some different plugs and sockets,
so that this never happens again?

Murphy lives everywhere. Including SA. :)

e
 
Last edited:

manuka

Senior Member
According to ex. RSA mates (now here in NZ) ,Murphy actually LIVES in Sth. Africa, with just occasional trips away elsewhere to blight the rest of us.

Aside from different plug types (which people WILL TRY TO RAM IN ANYWAY) a touch of colour coding/white out suitably placed on both plug & socket works wonders. Users then just have to match the patterns/numbers/letters - X to X, 1 to 1 etc. I've 9 cordless drills (long story) & their diverse chargers were often confused until this was done. Stan
 

Dippy

Moderator
Hopefully you will also have learnt to check the basics before checking something which must have been (by definition) working before when you first installed it.

So many people fail to check fuses before consigning their TV etc to the bin.
 
Top