Getting temperature and humidity values from sht11

Hello,

Is there anyone who's tried to work with sht11 module. I would like to get values of temperature and humidity from tmote sky mote. I used those formulas:

Temperature = (unsigned) (-39.60 + 0.01 * sht11_temp()); for temperature
rh = sht11_humidity(); for humidity

I am getting these wrong values : 615°C and 2650%.

Thank you.

Best regards.

I used those formulas

But, did you implement them correctly in the code?

Temperature = (unsigned) (-39.60 + 0.01 * sht11_temp()); for temperature
rh = sht11_humidity(); for humidity

Temperature and rh raw values are unsigned. However, Temperature is a signed floating point value and rh is an unsigned floating point value. Depending on how your code is implemented rh is calculated using temperature in degrees C. A float is commonly used for both values for simplicity. Appears that an unsigned temperature value is being used but hard to tell without seeing the code.

Eric

Hello Pauls,

what did you mean by "But, did you implement them correctly in the code?". i just apply these formula and display the value of variables temperature and humidity by calling them inside a printf. and these formulas are taken from datasheet.

LAVco, i do not think so there is unsigned floating point, because floating point types are float, double and long double, maybe am wrong?

Regards.

Amy.

what did you mean by "But, did you implement them correctly in the code?".

I meant Show Your Code. We can't tell how you implemented the equation from your hand waving. The equation has a mix of variable types. The compiler makes some assumptions, not always the ones you expect, about how mixed type operations should be performed. Sometimes you need to override that default behavior with intermediate variables or casting. We can't see whether you have done that, or not. If you haven't implemented the equations correctly, you could be getting zero or other incorrect output.

Here is the code. I did not include calling statement like #include <.....>

/---------------------- Computation of RSSI---------------------------------/

/* This assumes that the CC2420 is always on and "stable" */
static void
setting_frq(int c)
{
int f;
f = c + 302 + 0x4000;

FASTSPI_SETREG(CC2420_FSCTRL, f);
FASTSPI_STROBE(CC2420_SRXON);
}
//RSSI
static int do_rssi(void)
{
int channel = 26;
int RSSIvalue;
setting_frq(channel + 55);
RSSIvalue = cc2420_rssi();
return RSSIvalue;
}

PROCESS(process_test, "This is a test");
AUTOSTART_PROCESSES(&process_test);

static void
recv_from(struct test_conn *c, rimeaddr_t *origine, uint8_t seqno)
{

extern rimeaddr_t rimeaddr_node_addr;

printf("node %d.%d: send to node %d.%d:sequence Num(%u):'%.*s'\n",
origine->u8[0],origine->u8[1],
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], seqno,
rimebuf_datalen(),
(char *)rimebuf_dataptr());
}
static const struct test_callbacks test_call = {recv_from};

static struct test_conn test_conn;
/--------------------This contains the code of the process--------------------/
PROCESS_THREAD(process_broadcasting, ev, data)
{

PROCESS_EXITHANDLER(test_close(&test_conn):wink:

PROCESS_BEGIN();

test_open(&test_conn, 200, &test_call);

rime_mac->off(0);
cc2420_on();

SENSORS_ACTIVATE(battery_sensor);

while(1) {
static struct etimer et;
static unsigned rh;
unsigned Temperature;
uint16_t volt;
int len, rssi;

etimer_set(&et, CLOCK_SECOND * 5);

PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

rh = sht11_humidity();
volt = battery_sensor.value(0);
Temperature = (unsigned) (-39.60 + 0.01 * sht11_temp());
rssi = do_rssi();

/------ Battery voltage calculation formula
V(Battery Voltage) = v(Voltage Reference) * 1024 / ADC
Where: v = 1.223 ------
/

rimebuf_clear();

len = snprintf((char )rimebuf_dataptr(), RIMEBUF_SIZE,
"temperature(C);RSSI(dBm);ADC value(V);humid: %u %d %d.%dV %u%%",
Temperature,
rssi,(volt / 819), ((10 * volt / 819) % 10),
(unsigned) (-4 + 0.0405
rh - 2.8e-6*(rh*rh)));
rimebuf_set_datalen(len);

}

PROCESS_END();
}
/---------------------------------------------------------------------------/

Thanks.

Regards.

static unsigned rh;
(unsigned) (-4 + 0.0405*rh - 2.8e-6*(rh*rh))

2.8e-6rhrh is an integer, which is going to be 0 unless the value in rh is large. What value(s) are in rh when this code is executed?

0.0405*rh will be an integer after the multiplication is complete. If rh is small, the result will be 0.

-4 - 0 - 0 will be -4. Cast as an unsigned is going to produce strange results.

The code snippet doesn't define what type sht11_temp() returns, so I can't comment on that computation, except to think that Temperature should NOT be unsigned. Is there not the possibility that the temperature will go below 0? Happens here often enough.

sht11_temp() return nan unsigned integer, from sht11 datasheet. even if sht11_humidity: so unsigned int sht11_temp(void); unsigned int sht11_humidity(void);

thank you for your help.

Regards.

What are the range of values returned by sht11_humidity() and sht11_temp()?

The range values for tsht11_humidity() is: from 0 to 100% with accuracy of +- 3.5% and for sht11_temp(): -40 °Cto 123.8°C with accuracy of +-0.5°C at 25°C.

Regards.

If sht11_humidty() returns values in the range 0 to 100 (%), why do you need to manipulate the values with the equation?

If sht11_temp() returns values from -40 to 123.8, why are you storing the output in an unsigned int? Why do you then need to manipulate the values with the equation?

For clarification on my post; raw values read from the sensor are unsigned int. However, these raw values are multiplied by coefficient values as per sensirion datasheet and formulas provided which in turn produce floating point values. Temperatue must be read first in order to perform temperature compensation on the rh value.

Do a search within the forum for SHT11 or Sensirion. There are two libraries that exist to date. I have created my own library that has blocking and non-blocking calls porting sample code supplied on the Sensirion web site which is another place to compare your code against.

Eric

Hello Paul,

You have to use these equation for gettings temperature and humidity values, these formulas as the good one given from sht11 datasheet. I you want to measure temperature and humidity you have to follow these steps because sensor temeprature and humidity is from this constructeur. I think there is a measunderstood between what i want and what you reply. my devices are using teperature and humidity sensors from Sensirion which give shtt11.

Thanks Lavco for clairification, i will follow that.

Regards.

Hello Paul,

You have to use these equation for gettings temperature and humidity values, these formulas as the good one given from sht11 datasheet.

I asked what the output from sht11_humidity() and sht11_temp() looked like. The answer you gave was:

The range values for tsht11_humidity() is: from 0 to 100% with accuracy of +- 3.5% and for sht11_temp(): -40 °Cto 123.8°C with accuracy of +-0.5°C at 25°C.

Clearly, this reply is wrong.

This reply is taken form sht11 datasheet. Before to say "this reply is wrong", go to google and download the datasheet and see what is written there. I asked question for getting help and clearly response that can help me to get good measure, not misleading.

Thank you very much.

Regards.

And I asked you to show the code for the sht11_humidity() and sht11_temp() functions, and for the range of values each function can return.

The answer you gave was wrong. The answer you gave was the range of values that you are supposed to get from the equations that you showed.

Since you ARE getting values that are well outside that range, there are two possibilities.

The first is that the input to the equation is out of range. I don't know that because you haven't shown what kind of output you are getting from either function.

The second is that there is a problem with how the equation is being processed on the Arduino, due to unexpected casting. Despite the mix of types in the equation, you INSIST that this is not a possible source of the problem.

Therefore, there must be something wrong with the input to the equation, or you are wrong and there is a problem with the equation implementation.

The ball is in your court to provide more information.

Hello Pauls,

Just to know , i am not on this forum for talking about things that won't give anything interresting. If you really can help, you do not have to ask all these derivative questions. You asked many questons and i try to reply to my best understanding and the last reply was about ranges that formulas supposed to give. And also how can i reply to a question for ranges if i am using formula that suppose to give me the right temperature at that time. If i supposed to know everything in advance so why i am using these formulas.

Please and again i came to this forum for asking questions for getting solution to my problem not for responding to many questions that are not usefull and won't help for getting solution, i am sorry.

So if you would like to help i would be so greteful and many thanks to you.

the output for the teperature funtion for exemple should be the right temperature and at the beginning of my post i clearly gave what i am receiving like output.

unisgned int sht11_temp(void);
unsigned int sht11_humidity(void);
nad they should return the exact temeprature at the time of measure and the humidity percent.

Best regards.

You came in and said that the output from the SHT11 sensor you have is wrong. OK. There are many possibilities why that might be. The sensor could be defective. It could be wired up incorrectly. It could be being powered with the wrong voltage level. The output from the sensor could be being manipulated, in the code, incorrectly. The wrong value might being written to the Serial Monitor.

In order to determine which of the many causes of the problem is the real cause, we ask questions. If you don't understand the question, say so. If you don't know the answer, say so. If you do understand the question, and can provide the answers, do so.

But, complaining about having to answer questions won't help you solve your problem.

I asked you what raw values you are getting from sht11_humidity() and sht11_temp(). If the values you are getting from those functions are reasonable, then there is a reasonable chance that the hardware is working correctly. If not, then there is a reasonable chance that the hardware is not working correctly.

I'd ask you, again, to provide details on the range of values that you are getting from those two functions, but, since you are tired of answering questions, never mind.

Hello Pauls,

I think we do not understand eash other, i was not complaining on answering to your question but you asked many time the same things i already reply and what is the aim of my post, so i was not understanding what you are looking for. But never mind and thanks to you for replying me.

I do not think it is hardware problem because i tried to upload the code to fourth of them and they all almost gave the same value.

For output of temperature: if i make %u for unsigned int, i got 65535 and i try %d, i got -1 for both.

Regards.