Pages: [1]   Go Down
Author Topic: Sensor value calculation  (Read 819 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am new to the arduino world, really fun!

I would like your help to calculate the value for a humidity sensor HS15P (datasheet: http://www.robotstorehk.com/hs1215p.pdf)

I copy a script on a site , but I get negative values ​​...

Code:
.....
valb = analogRead(HumPin); // humidity calculation
prehum = (valb);
humconst = (0.16/0.0062);
humi = prehum - humconst;
pretruehumconst = 0.00216*tempc;
pretruehum = 1.0546-pretruehumconst;
truehum = humi/pretruehum ;
delay(1000);

Serial.print ("Humidity: ");


Thank you!
Logged

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you should post the whole script....
Logged

Retired from Arduino.
PMs are set to ignore all.

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

here the hole script, with lm35 T° sensor and HS15p .

The problem that this script is not made for HS15P but similar Humidity sensor with 2 pins.

Code:
int TemPin = 0; // analog pin
int HumPin = 1; // humidity
int tempc = 0, // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;

float humi = 0;
float prehum = 0;
float humconst = 0;
float truehum = 0;
float pretruehum = 0;
long pretruehumconst = 0;
long valb = 0;

void setup()
{
Serial.begin(9600); // start serial communication
}

void loop()
{

for(i = 0;i<=7;i++){

samples[i] = ( 5.0 * analogRead(TemPin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(1000);
}

tempc = tempc/8.0;
tempf = (tempc * 9)/ 5 + 32;

valb = analogRead(HumPin); // humidity calculation
prehum = (valb);
humconst = (0.16/0.0062);
humi = prehum - humconst;
pretruehumconst = 0.00216*tempc;
pretruehum = 1.0546-pretruehumconst;
truehum = humi/pretruehum ;
delay(1000);

Serial.print(tempc,DEC);
Serial.print(" Celsius, ");
Serial.print ("Humidity: ");
Serial.print ((long)truehum);
Serial.println ("% ");

tempc = 0;

delay(1000); // delay before loop
}

Moderator edit: Quote swapped for code tags
« Last Edit: December 30, 2012, 09:51:31 am by AWOL » Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you have the sensor connected to the Arduino? I note that the datasheet says it must be driven with AC only, max 1V rms @ 1KHz, and no DC bias.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16540
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem you face is that the sensor is simply a two terminal resistance element that changes resistance proportional to relative humidity. As such it must be wired into a voltage divider network (or a balanced bridge type circuit) to generate a given voltage range for the humidity range you wish to measure. So until you can calculate the resulting voltage measurement range you are not ready to write any software to handle the values you receive on a analog input pin. So show your sensor wiring setup and maybe we can help with the proper mapping of measurement values.

Lefty

Good point DC42 as that adds another dimension to the interface circuitry needed, a AC voltage source, a divider or bridge circuit, then a diode rectification/filtering stage to finally end up with a DC measurement voltage value.
« Last Edit: December 30, 2012, 09:51:32 am by retrolefty » Logged

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well that value "humconst" which is 0.16/0.0062 is about 26....

So therefore "humi = prehum - humconst" will be -ve for all values of prehum < 26.

Now, prehum is valb, which is the reading from the analog pin, which may be from 0 to 1023, and therefore can be < 26.

If I were you I'd add more serial.print() lines in your code to track the calculation through the steps so you can see where the -ve comes from. I'm guessing those constants in that script are derived for the sensor you mention (the other one, not your one) as part of some kind of calibration and probably don't apply to yours.

This page also warns against using DC!
Logged

Retired from Arduino.
PMs are set to ignore all.

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank 's all for your reply.

Japanese guys seems drive it to work : http://translate.google.tn/translate?sl=auto&tl=en&js=n&prev=_t&hl=fr&ie=UTF-8&eotf=1&u=http%3A%2F%2Ftomono.eleho.net%2F2011%2F03%2F08%2F761%2F&act=url

We cannot calculte the value with is graph :http://einstlab.web.fc2.com/hum/HS15P.png?

Currently in my country it is about 70% humidity
the value received by the analog input is from 1060 to 70% of humidity.
When I made ​​the mist on the sensor is at 1090-1100.

It's that simple? I remove  1000 and I have good values? smiley
« Last Edit: December 30, 2012, 10:14:02 am by azizth » Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Good point DC42 as that adds another dimension to the interface circuitry needed, a AC voltage source, a divider or bridge circuit, then a diode rectification/filtering stage to finally end up with a DC measurement voltage value.

I was thinking more along the lines of using one of the PWM pins to generate a 1kHz square wave, feeding this to a resistor and then the sensor, with a capacitor to ground on the other side of the sensor. Connect the resistor-sensor junction to an analog input and measure the high and low voltages, synchronising the ADC conversions to the timer generating the 1KHz.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16540
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good point DC42 as that adds another dimension to the interface circuitry needed, a AC voltage source, a divider or bridge circuit, then a diode rectification/filtering stage to finally end up with a DC measurement voltage value.

I was thinking more along the lines of using one of the PWM pins to generate a 1kHz square wave, feeding this to a resistor and then the sensor, with a capacitor to ground on the other side of the sensor. Connect the resistor-sensor junction to an analog input and measure the high and low voltages, synchronising the ADC conversions to the timer generating the 1KHz.

I would for me just look for a humidity sensor that has more internal smarts and does all the low level stuff itself. Such a raw sensor can have so many problems with calibration and accuracy problems that I don't know if it's worth the effort.  smiley-wink

Lefty
Logged

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Currently in my country it is about 70% humidity

If you're going to base your calibration on the fact that it's "about 70" when you take a reading to base your calculations on, you might as well not have a sensor in the first place.

But I'd go with Lefty's idea that you need a more crafty sensor anyway!
Logged

Retired from Arduino.
PMs are set to ignore all.

Sweden
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
Arduino System Go!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
your sensor seems to be working a whole lot like the EFS-10 humidity sensor, which I just recently managed to hook up to the Arduino and get to work thanks to the good people at this forum (yes, that's you MarkT :-).

The EFS-10 works on the same principle - you generate a square wave to feed it and you cannot use DC.

The code to drive it is available here, along with some documentation
https://github.com/aweijnitz/Hygrometer

This is the circuit I use an LM135 to measure temperature.



The square wave is generated by switching two digital pins on and off at the right frequency.

I am sure there is room for improvements, but I think it might be a starting point at least.

Good luck!

Anders



Logged

Pages: [1]   Go Up
Jump to: