# problem measure humidity using hs1101

Status
Not open for further replies.

#### Osawa_Odessa

##### Banned
Hello, could anyone help me with the circuit and program bellow.
I want to use HS1101 to measure humidity using 16F877A in CCS. Here is the circuit I have built as in datasheet of HS1101.

Is the circuit look OK to you? I think it is ok but I am not sure if there is something wrong with it.
And here is the program I have used to measure humidity:
Code:
#include "main.h"
#include "var.h"
#include "lcd16x2/lcd16x2.c"
#include "hs1101/hs1101.c"
#INT_RTCC
void  ngat_timer0(void)
{
disable_interrupts(GLOBAL);
set_timer0(5);
count++;
if(count==100)
{
frequency=get_timer1();
set_timer1(0);
count=0;
enable_display=1;
}
enable_interrupts(GLOBAL);
}

void main()
{
uint8_t str[20],humi;
DDRB=0xfe;
DDRD=0x00;
DDRE=0x00;
LCD_Init();
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
sprintf(str,"Test");
LCD_Puts(str);
delay_ms(40);
set_timer0(5);
set_timer1(0);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(TRUE)
{

if(enable_display)
{

humi=HS1101_GetHumi(frequency);
enable_display=0;
sprintf(str,"Do Am:%3u",humi);
LCD_Gotoxy(0,1);
LCD_Puts(str);
LCD_PutChar('%');
}
}
}
And here is hs1101.c
Code:
/**
******************************************************************************
* Ten Tep      :        hs1101.c
* Tac Gia      :        Nguyen Quy Nhat
* Cong Ty      :        MinhHaGroup
* Website      :        BanLinhKien.Vn
* Phien Ban    :        V1.0.0
* Ngay         :        31-07-2012
* Tom Tat      :        Dinh nghia ham do do am HS1101, khai bao bang tra.
*
*
******************************************************************************
* Chu Y        :
******************************************************************************
**/
#include "hs1101.h"
const uint16_t HS1101_Table[101]={
8109,8090,8070,8051,8033,8015,7997,7979,7961,7944,
7927,7910,7894,7878,7862,7846,7830,7815,7799,7784,
7769,7755,7740,7726,7711,7697,7683,7669,7655,7641,
7628,7614,7600,7587,7574,7560,7547,7534,7521,7507,
7494,7481,7468,7455,7442,7429,7416,7403,7390,7377,
7364,7350,7337,7324,7311,7298,7284,7271,7257,7244,
7230,7216,7203,7189,7175,7161,7147,7132,7118,7103,
7089,7074,7059,7045,7029,7014,6999,6984,6968,6952,
6936,6920,6904,6888,6872,6855,6838,6821,6804,6787,
6770,6752,6735,6717,6699,6680,6662,6644,6625,6606,
6587};
/*******************************************************************************
Noi Dung    :   Doc gia tri do am.
Tham Bien   :   frequency: tan so do duoc tu bo dao dong NE555 ket hop HS1101.
Tra Ve      :   Gia tri do am do duoc tu HS1101.
********************************************************************************/
uint8_t HS1101_GetHumi(uint16_t frequency)
{
uint8_t i;
for(i=0;i<101;i++)
{
if((frequency+25)>HS1101_Table[i])return i;
}
return 100;
}
/******************************KET THUC FILE******************************
______________________________NGUYEN QUY NHAT______________________________*/
I have tried to changed the cap-var to change frequency and therefore change humidity but it always display humidity 0%.
Could you tell me what I am wrong? Your help is greatly appreciated!

##### Banned
I will answer in another 1 hour. Mention your Compiler, MCU, Fosc.

#### Osawa_Odessa

##### Banned
Hello,
Thanks, I use picc compiler CCS, pic 16F877A and Fosc = 20 Mhz.:smile:
I will attach some file in case you need to see it in more detail

- - - Updated - - -

I have checked by replace output of 555(in this case is Fout) by pulse generator in proteus. I changed its frequency and check if humidity is displayed correct but it is not. Sometimes it is correct but most of the cases it is entirely wrong. I have checked code many times both main.c and hs1101.c but I don't see what is wrong with it.

#### Attachments

• code.rar
21.1 KB · Views: 20

#### Osawa_Odessa

##### Banned
Hello,
Now this code is work well when I use pulse generator to create frequency and connect to PIC.
Code:
#include "main.h"
#include "var.h"
#include "lcd16x2/lcd16x2.c"
#include "hs1101/hs1101.c"
#INT_RTCC
void  ngat_timer0(void)
{
disable_interrupts(GLOBAL);
set_timer0(5);
count++;
if(count==78)
{
frequency=get_timer1();
set_timer1(0);
count=0;
enable_display=1;
}
enable_interrupts(GLOBAL);
}

void main()
{
uint8_t str[20],humi;
//DDRB=0xfe;
DDRD=0x00;
DDRE=0x00;
LCD_Init();
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
set_timer0(6);
set_timer1(0);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
sprintf(str,"BanLinhKien.Vn");
LCD_Puts(str);
//delay_us(10);
while(TRUE)
{
if(enable_display)
{

humi=HS1101_GetHumi(frequency);
enable_display=0;
sprintf(str,"Do Am:%3u",humi);
LCD_Gotoxy(0,1);
LCD_Puts(str);
LCD_PutChar('%');
}
}
}
But when I connect the output Fout from NE5555 it doesn't work. I think the problem here is from the circuit. I made it as in datasheet but I think I need to know how it work.

- - - Updated - - -

Aha, it works now!:-D I change nothing! I don't know why but the only problem now is that the time for LCD to display the humidity is too slow. I think it may be 10s delay.

Status
Not open for further replies.